@nexusts/openapi 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Public entry point for `nexusjs/openapi`.
2
+ * Public entry point for `@nexusts/openapi`.
3
3
  */
4
4
  export * from "./types.js";
5
5
  export { OpenAPIService } from "./openapi.service.js";
package/dist/index.js.map CHANGED
@@ -3,10 +3,10 @@
3
3
  "sources": ["../src/scalar.ts", "../src/types.ts", "../src/openapi.service.ts", "../src/zod-to-json-schema.ts", "../src/openapi.module.ts", "../src/decorators/tags.ts", "../src/decorators/operation.ts", "../src/decorators/response.ts", "../src/decorators/param.ts", "../src/decorators/body.ts", "../src/decorators/property.ts", "../src/decorators/security.ts"],
4
4
  "sourcesContent": [
5
5
  "/**\n * Scalar UI HTML — a single self-contained page that loads Scalar\n * from the jsDelivr CDN.\n *\n * The page mounts Scalar as a custom-element via `<script\n * id=\"api-reference\" data-url=\"...\">` and waits for the CDN script\n * to upgrade it.\n *\n * No assets are bundled with the framework. No build step required.\n */\n\nexport function scalarHtml(opts: { title: string; specUrl: string; theme?: \"default\" | \"dark\" | \"purple\" | \"alternate\" | \"moon\" | \"solarized\" | \"bluePlanet\" | \"saturn\" | \"kepler\" | \"mars\" | \"deepSpace\" | \"laserwave\" | \"none\" }): string {\n\tconst title = escapeHtml(opts.title);\n\tconst theme = opts.theme ?? \"default\";\n\treturn `<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${title} — API Reference</title>\n <meta name=\"description\" content=\"API reference for ${title}, generated from OpenAPI.\" />\n <style>\n :root { color-scheme: light dark; }\n body { margin: 0; font-family: ui-sans-serif, system-ui, sans-serif; }\n </style>\n</head>\n<body>\n <script\n id=\"api-reference\"\n type=\"application/json\"\n data-url=\"${escapeHtml(opts.specUrl)}\"\n data-configuration='${escapeJsonForAttr(JSON.stringify({ theme, hideClientButton: true }))}'\n ></script>\n <script src=\"https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.25.0\"></script>\n</body>\n</html>`;\n}\n\nfunction escapeHtml(s: string): string {\n\treturn s\n\t\t.replace(/&/g, \"&amp;\")\n\t\t.replace(/</g, \"&lt;\")\n\t\t.replace(/>/g, \"&gt;\")\n\t\t.replace(/\"/g, \"&quot;\")\n\t\t.replace(/'/g, \"&#39;\");\n}\n\n/**\n * Encode a string for use inside an HTML attribute value. We avoid\n * `&quot;` so the value remains valid JSON for Scalar's parser.\n */\nfunction escapeJsonForAttr(s: string): string {\n\treturn s.replace(/'/g, \"&#39;\").replace(/</g, \"&lt;\");\n}",
6
- "/**\nimport { safeGetMeta, safeDefineMeta, safeHasMeta } from \"@nexusts/core/di/safe-reflect\";\n * `nexusjs/openapi` — OpenAPI 3.1 + Scalar UI.\n *\n * @Module({\n * imports: [\n * OpenAPIModule.forRoot({\n * info: { title: 'My API', version: '1.0.0' },\n * servers: [{ url: 'http://localhost:3000' }],\n * }),\n * ],\n * })\n *\n * @Controller('/users')\n * @ApiTags('Users')\n * class UserController {\n * @Get('/')\n * @ApiOperation({ summary: 'List users' })\n * @ApiResponse(200, { description: 'OK', schema: UserSchema })\n * list() { ... }\n * }\n *\n * // -> GET /openapi.json (the spec)\n * // -> GET /docs (Scalar UI)\n */\n\n\n// ---------------------------------------------------------------------------\n// OpenAPI spec types (subset of OpenAPI 3.1 — enough for 95% of real APIs)\n// ---------------------------------------------------------------------------\n\nexport interface OpenAPIConfig {\n\t/** Top-level info block. */\n\tinfo: OpenAPIInfo;\n\t/** Server URLs. Default: [{ url: '/' }]. */\n\tservers?: OpenAPIServer[];\n\t/** Tags grouped at the top of the spec. */\n\ttags?: OpenAPITag[];\n\t/** Path under which the JSON spec is served. Default: '/openapi.json'. */\n\tspecPath?: string;\n\t/** Path under which the Scalar UI is served. Default: '/docs'. */\n\tpath?: string;\n\t/** External docs link. */\n\texternalDocs?: { url: string; description?: string };\n}\n\nexport interface OpenAPIInfo {\n\ttitle: string;\n\tversion: string;\n\tdescription?: string;\n\ttermsOfService?: string;\n\tcontact?: { name?: string; url?: string; email?: string };\n\tlicense?: { name: string; url?: string };\n}\n\nexport interface OpenAPIServer {\n\turl: string;\n\tdescription?: string;\n\tvariables?: Record<string, { default: string; enum?: string[]; description?: string }>;\n}\n\nexport interface OpenAPITag {\n\tname: string;\n\tdescription?: string;\n\texternalDocs?: { url: string; description?: string };\n}\n\n/** OpenAPI Path Item. */\nexport interface OpenAPIPath {\n\t[method: string]: OpenAPIOperation | undefined;\n}\n\n/** OpenAPI Operation. */\nexport interface OpenAPIOperation {\n\ttags?: string[];\n\tsummary?: string;\n\tdescription?: string;\n\toperationId?: string;\n\tparameters?: OpenAPIParameter[];\n\trequestBody?: OpenAPIRequestBody;\n\tresponses: Record<string, OpenAPIResponse>;\n\tdeprecated?: boolean;\n\tsecurity?: OpenAPISecurity[];\n}\n\n/** OpenAPI Parameter (path, query, header, cookie). */\nexport interface OpenAPIParameter {\n\tname: string;\n\tin: \"path\" | \"query\" | \"header\" | \"cookie\";\n\tdescription?: string;\n\trequired?: boolean;\n\tdeprecated?: boolean;\n\tschema: JSONSchema;\n\texample?: unknown;\n\texamples?: Record<string, { summary?: string; value: unknown }>;\n}\n\n/** OpenAPI Request Body. */\nexport interface OpenAPIRequestBody {\n\tdescription?: string;\n\tcontent: Record<string, OpenAPIMediaType>;\n\trequired?: boolean;\n}\n\nexport interface OpenAPIMediaType {\n\tschema: JSONSchema;\n\texample?: unknown;\n\texamples?: Record<string, { summary?: string; value: unknown }>;\n\tencoding?: Record<string, OpenAPIEncoding>;\n}\n\nexport interface OpenAPIEncoding {\n\tcontentType?: string;\n\theaders?: Record<string, OpenAPIParameter>;\n\tstyle?: string;\n\texplode?: boolean;\n\tallowReserved?: boolean;\n}\n\n/** OpenAPI Response. */\nexport interface OpenAPIResponse {\n\tdescription: string;\n\theaders?: Record<string, OpenAPIParameter>;\n\tcontent?: Record<string, OpenAPIMediaType>;\n\tlinks?: Record<string, OpenAPILink>;\n}\n\nexport interface OpenAPILink {\n\toperationRef?: string;\n\toperationId?: string;\n\tparameters?: Record<string, unknown>;\n\tdescription?: string;\n\tserver?: OpenAPIServer;\n}\n\nexport interface OpenAPISecurity {\n\t[name: string]: string[];\n}\n\n/** OpenAPI Component (schemas, parameters, responses, ...). */\nexport interface OpenAPIComponents {\n\tschemas?: Record<string, JSONSchema>;\n\tparameters?: Record<string, OpenAPIParameter>;\n\tresponses?: Record<string, OpenAPIResponse>;\n\trequestBodies?: Record<string, OpenAPIRequestBody>;\n\theaders?: Record<string, OpenAPIParameter>;\n\tsecuritySchemes?: Record<string, OpenAPISecurityScheme>;\n\tlinks?: Record<string, OpenAPILink>;\n}\n\nexport interface OpenAPISecurityScheme {\n\ttype: \"apiKey\" | \"http\" | \"oauth2\" | \"openIdConnect\" | \"mutualTLS\";\n\tdescription?: string;\n\tname?: string;\n\tin?: \"query\" | \"header\" | \"cookie\";\n\tscheme?: string;\n\tbearerFormat?: string;\n\tflows?: unknown;\n\topenIdConnectUrl?: string;\n}\n\nexport interface OpenAPIDocument {\n\topenapi: \"3.1.0\";\n\tinfo: OpenAPIInfo;\n\tservers?: OpenAPIServer[];\n\tpaths: Record<string, OpenAPIPath>;\n\tcomponents?: OpenAPIComponents;\n\ttags?: OpenAPITag[];\n\texternalDocs?: { url: string; description?: string };\n\tsecurity?: OpenAPISecurity[];\n\twebhooks?: Record<string, OpenAPIPath | OpenAPIOperation>;\n}\n\n// ---------------------------------------------------------------------------\n// JSON Schema (subset)\n// ---------------------------------------------------------------------------\n\nexport interface JSONSchema {\n\t$ref?: string;\n\ttype?:\n\t\t| \"string\"\n\t\t| \"number\"\n\t\t| \"integer\"\n\t\t| \"boolean\"\n\t\t| \"object\"\n\t\t| \"array\"\n\t\t| \"null\"\n\t\t| (string & {});\n\tformat?: string;\n\ttitle?: string;\n\tdescription?: string;\n\tdefault?: unknown;\n\texample?: unknown;\n\tenum?: unknown[];\n\tconst?: unknown;\n\tproperties?: Record<string, JSONSchema>;\n\trequired?: string[];\n\tadditionalProperties?: boolean | JSONSchema;\n\titems?: JSONSchema;\n\tprefixItems?: JSONSchema[];\n\tminItems?: number;\n\tmaxItems?: number;\n\tuniqueItems?: boolean;\n\tminimum?: number;\n\tmaximum?: number;\n\tminLength?: number;\n\tmaxLength?: number;\n\tpattern?: string;\n\tnullable?: boolean;\n\toneOf?: JSONSchema[];\n\tanyOf?: JSONSchema[];\n\tallOf?: JSONSchema[];\n\tnot?: JSONSchema;\n\t$defs?: Record<string, JSONSchema>;\n\t$schema?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Decorator payload types\n// ---------------------------------------------------------------------------\n\nexport interface ApiOperationOptions {\n\tsummary?: string;\n\tdescription?: string;\n\toperationId?: string;\n\tdeprecated?: boolean;\n\ttags?: string[];\n}\n\nexport interface ApiResponseOptions {\n\tdescription: string;\n\tschema?: unknown;\n\theaders?: Record<string, OpenAPIParameter>;\n\texample?: unknown;\n\texamples?: Record<string, { summary?: string; value: unknown }>;\n}\n\nexport interface ApiParamOptions {\n\tname: string;\n\tdescription?: string;\n\trequired?: boolean;\n\tschema?: unknown;\n\texample?: unknown;\n}\n\nexport interface ApiQueryOptions extends Omit<ApiParamOptions, \"name\"> {\n\tname: string;\n}\n\nexport interface ApiBodyOptions {\n\tdescription?: string;\n\trequired?: boolean;\n\tschema?: unknown;\n\texample?: unknown;\n}\n\nexport interface ApiPropertyOptions {\n\tdescription?: string;\n\trequired?: boolean;\n\texample?: unknown;\n\tdeprecated?: boolean;\n\tformat?: string;\n\tschema?: unknown;\n}\n\nexport interface ApiSecurityOptions {\n\t[name: string]: string[];\n}\n\n// ---------------------------------------------------------------------------\n// Reflect metadata keys\n// ---------------------------------------------------------------------------\n\nexport const OPENAPI_META = {\n\tTAGS: \"nexus:openapi:tags\",\n\tOPERATION: \"nexus:openapi:operation\",\n\tRESPONSES: \"nexus:openapi:responses\",\n\tPARAMS: \"nexus:openapi:params\",\n\tQUERIES: \"nexus:openapi:queries\",\n\tBODY: \"nexus:openapi:body\",\n\tPROPERTIES: \"nexus:openapi:properties\",\n\tSECURITY: \"nexus:openapi:security\",\n\tEXCLUDE: \"nexus:openapi:exclude\",\n\tPRODUCES: \"nexus:openapi:produces\",\n\tCONSUMES: \"nexus:openapi:consumes\",\n} as const;\n",
6
+ "/**\nimport { safeGetMeta, safeDefineMeta, safeHasMeta } from \"@nexusts/core/di/safe-reflect\";\n * `@nexusts/openapi` — OpenAPI 3.1 + Scalar UI.\n *\n * @Module({\n * imports: [\n * OpenAPIModule.forRoot({\n * info: { title: 'My API', version: '1.0.0' },\n * servers: [{ url: 'http://localhost:3000' }],\n * }),\n * ],\n * })\n *\n * @Controller('/users')\n * @ApiTags('Users')\n * class UserController {\n * @Get('/')\n * @ApiOperation({ summary: 'List users' })\n * @ApiResponse(200, { description: 'OK', schema: UserSchema })\n * list() { ... }\n * }\n *\n * // -> GET /openapi.json (the spec)\n * // -> GET /docs (Scalar UI)\n */\n\n\n// ---------------------------------------------------------------------------\n// OpenAPI spec types (subset of OpenAPI 3.1 — enough for 95% of real APIs)\n// ---------------------------------------------------------------------------\n\nexport interface OpenAPIConfig {\n\t/** Top-level info block. */\n\tinfo: OpenAPIInfo;\n\t/** Server URLs. Default: [{ url: '/' }]. */\n\tservers?: OpenAPIServer[];\n\t/** Tags grouped at the top of the spec. */\n\ttags?: OpenAPITag[];\n\t/** Path under which the JSON spec is served. Default: '/openapi.json'. */\n\tspecPath?: string;\n\t/** Path under which the Scalar UI is served. Default: '/docs'. */\n\tpath?: string;\n\t/** External docs link. */\n\texternalDocs?: { url: string; description?: string };\n}\n\nexport interface OpenAPIInfo {\n\ttitle: string;\n\tversion: string;\n\tdescription?: string;\n\ttermsOfService?: string;\n\tcontact?: { name?: string; url?: string; email?: string };\n\tlicense?: { name: string; url?: string };\n}\n\nexport interface OpenAPIServer {\n\turl: string;\n\tdescription?: string;\n\tvariables?: Record<string, { default: string; enum?: string[]; description?: string }>;\n}\n\nexport interface OpenAPITag {\n\tname: string;\n\tdescription?: string;\n\texternalDocs?: { url: string; description?: string };\n}\n\n/** OpenAPI Path Item. */\nexport interface OpenAPIPath {\n\t[method: string]: OpenAPIOperation | undefined;\n}\n\n/** OpenAPI Operation. */\nexport interface OpenAPIOperation {\n\ttags?: string[];\n\tsummary?: string;\n\tdescription?: string;\n\toperationId?: string;\n\tparameters?: OpenAPIParameter[];\n\trequestBody?: OpenAPIRequestBody;\n\tresponses: Record<string, OpenAPIResponse>;\n\tdeprecated?: boolean;\n\tsecurity?: OpenAPISecurity[];\n}\n\n/** OpenAPI Parameter (path, query, header, cookie). */\nexport interface OpenAPIParameter {\n\tname: string;\n\tin: \"path\" | \"query\" | \"header\" | \"cookie\";\n\tdescription?: string;\n\trequired?: boolean;\n\tdeprecated?: boolean;\n\tschema: JSONSchema;\n\texample?: unknown;\n\texamples?: Record<string, { summary?: string; value: unknown }>;\n}\n\n/** OpenAPI Request Body. */\nexport interface OpenAPIRequestBody {\n\tdescription?: string;\n\tcontent: Record<string, OpenAPIMediaType>;\n\trequired?: boolean;\n}\n\nexport interface OpenAPIMediaType {\n\tschema: JSONSchema;\n\texample?: unknown;\n\texamples?: Record<string, { summary?: string; value: unknown }>;\n\tencoding?: Record<string, OpenAPIEncoding>;\n}\n\nexport interface OpenAPIEncoding {\n\tcontentType?: string;\n\theaders?: Record<string, OpenAPIParameter>;\n\tstyle?: string;\n\texplode?: boolean;\n\tallowReserved?: boolean;\n}\n\n/** OpenAPI Response. */\nexport interface OpenAPIResponse {\n\tdescription: string;\n\theaders?: Record<string, OpenAPIParameter>;\n\tcontent?: Record<string, OpenAPIMediaType>;\n\tlinks?: Record<string, OpenAPILink>;\n}\n\nexport interface OpenAPILink {\n\toperationRef?: string;\n\toperationId?: string;\n\tparameters?: Record<string, unknown>;\n\tdescription?: string;\n\tserver?: OpenAPIServer;\n}\n\nexport interface OpenAPISecurity {\n\t[name: string]: string[];\n}\n\n/** OpenAPI Component (schemas, parameters, responses, ...). */\nexport interface OpenAPIComponents {\n\tschemas?: Record<string, JSONSchema>;\n\tparameters?: Record<string, OpenAPIParameter>;\n\tresponses?: Record<string, OpenAPIResponse>;\n\trequestBodies?: Record<string, OpenAPIRequestBody>;\n\theaders?: Record<string, OpenAPIParameter>;\n\tsecuritySchemes?: Record<string, OpenAPISecurityScheme>;\n\tlinks?: Record<string, OpenAPILink>;\n}\n\nexport interface OpenAPISecurityScheme {\n\ttype: \"apiKey\" | \"http\" | \"oauth2\" | \"openIdConnect\" | \"mutualTLS\";\n\tdescription?: string;\n\tname?: string;\n\tin?: \"query\" | \"header\" | \"cookie\";\n\tscheme?: string;\n\tbearerFormat?: string;\n\tflows?: unknown;\n\topenIdConnectUrl?: string;\n}\n\nexport interface OpenAPIDocument {\n\topenapi: \"3.1.0\";\n\tinfo: OpenAPIInfo;\n\tservers?: OpenAPIServer[];\n\tpaths: Record<string, OpenAPIPath>;\n\tcomponents?: OpenAPIComponents;\n\ttags?: OpenAPITag[];\n\texternalDocs?: { url: string; description?: string };\n\tsecurity?: OpenAPISecurity[];\n\twebhooks?: Record<string, OpenAPIPath | OpenAPIOperation>;\n}\n\n// ---------------------------------------------------------------------------\n// JSON Schema (subset)\n// ---------------------------------------------------------------------------\n\nexport interface JSONSchema {\n\t$ref?: string;\n\ttype?:\n\t\t| \"string\"\n\t\t| \"number\"\n\t\t| \"integer\"\n\t\t| \"boolean\"\n\t\t| \"object\"\n\t\t| \"array\"\n\t\t| \"null\"\n\t\t| (string & {});\n\tformat?: string;\n\ttitle?: string;\n\tdescription?: string;\n\tdefault?: unknown;\n\texample?: unknown;\n\tenum?: unknown[];\n\tconst?: unknown;\n\tproperties?: Record<string, JSONSchema>;\n\trequired?: string[];\n\tadditionalProperties?: boolean | JSONSchema;\n\titems?: JSONSchema;\n\tprefixItems?: JSONSchema[];\n\tminItems?: number;\n\tmaxItems?: number;\n\tuniqueItems?: boolean;\n\tminimum?: number;\n\tmaximum?: number;\n\tminLength?: number;\n\tmaxLength?: number;\n\tpattern?: string;\n\tnullable?: boolean;\n\toneOf?: JSONSchema[];\n\tanyOf?: JSONSchema[];\n\tallOf?: JSONSchema[];\n\tnot?: JSONSchema;\n\t$defs?: Record<string, JSONSchema>;\n\t$schema?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Decorator payload types\n// ---------------------------------------------------------------------------\n\nexport interface ApiOperationOptions {\n\tsummary?: string;\n\tdescription?: string;\n\toperationId?: string;\n\tdeprecated?: boolean;\n\ttags?: string[];\n}\n\nexport interface ApiResponseOptions {\n\tdescription: string;\n\tschema?: unknown;\n\theaders?: Record<string, OpenAPIParameter>;\n\texample?: unknown;\n\texamples?: Record<string, { summary?: string; value: unknown }>;\n}\n\nexport interface ApiParamOptions {\n\tname: string;\n\tdescription?: string;\n\trequired?: boolean;\n\tschema?: unknown;\n\texample?: unknown;\n}\n\nexport interface ApiQueryOptions extends Omit<ApiParamOptions, \"name\"> {\n\tname: string;\n}\n\nexport interface ApiBodyOptions {\n\tdescription?: string;\n\trequired?: boolean;\n\tschema?: unknown;\n\texample?: unknown;\n}\n\nexport interface ApiPropertyOptions {\n\tdescription?: string;\n\trequired?: boolean;\n\texample?: unknown;\n\tdeprecated?: boolean;\n\tformat?: string;\n\tschema?: unknown;\n}\n\nexport interface ApiSecurityOptions {\n\t[name: string]: string[];\n}\n\n// ---------------------------------------------------------------------------\n// Reflect metadata keys\n// ---------------------------------------------------------------------------\n\nexport const OPENAPI_META = {\n\tTAGS: \"nexus:openapi:tags\",\n\tOPERATION: \"nexus:openapi:operation\",\n\tRESPONSES: \"nexus:openapi:responses\",\n\tPARAMS: \"nexus:openapi:params\",\n\tQUERIES: \"nexus:openapi:queries\",\n\tBODY: \"nexus:openapi:body\",\n\tPROPERTIES: \"nexus:openapi:properties\",\n\tSECURITY: \"nexus:openapi:security\",\n\tEXCLUDE: \"nexus:openapi:exclude\",\n\tPRODUCES: \"nexus:openapi:produces\",\n\tCONSUMES: \"nexus:openapi:consumes\",\n} as const;\n",
7
7
  "/**\n * `OpenAPIService` — walks the framework's route table, reads\n * `@ApiTags` / `@ApiOperation` / `@ApiResponse` / `@ApiBody` /\n * `@ApiParam` / `@ApiQuery` / `@Validate` metadata, and produces an\n * OpenAPI 3.1 document.\n *\n * The document is rebuilt on demand (cheap: in-memory walk) and\n * exposed via `getSpec()`. The framework's router already exposes a\n * `getRoutes()` method that returns the registered route list, so\n * the spec is always in sync with the actual API.\n */\nimport { Inject, Injectable } from \"@nexusts/core\";\nimport type {\n\tApiOperationOptions,\n\tApiParamOptions,\n\tApiPropertyOptions,\n\tApiResponseOptions,\n\tJSONSchema,\n\tOPENAPI_META as _OM,\n\tOpenAPIConfig,\n\tOpenAPIDocument,\n\tOpenAPIMediaType,\n\tOpenAPIOperation,\n\tOpenAPIParameter,\n\tOpenAPIRequestBody,\n\tOpenAPIResponse,\n} from \"./types.js\";\nimport { OPENAPI_META } from \"./types.js\";\nimport { zodToJsonSchema } from \"./zod-to-json-schema.js\";\nimport { safeGetMeta, safeDefineMeta, safeHasMeta } from \"@nexusts/core/di/safe-reflect\";\n\n@Injectable()\nexport class OpenAPIService {\n\t/** DI token. */\n\tstatic readonly TOKEN = Symbol.for(\"nexus:OpenAPIService\");\n\n\t#config: OpenAPIConfig;\n\t#components: { schemas: Map<string, JSONSchema> } = { schemas: new Map() };\n\t#routes: { method: string; path: string; target: any; propertyKey: string | symbol; validation?: any }[] = [];\n\n\tconstructor(@Inject(\"OPENAPI_CONFIG\") config: OpenAPIConfig) {\n\t\tthis.#config = config;\n\t}\n\n\t/**\n\t * Inject the route list. The framework's router calls this on boot.\n\t * Each entry is the data needed to emit one OpenAPI operation.\n\t */\n\tsetRoutes(\n\t\troutes: {\n\t\t\tmethod: string;\n\t\t\tpath: string;\n\t\t\ttarget: any;\n\t\t\tpropertyKey: string | symbol;\n\t\t\tvalidation?: { body?: unknown; query?: unknown; params?: unknown; headers?: unknown };\n\t\t}[],\n\t): void {\n\t\tthis.#routes = routes;\n\t}\n\n\t/** Register a named component schema (e.g. for re-use). */\n\tregisterSchema(name: string, schema: JSONSchema): void {\n\t\tthis.#components.schemas.set(name, schema);\n\t}\n\n\t/** Build the OpenAPI 3.1 document. */\n\tgetSpec(): OpenAPIDocument {\n\t\tconst paths: Record<string, Record<string, OpenAPIOperation>> = {};\n\t\tfor (const route of this.#routes) {\n\t\t\tif (safeGetMeta(OPENAPI_META.EXCLUDE, route.target.constructor, route.propertyKey)) continue;\n\t\t\tconst op = this.buildOperation(route);\n\t\t\tconst normalized = this.normalizePath(route.path);\n\t\t\tconst method = route.method.toLowerCase();\n\t\t\tif (!paths[normalized]) paths[normalized] = {};\n\t\t\tpaths[normalized][method] = op;\n\t\t}\n\n\t\tconst doc: OpenAPIDocument = {\n\t\t\topenapi: \"3.1.0\",\n\t\t\tinfo: this.#config.info,\n\t\t\tpaths,\n\t\t};\n\t\tif (this.#config.servers?.length) doc.servers = this.#config.servers;\n\t\tif (this.#config.tags?.length) doc.tags = this.#config.tags;\n\t\tif (this.#config.externalDocs) doc.externalDocs = this.#config.externalDocs;\n\t\tif (this.#components.schemas.size > 0) {\n\t\t\tdoc.components = {\n\t\t\t\tschemas: Object.fromEntries(this.#components.schemas),\n\t\t\t};\n\t\t}\n\t\treturn doc;\n\t}\n\n\t/**\n\t * Build one operation from a route.\n\t */\n\tprivate buildOperation(route: {\n\t\tmethod: string;\n\t\tpath: string;\n\t\ttarget: any;\n\t\tpropertyKey: string | symbol;\n\t\tvalidation?: { body?: unknown; query?: unknown; params?: unknown; headers?: unknown };\n\t}): OpenAPIOperation {\n\t\tconst ctor = route.target.constructor ?? route.target;\n\t\tconst propKey = route.propertyKey;\n\n\t\t// 1. Tags from class + operation\n\t\tconst classTags: string[] = safeGetMeta(OPENAPI_META.TAGS, ctor) ?? [];\n\t\tconst opMeta: ApiOperationOptions | undefined = safeGetMeta(\n\t\t\tOPENAPI_META.OPERATION,\n\t\t\tctor,\n\t\t\tpropKey,\n\t\t);\n\t\tconst opTags: string[] = opMeta?.tags ?? [];\n\t\tconst tags = [...new Set([...classTags, ...opTags])];\n\n\t\t// 2. Parameters (path / query / headers)\n\t\tconst params: OpenAPIParameter[] = [];\n\t\t// Auto-derive path params from the route pattern.\n\t\tconst pathParams = this.extractPathParams(route.path);\n\t\tfor (const name of pathParams) {\n\t\t\tconst override = (\n\t\t\t\t(safeGetMeta(OPENAPI_META.PARAMS, ctor, propKey) ?? []) as ApiParamOptions[]\n\t\t\t).find((p) => p.name === name);\n\t\t\tparams.push({\n\t\t\t\tname,\n\t\t\t\tin: \"path\",\n\t\t\t\trequired: true,\n\t\t\t\tdescription: override?.description,\n\t\t\t\tschema: override?.schema ? this.toSchema(override.schema) : { type: \"string\" },\n\t\t\t});\n\t\t}\n\t\t// Auto-derive query params from `@Validate({ query })`.\n\t\tif (route.validation?.query) {\n\t\t\tthis.appendZodParams(\n\t\t\t\tctor,\n\t\t\t\tpropKey,\n\t\t\t\t\"query\",\n\t\t\t\troute.validation.query,\n\t\t\t\tparams,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t}\n\t\t// Auto-derive headers from `@Validate({ headers })`.\n\t\tif (route.validation?.headers) {\n\t\t\tthis.appendZodParams(\n\t\t\t\tctor,\n\t\t\t\tpropKey,\n\t\t\t\t\"header\",\n\t\t\t\troute.validation.headers,\n\t\t\t\tparams,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t}\n\t\t// Explicit `@ApiQuery` decorators override / supplement.\n\t\tconst explicitQueries: ApiParamOptions[] =\n\t\t\tsafeGetMeta(OPENAPI_META.QUERIES, ctor, propKey) ?? [];\n\t\tfor (const q of explicitQueries) {\n\t\t\t// Replace any auto-derived entry for the same name.\n\t\t\tconst idx = params.findIndex(\n\t\t\t\t(p) => p.in === \"query\" && p.name === q.name,\n\t\t\t);\n\t\t\tconst param: OpenAPIParameter = {\n\t\t\t\tname: q.name,\n\t\t\t\tin: \"query\",\n\t\t\t\trequired: q.required ?? false,\n\t\t\t\tdescription: q.description,\n\t\t\t\tschema: q.schema ? this.toSchema(q.schema) : { type: \"string\" },\n\t\t\t};\n\t\t\tif (idx >= 0) params[idx] = param;\n\t\t\telse params.push(param);\n\t\t}\n\t\t// Explicit `@ApiParam` decorators override path params.\n\t\tconst explicitParams: ApiParamOptions[] =\n\t\t\tsafeGetMeta(OPENAPI_META.PARAMS, ctor, propKey) ?? [];\n\t\tfor (const p of explicitParams) {\n\t\t\tconst idx = params.findIndex(\n\t\t\t\t(x) => x.in === \"path\" && x.name === p.name,\n\t\t\t);\n\t\t\tconst param: OpenAPIParameter = {\n\t\t\t\tname: p.name,\n\t\t\t\tin: \"path\",\n\t\t\t\trequired: p.required ?? true,\n\t\t\t\tdescription: p.description,\n\t\t\t\tschema: p.schema ? this.toSchema(p.schema) : { type: \"string\" },\n\t\t\t};\n\t\t\tif (idx >= 0) params[idx] = param;\n\t\t\telse params.push(param);\n\t\t}\n\n\t\t// 3. Request body\n\t\tlet requestBody: OpenAPIRequestBody | undefined;\n\t\tconst bodyMeta = safeGetMeta(OPENAPI_META.BODY, ctor, propKey);\n\t\tif (bodyMeta?.schema || route.validation?.body) {\n\t\t\tconst schema = bodyMeta?.schema ?? route.validation?.body;\n\t\t\tconst mediaType: OpenAPIMediaType = { schema: this.toSchema(schema) };\n\t\t\tif (bodyMeta?.example !== undefined) mediaType.example = bodyMeta.example;\n\t\t\trequestBody = {\n\t\t\t\tdescription: bodyMeta?.description ?? \"Request body\",\n\t\t\t\tcontent: { \"application/json\": mediaType },\n\t\t\t\trequired: bodyMeta?.required ?? true,\n\t\t\t};\n\t\t}\n\n\t\t// 4. Responses\n\t\tconst responses: Record<string, OpenAPIResponse> = {};\n\t\tconst responseMetas: Array<[string, ApiResponseOptions]> =\n\t\t\tsafeGetMeta(OPENAPI_META.RESPONSES, ctor, propKey) ?? [];\n\t\tfor (const [status, opt] of responseMetas) {\n\t\t\tconst r: OpenAPIResponse = { description: opt.description };\n\t\t\tif (opt.schema) {\n\t\t\t\tr.content = {\n\t\t\t\t\t\"application/json\": {\n\t\t\t\t\t\tschema: this.toSchema(opt.schema),\n\t\t\t\t\t\t...(opt.example !== undefined ? { example: opt.example } : {}),\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tresponses[status] = r;\n\t\t}\n\t\t// Default 200 OK if no responses declared.\n\t\tif (Object.keys(responses).length === 0) {\n\t\t\tresponses[\"200\"] = { description: \"Successful response\" };\n\t\t}\n\n\t\t// 5. Compose\n\t\tconst op: OpenAPIOperation = {\n\t\t\tresponses,\n\t\t};\n\t\tif (tags.length > 0) op.tags = tags;\n\t\tif (opMeta?.summary) op.summary = opMeta.summary;\n\t\tif (opMeta?.description) op.description = opMeta.description;\n\t\tif (opMeta?.operationId) op.operationId = opMeta.operationId;\n\t\tif (opMeta?.deprecated) op.deprecated = true;\n\t\tif (params.length > 0) op.parameters = params;\n\t\tif (requestBody) op.requestBody = requestBody;\n\t\treturn op;\n\t}\n\n\t/**\n\t * Convert any of:\n\t * - a Zod schema → JSON Schema via `zodToJsonSchema`\n\t * - a `JSONSchema` object → passthrough\n\t * - a class decorated with `@ApiProperty` → JSON Schema\n\t * - `null` / `undefined` → empty object\n\t */\n\tprivate toSchema(input: unknown): JSONSchema {\n\t\tif (input == null) return {};\n\t\t// JSONSchema passthrough (has `type` or `$ref` or any of our keys).\n\t\tif (typeof input === \"object\" && !isZodLike(input)) {\n\t\t\treturn input as JSONSchema;\n\t\t}\n\t\t// Zod-like: try the converter.\n\t\ttry {\n\t\t\treturn zodToJsonSchema(input);\n\t\t} catch {\n\t\t\treturn {};\n\t\t}\n\t}\n\n\tprivate appendZodParams(\n\t\tctor: any,\n\t\tpropKey: string | symbol,\n\t\twhere: \"query\" | \"header\",\n\t\tschema: unknown,\n\t\tparams: OpenAPIParameter[],\n\t\trequired: boolean,\n\t): void {\n\t\tconst json = this.toSchema(schema);\n\t\t// Unwrap top-level object to one entry per property.\n\t\tif (json.type === \"object\" && json.properties) {\n\t\t\tconst req = new Set(json.required ?? []);\n\t\t\tfor (const [name, sub] of Object.entries(json.properties)) {\n\t\t\t\tparams.push({\n\t\t\t\t\tname,\n\t\t\t\t\tin: where,\n\t\t\t\t\trequired: required || req.has(name),\n\t\t\t\t\tschema: sub,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate extractPathParams(path: string): string[] {\n\t\tconst out: string[] = [];\n\t\tconst re = /:([A-Za-z0-9_]+)/g;\n\t\tlet m: RegExpExecArray | null;\n\t\twhile ((m = re.exec(path)) !== null) out.push(m[1]!);\n\t\treturn out;\n\t}\n\n\tprivate normalizePath(path: string): string {\n\t\treturn path.replace(/:([A-Za-z0-9_]+)/g, \"{$1}\");\n\t}\n}\n\nfunction isZodLike(s: unknown): boolean {\n\tif (typeof s !== \"object\" || s === null) return false;\n\tconst o = s as { _def?: { typeName?: string }; typeName?: string };\n\tconst t = o._def?.typeName ?? o.typeName;\n\treturn typeof t === \"string\" && t.startsWith(\"Zod\");\n}",
8
8
  "/**\n * `zodToJsonSchema` — convert a Zod schema to an OpenAPI-compatible\n * JSON Schema. Zero dependencies, supports the Zod patterns that\n * show up in real APIs:\n *\n * - primitives (string / number / integer / boolean / null)\n * - literal, enum, nativeEnum\n * - object (with required / optional / nullable fields)\n * - array / tuple\n * - union / discriminatedUnion\n * - optional / nullable / default\n * - record / map\n * - format inference (email, uuid, url, datetime, ...)\n * - min / max / length / regex constraints\n *\n * Limitations (by design):\n * - transforms / pipes / preprocess: not represented\n * - branded types: erased\n * - recursive schemas: pass `$ref` manually via `setRefName`\n *\n * For richer support, pre-compute a `JSONSchema` and pass it via\n * the decorator's `schema` field; this converter is a convenience,\n * not a complete codegen.\n */\n\nimport type { JSONSchema } from \"./types.js\";\n\n/**\n * Convert a Zod schema (or any value that quacks like one) to a\n * JSON Schema object.\n */\nexport function zodToJsonSchema(\n\tschema: unknown,\n\topts: { $defs?: Record<string, JSONSchema>; visited?: WeakSet<object> } = {},\n): JSONSchema {\n\tconst defs = opts.$defs ?? {};\n\tconst visited = opts.visited ?? new WeakSet<object>();\n\tif (visited.has(schema as object)) {\n\t\t// Recursive schema — fall back to `{}` so we don't infinite-loop.\n\t\treturn {};\n\t}\n\tif (typeof schema === \"object\" && schema !== null) {\n\t\tvisited.add(schema as object);\n\t}\n\n\tconst def = readDef(schema);\n\n\t// Primitives\n\tif (def.typeName === \"ZodString\") return convertString(def);\n\tif (def.typeName === \"ZodNumber\") return convertNumber(def);\n\tif (def.typeName === \"ZodBigInt\") return { type: \"integer\", format: \"int64\" };\n\tif (def.typeName === \"ZodBoolean\") return { type: \"boolean\" };\n\tif (def.typeName === \"ZodDate\") return { type: \"string\", format: \"date-time\" };\n\tif (def.typeName === \"ZodNull\") return { type: \"null\" };\n\tif (def.typeName === \"ZodUndefined\") return { not: {} };\n\tif (def.typeName === \"ZodAny\") return {};\n\tif (def.typeName === \"ZodUnknown\") return {};\n\tif (def.typeName === \"ZodNever\") return { not: {} };\n\n\tif (def.typeName === \"ZodLiteral\") {\n\t\tconst v = (def as { value: unknown }).value;\n\t\treturn { type: jsonTypeOf(v) as JSONSchema[\"type\"], enum: [v] };\n\t}\n\n\tif (def.typeName === \"ZodEnum\") {\n\t\tconst values = (def as { values: ReadonlyArray<string | number> }).values;\n\t\tconst t = values.every((v) => typeof v === \"number\") ? \"number\" : \"string\";\n\t\treturn { type: t as JSONSchema[\"type\"], enum: [...values] };\n\t}\n\n\tif (def.typeName === \"ZodNativeEnum\") {\n\t\tconst values = (def as { values: Record<string, string | number> }).values;\n\t\tconst entries = Object.entries(values).filter(\n\t\t\t([k, v]) => typeof v !== \"number\" || isNaN(Number(k)),\n\t\t);\n\t\tconst opts = entries.map(([, v]) => v);\n\t\tconst t = opts.every((v) => typeof v === \"number\") ? \"number\" : \"string\";\n\t\treturn { type: t as JSONSchema[\"type\"], enum: opts };\n\t}\n\n\tif (def.typeName === \"ZodObject\") {\n\t\treturn convertObject(schema, def, defs, visited);\n\t}\n\n\tif (def.typeName === \"ZodArray\") {\n\t\treturn convertArray(schema, def, defs, visited);\n\t}\n\n\tif (def.typeName === \"ZodTuple\") {\n\t\tconst items = (def as { items: unknown[] }).items;\n\t\treturn {\n\t\t\ttype: \"array\",\n\t\t\tprefixItems: items.map((s) => zodToJsonSchema(s, { $defs: defs, visited })),\n\t\t\tminItems: items.length,\n\t\t\tmaxItems: items.length,\n\t\t};\n\t}\n\n\tif (def.typeName === \"ZodUnion\" || def.typeName === \"ZodDiscriminatedUnion\") {\n\t\tconst options = (def as { options?: unknown[]; optionsArray?: unknown[] }).options\n\t\t\t?? (def as { optionsArray?: unknown[] }).optionsArray\n\t\t\t?? [];\n\t\treturn {\n\t\t\toneOf: options.map((s) => zodToJsonSchema(s, { $defs: defs, visited })),\n\t\t};\n\t}\n\n\tif (def.typeName === \"ZodDiscriminatedUnion\") {\n\t\tconst discriminator = (def as { discriminator?: string }).discriminator;\n\t\tconst options = (def as { options?: unknown[] }).options ?? [];\n\t\tconst mapping: Record<string, JSONSchema> = {};\n\t\tfor (const opt of options) {\n\t\t\tconst od = readDef(opt);\n\t\t\tif (od.typeName === \"ZodObject\") {\n\t\t\t\tconst shape = (od as { shape: () => Record<string, unknown> }).shape();\n\t\t\t\tconst disc = shape[discriminator ?? \"\"] as { value: unknown } | undefined;\n\t\t\t\tif (disc && \"value\" in disc) {\n\t\t\t\t\tmapping[String(disc.value)] = zodToJsonSchema(opt, { $defs: defs, visited });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\toneOf: Object.values(mapping),\n\t\t\tdiscriminator: { propertyName: discriminator ?? \"type\" },\n\t\t} as JSONSchema;\n\t}\n\n\tif (def.typeName === \"ZodIntersection\") {\n\t\tconst left = (def as { _def?: { left: unknown; right: unknown } })._def?.left\n\t\t\t?? (def as { left: unknown }).left;\n\t\tconst right = (def as { _def?: { left: unknown; right: unknown } })._def?.right\n\t\t\t?? (def as { right: unknown }).right;\n\t\treturn {\n\t\t\tallOf: [\n\t\t\t\tzodToJsonSchema(left, { $defs: defs, visited }),\n\t\t\t\tzodToJsonSchema(right, { $defs: defs, visited }),\n\t\t\t],\n\t\t};\n\t}\n\n\tif (def.typeName === \"ZodRecord\") {\n\t\tconst valueType = (def as { valueType: unknown }).valueType;\n\t\treturn {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: zodToJsonSchema(valueType, { $defs: defs, visited }),\n\t\t};\n\t}\n\n\tif (def.typeName === \"ZodMap\") {\n\t\tconst valueType = (def as { valueType: unknown }).valueType;\n\t\treturn {\n\t\t\ttype: \"object\",\n\t\t\tadditionalProperties: zodToJsonSchema(valueType, { $defs: defs, visited }),\n\t\t};\n\t}\n\n\tif (def.typeName === \"ZodOptional\") {\n\t\tconst inner = (def as { innerType: unknown }).innerType;\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\tif (def.typeName === \"ZodNullable\") {\n\t\tconst inner = (def as { innerType: unknown }).innerType;\n\t\treturn {\n\t\t\t...zodToJsonSchema(inner, { $defs: defs, visited }),\n\t\t\tnullable: true,\n\t\t};\n\t}\n\n\tif (def.typeName === \"ZodDefault\") {\n\t\tconst inner = (def as { innerType: unknown; defaultValue: () => unknown }).innerType;\n\t\tconst dv = (def as { defaultValue: () => unknown }).defaultValue;\n\t\treturn {\n\t\t\t...zodToJsonSchema(inner, { $defs: defs, visited }),\n\t\t\tdefault: safeCall(dv),\n\t\t};\n\t}\n\n\tif (def.typeName === \"ZodCatch\") {\n\t\tconst inner = (def as { innerType: unknown }).innerType;\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\tif (def.typeName === \"ZodBranded\") {\n\t\tconst inner = (def as { type: unknown }).type;\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\tif (def.typeName === \"ZodReadonly\") {\n\t\tconst inner = (def as { innerType: unknown }).innerType;\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\tif (def.typeName === \"ZodLazy\") {\n\t\tconst getter = (def as { getter: () => unknown }).getter;\n\t\tconst inner = safeCall(getter);\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\tif (def.typeName === \"ZodEffects\") {\n\t\tconst inner = (def as { source?: unknown; schema?: unknown; innerType?: unknown }).source\n\t\t\t?? (def as { schema?: unknown }).schema\n\t\t\t?? (def as { innerType?: unknown }).innerType;\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\tif (def.typeName === \"ZodPipeline\") {\n\t\tconst inner = (def as { out: unknown }).out;\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\tif (def.typeName === \"ZodFunction\") return { type: \"null\" };\n\tif (def.typeName === \"ZodPromise\") {\n\t\tconst inner = (def as { innerType: unknown }).innerType;\n\t\treturn zodToJsonSchema(inner, { $defs: defs, visited });\n\t}\n\n\t// Fallback: emit a permissive object schema so the spec is at least\n\t// structurally valid. The user can refine by passing an explicit\n\t// `schema: {...}` on the decorator.\n\treturn {};\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\ntype ZodDef = Record<string, unknown>;\n\nfunction readDef(schema: unknown): ZodDef {\n\tif (typeof schema !== \"object\" || schema === null) return { typeName: \"\" };\n\t// Zod 3 / 3.25: stores everything under `_def`.\n\tconst s = schema as { _def?: ZodDef };\n\tif (s._def && typeof s._def === \"object\") return s._def;\n\t// Fallback: top-level access (some forks).\n\treturn s as ZodDef;\n}\n\nfunction convertString(def: ZodDef): JSONSchema {\n\tconst out: JSONSchema = { type: \"string\" };\n\tconst checks = (def.checks ?? []) as Array<{ kind: string; value?: unknown; regex?: { source: string; flags?: string } }>;\n\tfor (const c of checks) {\n\t\tswitch (c.kind) {\n\t\t\tcase \"email\": out.format = \"email\"; break;\n\t\t\tcase \"url\": out.format = \"uri\"; break;\n\t\t\tcase \"uuid\": out.format = \"uuid\"; break;\n\t\t\tcase \"cuid\":\n\t\t\tcase \"cuid2\": out.format = \"cuid\"; break;\n\t\t\tcase \"emoji\": break;\n\t\t\tcase \"ip\": out.format = \"ipv4\"; break;\n\t\t\tcase \"cidr\": out.format = \"cidr\"; break;\n\t\t\tcase \"datetime\": out.format = \"date-time\"; break;\n\t\t\tcase \"date\": out.format = \"date\"; break;\n\t\t\tcase \"time\": out.format = \"time\"; break;\n\t\t\tcase \"duration\": break;\n\t\t\tcase \"min\":\n\t\t\tcase \"length\": out.minLength = Number(c.value); break;\n\t\t\tcase \"max\": out.maxLength = Number(c.value); break;\n\t\t\tcase \"regex\": if (c.regex) out.pattern = c.regex.source; break;\n\t\t\tcase \"trim\":\n\t\t\tcase \"toLowerCase\":\n\t\t\tcase \"toUpperCase\":\n\t\t\tcase \"startsWith\":\n\t\t\tcase \"endsWith\":\n\t\t\tcase \"includes\":\n\t\t\t\t// No JSON Schema equivalent; ignore.\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction convertNumber(def: ZodDef): JSONSchema {\n\tconst out: JSONSchema = { type: \"number\" };\n\tconst checks = (def.checks ?? []) as Array<{ kind: string; value?: number }>;\n\tlet isInt = false;\n\tfor (const c of checks) {\n\t\tswitch (c.kind) {\n\t\t\tcase \"int\":\n\t\t\tcase \"safeint\": isInt = true; break;\n\t\t\tcase \"min\": out.minimum = c.value; break;\n\t\t\tcase \"max\": out.maximum = c.value; break;\n\t\t\tcase \"finite\":\n\t\t\tcase \"multipleOf\":\n\t\t\t\t// `multipleOf` accepts arbitrary numbers; we skip the\n\t\t\t\t// stricter check that the value is present.\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tif (isInt) out.type = \"integer\";\n\treturn out;\n}\n\nfunction convertObject(\n\t_schema: unknown,\n\tdef: ZodDef,\n\tdefs: Record<string, JSONSchema>,\n\tvisited: WeakSet<object>,\n): JSONSchema {\n\tconst shapeFn = (def as { shape?: unknown }).shape;\n\tconst shape = typeof shapeFn === \"function\" ? (shapeFn as () => Record<string, unknown>)() : shapeFn;\n\tconst properties: Record<string, JSONSchema> = {};\n\tconst required: string[] = [];\n\tconst catchall = (def as { catchall?: unknown }).catchall;\n\tif (shape && typeof shape === \"object\") {\n\t\tfor (const [key, value] of Object.entries(shape)) {\n\t\t\tconst child = zodToJsonSchema(value, { $defs: defs, visited });\n\t\t\tconst childDef = readDef(value);\n\t\t\t// Zod: optional / nullable / default are NOT in `required`.\n\t\t\tconst isOptional =\n\t\t\t\tchildDef.typeName === \"ZodOptional\" ||\n\t\t\t\tchildDef.typeName === \"ZodDefault\" ||\n\t\t\t\tchildDef.typeName === \"ZodCatch\";\n\t\t\tproperties[key] = child;\n\t\t\tif (!isOptional) required.push(key);\n\t\t}\n\t}\n\tconst description = (def as { description?: string }).description;\n\tconst out: JSONSchema = { type: \"object\", properties };\n\tif (required.length > 0) out.required = required;\n\tif (typeof catchall === \"object\" && catchall !== null) {\n\t\tconst c = readDef(catchall);\n\t\t// `ZodNever` catchall = strict; `ZodAny`/`ZodUnknown` = passthrough.\n\t\tif (c.typeName === \"ZodNever\") out.additionalProperties = false;\n\t\telse out.additionalProperties = true;\n\t}\n\tif (description) out.description = description;\n\treturn out;\n}\n\nfunction convertArray(\n\t_schema: unknown,\n\tdef: ZodDef,\n\tdefs: Record<string, JSONSchema>,\n\tvisited: WeakSet<object>,\n): JSONSchema {\n\tconst out: JSONSchema = { type: \"array\" };\n\tconst element = (def as { element?: unknown; type?: unknown }).element\n\t\t?? (def as { type?: unknown }).type;\n\tif (element) out.items = zodToJsonSchema(element, { $defs: defs, visited });\n\tconst checks = (def as { minLength?: { value: number }; maxLength?: { value: number } });\n\tif (checks.minLength?.value != null) out.minItems = checks.minLength.value;\n\tif (checks.maxLength?.value != null) out.maxItems = checks.maxLength.value;\n\treturn out;\n}\n\nfunction jsonTypeOf(v: unknown): \"string\" | \"number\" | \"boolean\" | \"object\" | \"null\" {\n\tif (v === null) return \"null\";\n\tif (typeof v === \"string\") return \"string\";\n\tif (typeof v === \"number\") return \"number\";\n\tif (typeof v === \"boolean\") return \"boolean\";\n\treturn \"object\";\n}\n\nfunction safeCall<T>(fn: unknown): T {\n\ttry {\n\t\treturn (fn as () => T)();\n\t} catch {\n\t\treturn undefined as unknown as T;\n\t}\n}",
9
- "/**\n * `OpenAPIModule` — drop-in OpenAPI 3.1 + Scalar UI.\n *\n * @Module({\n * imports: [\n * OpenAPIModule.forRoot({\n * info: { title: 'My API', version: '1.0.0' },\n * servers: [{ url: 'http://localhost:3000' }],\n * }),\n * ],\n * })\n * export class AppModule {}\n *\n * After boot, the framework exposes:\n *\n * GET /openapi.json — the OpenAPI 3.1 spec\n * GET /docs — the Scalar UI\n *\n * To feed routes to the spec, the application must call\n * `OpenAPIService.setRoutes(...)` after the router is built. The\n * recommended way is to read routes from the `NexusServer` instance\n * inside the module's onModuleInit hook (see the helper below).\n */\nimport { Module } from \"@nexusts/core\";\nimport { OpenAPIService } from \"./openapi.service.js\";\nimport type { OpenAPIConfig } from \"./types.js\";\nimport { safeGetMeta, safeDefineMeta, safeHasMeta } from \"@nexusts/core/di/safe-reflect\";\n\n@Module({\n\tproviders: [\n\t\tOpenAPIService,\n\t\t{ provide: OpenAPIService.TOKEN, useExisting: OpenAPIService },\n\t],\n\texports: [OpenAPIService, OpenAPIService.TOKEN],\n})\nexport class OpenAPIModule {\n\tstatic forRoot(config: OpenAPIConfig) {\n\t\t@Module({\n\t\t\tproviders: [\n\t\t\t\tOpenAPIService,\n\t\t\t\t{ provide: OpenAPIService.TOKEN, useExisting: OpenAPIService },\n\t\t\t\t{ provide: \"OPENAPI_CONFIG\", useValue: config },\n\t\t\t],\n\t\t\texports: [OpenAPIService, OpenAPIService.TOKEN],\n\t\t})\n\t\tclass ConfiguredOpenAPIModule {}\n\t\tObject.defineProperty(ConfiguredOpenAPIModule, \"name\", {\n\t\t\tvalue: \"ConfiguredOpenAPIModule\",\n\t\t});\n\t\treturn ConfiguredOpenAPIModule;\n\t}\n\n\t/**\n\t * Mount the spec + Scalar UI on an existing Hono app. The user\n\t * calls this once, after the framework's router is built, passing\n\t * the route list.\n\t *\n\t * import { mountOpenAPI } from 'nexusjs/openapi';\n\t * const openapi = new OpenAPIService(config);\n\t * openapi.setRoutes(routes);\n\t * mountOpenAPI(app, openapi, config);\n\t */\n\tstatic mount(\n\t\tapp: { use: (path: string, ...handlers: any[]) => any; get: (path: string, ...handlers: any[]) => any },\n\t\tsvc: OpenAPIService,\n\t\tconfig: OpenAPIConfig,\n\t): void {\n\t\tconst specPath = config.specPath ?? \"/openapi.json\";\n\t\tconst docsPath = config.path ?? \"/docs\";\n\t\t// The route handlers are evaluated lazily at request time.\n\t\tapp.get(specPath, (c: any) => c.json(svc.getSpec(), 200, { \"Content-Type\": \"application/json\" }));\n\t\tapp.get(docsPath, (c: any) => {\n\t\t\t// We import lazily to avoid a circular dep.\n\t\t\tconst { scalarHtml } = require(\"./scalar.js\") as typeof import(\"./scalar.js\");\n\t\t\tconst html = scalarHtml({\n\t\t\t\ttitle: config.info.title,\n\t\t\t\tspecUrl: specPath,\n\t\t\t});\n\t\t\treturn c.html(html, 200, { \"Content-Type\": \"text/html; charset=utf-8\" });\n\t\t});\n\t}\n}",
9
+ "/**\n * `OpenAPIModule` — drop-in OpenAPI 3.1 + Scalar UI.\n *\n * @Module({\n * imports: [\n * OpenAPIModule.forRoot({\n * info: { title: 'My API', version: '1.0.0' },\n * servers: [{ url: 'http://localhost:3000' }],\n * }),\n * ],\n * })\n * export class AppModule {}\n *\n * After boot, the framework exposes:\n *\n * GET /openapi.json — the OpenAPI 3.1 spec\n * GET /docs — the Scalar UI\n *\n * To feed routes to the spec, the application must call\n * `OpenAPIService.setRoutes(...)` after the router is built. The\n * recommended way is to read routes from the `NexusServer` instance\n * inside the module's onModuleInit hook (see the helper below).\n */\nimport { Module } from \"@nexusts/core\";\nimport { OpenAPIService } from \"./openapi.service.js\";\nimport type { OpenAPIConfig } from \"./types.js\";\nimport { safeGetMeta, safeDefineMeta, safeHasMeta } from \"@nexusts/core/di/safe-reflect\";\n\n@Module({\n\tproviders: [\n\t\tOpenAPIService,\n\t\t{ provide: OpenAPIService.TOKEN, useExisting: OpenAPIService },\n\t],\n\texports: [OpenAPIService, OpenAPIService.TOKEN],\n})\nexport class OpenAPIModule {\n\tstatic forRoot(config: OpenAPIConfig) {\n\t\t@Module({\n\t\t\tproviders: [\n\t\t\t\tOpenAPIService,\n\t\t\t\t{ provide: OpenAPIService.TOKEN, useExisting: OpenAPIService },\n\t\t\t\t{ provide: \"OPENAPI_CONFIG\", useValue: config },\n\t\t\t],\n\t\t\texports: [OpenAPIService, OpenAPIService.TOKEN],\n\t\t})\n\t\tclass ConfiguredOpenAPIModule {}\n\t\tObject.defineProperty(ConfiguredOpenAPIModule, \"name\", {\n\t\t\tvalue: \"ConfiguredOpenAPIModule\",\n\t\t});\n\t\treturn ConfiguredOpenAPIModule;\n\t}\n\n\t/**\n\t * Mount the spec + Scalar UI on an existing Hono app. The user\n\t * calls this once, after the framework's router is built, passing\n\t * the route list.\n\t *\n\t * import { mountOpenAPI } from '@nexusts/openapi';\n\t * const openapi = new OpenAPIService(config);\n\t * openapi.setRoutes(routes);\n\t * mountOpenAPI(app, openapi, config);\n\t */\n\tstatic mount(\n\t\tapp: { use: (path: string, ...handlers: any[]) => any; get: (path: string, ...handlers: any[]) => any },\n\t\tsvc: OpenAPIService,\n\t\tconfig: OpenAPIConfig,\n\t): void {\n\t\tconst specPath = config.specPath ?? \"/openapi.json\";\n\t\tconst docsPath = config.path ?? \"/docs\";\n\t\t// The route handlers are evaluated lazily at request time.\n\t\tapp.get(specPath, (c: any) => c.json(svc.getSpec(), 200, { \"Content-Type\": \"application/json\" }));\n\t\tapp.get(docsPath, (c: any) => {\n\t\t\t// We import lazily to avoid a circular dep.\n\t\t\tconst { scalarHtml } = require(\"./scalar.js\") as typeof import(\"./scalar.js\");\n\t\t\tconst html = scalarHtml({\n\t\t\t\ttitle: config.info.title,\n\t\t\t\tspecUrl: specPath,\n\t\t\t});\n\t\t\treturn c.html(html, 200, { \"Content-Type\": \"text/html; charset=utf-8\" });\n\t\t});\n\t}\n}",
10
10
  "/**\n * `@ApiTags('Users', 'Admin')` — group operations under one or more\n * tags in the OpenAPI spec.\n */\nimport { safeGetMeta, safeDefineMeta } from \"@nexusts/core/di/safe-reflect\";\nimport { OPENAPI_META } from \"../types.js\";\n\nexport function ApiTags(...tags: string[]): ClassDecorator {\n\treturn (target: any) => {\n\t\tconst existing: string[] = safeGetMeta(OPENAPI_META.TAGS, target) ?? [];\n\t\tsafeDefineMeta(OPENAPI_META.TAGS, [...existing, ...tags], target);\n\t};\n}\n",
11
11
  "/**\n * `@ApiOperation({ summary, description, operationId, tags, deprecated })`\n *\n * Decorate a controller method to describe the operation in the spec.\n */\nimport { OPENAPI_META, type ApiOperationOptions } from \"../types.js\";\nimport { safeGetMeta, safeDefineMeta, safeHasMeta } from \"@nexusts/core/di/safe-reflect\";\n\nexport function ApiOperation(options: ApiOperationOptions): MethodDecorator {\n\treturn (target: object, propertyKey: string | symbol) => {\n\t\tsafeDefineMeta(OPENAPI_META.OPERATION, options, target.constructor, propertyKey);\n\t};\n}",
12
12
  "/**\n * `@ApiResponse(200, { description: 'OK', schema: UserSchema })`\n *\n * Decorate a controller method to describe one of its responses.\n * Multiple `@ApiResponse` calls accumulate.\n */\nimport { OPENAPI_META, type ApiResponseOptions } from \"../types.js\";\nimport { safeGetMeta, safeDefineMeta, safeHasMeta } from \"@nexusts/core/di/safe-reflect\";\n\nexport function ApiResponse(\n\tstatus: number | string,\n\toptions: ApiResponseOptions,\n): MethodDecorator {\n\treturn (target: object, propertyKey: string | symbol) => {\n\t\tconst existing: Array<[string, ApiResponseOptions]> =\n\t\t\tsafeGetMeta(OPENAPI_META.RESPONSES, target.constructor, propertyKey) ?? [];\n\t\texisting.push([String(status), options]);\n\t\tsafeDefineMeta(OPENAPI_META.RESPONSES, existing, target.constructor, propertyKey);\n\t};\n}",
@@ -9,7 +9,7 @@ export declare class OpenAPIModule {
9
9
  * calls this once, after the framework's router is built, passing
10
10
  * the route list.
11
11
  *
12
- * import { mountOpenAPI } from 'nexusjs/openapi';
12
+ * import { mountOpenAPI } from '@nexusts/openapi';
13
13
  * const openapi = new OpenAPIService(config);
14
14
  * openapi.setRoutes(routes);
15
15
  * mountOpenAPI(app, openapi, config);
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  import { safeGetMeta, safeDefineMeta, safeHasMeta } from "@nexusts/core/di/safe-reflect";
3
- * `nexusjs/openapi` — OpenAPI 3.1 + Scalar UI.
3
+ * `@nexusts/openapi` — OpenAPI 3.1 + Scalar UI.
4
4
  *
5
5
  * @Module({
6
6
  * imports: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexusts/openapi",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "OpenAPI 3.1 spec generation from Zod",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@nexusts/core": "^0.9.0"
29
+ "@nexusts/core": "^0.9.1"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",