diff --git a/src/constants.ts b/src/constants.ts index f1da6a5..6cfd699 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,6 @@ -export const API_VERSION = "v1"; -export const APP_VERSION = "1.1.0"; +import { API_VERSION, APP_VERSION } from "./version"; + +export { API_VERSION, APP_VERSION }; export const API_PREFIX = `/api/${API_VERSION}`; export const AUTH_PREFIX = `/${API_VERSION}/auth`; export const DOCS_PREFIX = `/docs/${API_VERSION}`; diff --git a/src/index.ts b/src/index.ts index e327a31..4939315 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,9 @@ import { serveStatic } from "hono/bun"; import { logger } from "hono/logger"; import { prettyJSON } from "hono/pretty-json"; import { config } from "./config"; -import { API_PREFIX, APP_VERSION, AUTH_PREFIX, DOCS_PREFIX } from "./constants"; +import { API_PREFIX, AUTH_PREFIX, DOCS_PREFIX } from "./constants"; import { redis } from "./core/RedisClient"; +import { openApiSpec, securityScheme } from "./openapi"; import { apiRoutes } from "./routes/api"; import { authRoutes } from "./routes/auth"; import { configRoutes } from "./routes/config"; @@ -14,35 +15,8 @@ import { dashboardRoutes } from "./routes/dashboard"; const app = new OpenAPIHono({ strict: false }); // OpenAPI specs -app.doc(`${DOCS_PREFIX}/openapi.json`, { - openapi: "3.0.0", - info: { - version: APP_VERSION, - title: "toknd Auth Broker API", - description: - "A high-performance OAuth2 broker and token management service. Designed to centralize provider configurations and automate token lifecycle management across distributed systems.", - }, - tags: [ - { - name: "Tokens", - description: "Endpoint operations for accessing and force-refreshing active provider tokens.", - }, - { - name: "Management", - description: "Administrative operations for provider lifecycle and configuration.", - }, - { - name: "Auth (Internal)", - description: "System-level OAuth2 handshake and callback processing.", - }, - ], - security: [{ API_KEY: [] }], -}); - -app.openAPIRegistry.registerComponent("securitySchemes", "API_KEY", { - type: "http", - scheme: "bearer", -}); +app.doc(`${DOCS_PREFIX}/openapi.json`, openApiSpec); +app.openAPIRegistry.registerComponent("securitySchemes", "API_KEY", securityScheme); // Scalar API Reference app.get( diff --git a/src/openapi.ts b/src/openapi.ts new file mode 100644 index 0000000..dbfb7d5 --- /dev/null +++ b/src/openapi.ts @@ -0,0 +1,31 @@ +import { API_VERSION, APP_VERSION } from "./constants"; + +export const openApiSpec = { + openapi: "3.0.0", + info: { + version: `${API_VERSION}.${APP_VERSION}`, + title: "toknd Auth Broker API", + description: + "A high-performance OAuth2 broker and token management service. Designed to centralize provider configurations and automate token lifecycle management across distributed systems.", + }, + tags: [ + { + name: "Tokens", + description: "Endpoint operations for accessing and force-refreshing active provider tokens.", + }, + { + name: "Management", + description: "Administrative operations for provider lifecycle and configuration.", + }, + { + name: "Auth (Internal)", + description: "System-level OAuth2 handshake and callback processing.", + }, + ], + security: [{ API_KEY: [] }], +}; + +export const securityScheme = { + type: "http", + scheme: "bearer", +} as const; diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..aed130b --- /dev/null +++ b/src/version.ts @@ -0,0 +1,2 @@ +export const API_VERSION = "v1"; +export const APP_VERSION = "1.0";