From 7ddbbbbca4f06294d90ec9b3da46930342e68b19 Mon Sep 17 00:00:00 2001 From: ccbikai Date: Wed, 21 May 2025 20:31:12 +0800 Subject: [PATCH] feat: add OpenAPI metadata to endpoints Enhances API documentation by adding OpenAPI metadata to location and verify endpoints. Includes: - Security requirements for both endpoints - Detailed description of endpoint purposes - Response documentation for verify endpoint with success/error cases --- server/api/location.ts | 7 +++++++ server/api/verify.ts | 15 +++++++++++++++ server/utils/openapi.ts | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 server/utils/openapi.ts diff --git a/server/api/location.ts b/server/api/location.ts index ca7c3e2..aa9dadb 100644 --- a/server/api/location.ts +++ b/server/api/location.ts @@ -1,3 +1,10 @@ +defineRouteMeta({ + openAPI: { + description: 'Get the location of the user', + security: openAPISecurity, + }, +}) + export default eventHandler((event) => { const { request: { cf } } = event.context.cloudflare return { diff --git a/server/api/verify.ts b/server/api/verify.ts index 3e9ccaa..9a77d68 100644 --- a/server/api/verify.ts +++ b/server/api/verify.ts @@ -1,3 +1,18 @@ +defineRouteMeta({ + openAPI: { + description: 'Verify the site token', + security: openAPISecurity, + responses: { + 200: { + description: 'The site token is valid', + }, + default: { + description: 'The site token is invalid', + }, + }, + }, +}) + export default eventHandler(() => { return { name: 'Sink', diff --git a/server/utils/openapi.ts b/server/utils/openapi.ts new file mode 100644 index 0000000..644cb53 --- /dev/null +++ b/server/utils/openapi.ts @@ -0,0 +1,5 @@ +export const openAPISecurity = [{ + type: 'http', + scheme: 'bearer', + description: 'The site\'s token', +}]