@my-nestjs-kit/openapi 0.0.0-stage → 0.1.0-dev.20261129010337

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sabationok
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,40 @@
1
- # Temporary Holding Version
1
+ # @my-nestjs-kit/openapi
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ```sh
4
+ npm i @my-nestjs-kit/openapi
5
+ ```
6
+
7
+ Peers: `@nestjs/common`, `@nestjs/swagger`; optional, only for the matching UI: `redoc-express`, `@scalar/nestjs-api-reference`, `js-yaml`. No other kit package.
8
+
9
+ Builds the OpenAPI document once at bootstrap and mounts the docs UIs the app chooses. UI libs are optional peers, loaded only when their UI is in `uis`.
10
+
11
+ ```ts
12
+ // app.module.ts
13
+ OpenApiModule.forRoot({
14
+ document: (b) => b.setTitle('My API').setVersion('1.0').addBearerAuth(),
15
+ documentRoute: { path: 'v1/docs', decorators: [Public()] }, // optional Nest route returning the document
16
+ uis: [
17
+ swaggerUi({ path: 'api' }), // /api, /api-json, /api-yaml
18
+ redocUi({ path: '/api/docs', specUrl: '/api-json' }), // needs redoc-express
19
+ scalarUi({ path: '/api/reference', theme: 'purple' }), // needs @scalar/nestjs-api-reference
20
+ specRoutes({ jsonPath: '/openapi.json', yamlPath: '/openapi.yaml' }),
21
+ ],
22
+ validateRefs: true, // default: throw on broken $refs
23
+ });
24
+ // or OpenApiModule.forRootAsync({ imports, inject, useFactory, documentRoute })
25
+
26
+ // main.ts, after global prefix / middlewares, before listen
27
+ await OpenApiModule.setup(app);
28
+ ```
29
+
30
+ - Inject `OpenApiService` to read `document`. `OpenApiModule.document` is a static accessor for code outside DI (legacy).
31
+ - UI paths are absolute; the global prefix is not applied (same as `SwaggerModule.setup`).
32
+ - UIs are mounted as HTTP middlewares, so guards do not run on them. `documentRoute` is a real Nest route, so pass the app's public-route decorator.
33
+ - Custom UI: any `{ name, mount({ app, document }) }` object.
34
+
35
+ ## Decorators (in `@my-nestjs-kit/core`)
36
+
37
+ The property and controller decorators live in `@my-nestjs-kit/core`, because core's entities, dtos and validators use them:
38
+
39
+ - `ApiPropDescriptor(opts)` — Swagger property metadata (`hidden`, `each`, `optional` default `true`). Used by the kit's composite validation decorators.
40
+ - `ControllerMeta(prefix, { apiTags?, apiAuth? })` — `@Controller` + `@ApiTags` + auth schemes (`jwt`, `p_token`, `x_token*`, `jwt_refresh_*`).
@@ -0,0 +1,10 @@
1
+ import { OpenAPIObject } from '@nestjs/swagger';
2
+ /**
3
+ * Validates every $ref in an OpenAPI document:
4
+ * - catches malformed refs like "#/components/schemas/"
5
+ * - catches refs to missing components
6
+ * - throws a report with the location path of each issue
7
+ */
8
+ export declare function assertOpenApiRefs(doc: OpenAPIObject, opts?: {
9
+ maxNodes?: number;
10
+ }): void;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertOpenApiRefs = void 0;
4
+ function getByJsonPointer(doc, ref) {
5
+ if (typeof ref !== 'string')
6
+ return undefined;
7
+ if (!ref.startsWith('#/'))
8
+ return undefined;
9
+ const parts = ref
10
+ .slice(2)
11
+ .split('/')
12
+ .map((p) => decodeURIComponent(p));
13
+ let cur = doc;
14
+ for (const p of parts) {
15
+ cur = cur?.[p];
16
+ if (cur == null)
17
+ return undefined;
18
+ }
19
+ return cur;
20
+ }
21
+ /**
22
+ * Validates every $ref in an OpenAPI document:
23
+ * - catches malformed refs like "#/components/schemas/"
24
+ * - catches refs to missing components
25
+ * - throws a report with the location path of each issue
26
+ */
27
+ function assertOpenApiRefs(doc, opts) {
28
+ const maxNodes = opts?.maxNodes ?? 500_000; // safety against huge docs
29
+ const issues = [];
30
+ let visited = 0;
31
+ const seenObjs = new WeakSet();
32
+ function walk(node, at) {
33
+ if (visited++ > maxNodes) {
34
+ throw new Error(`OpenAPI ref scan aborted: exceeded maxNodes=${maxNodes}`);
35
+ }
36
+ if (node == null)
37
+ return;
38
+ if (typeof node !== 'object')
39
+ return;
40
+ // avoid infinite loops on shared objects
41
+ if (typeof node === 'object') {
42
+ if (seenObjs.has(node))
43
+ return;
44
+ seenObjs.add(node);
45
+ }
46
+ if (typeof node.$ref !== 'undefined') {
47
+ const ref = node.$ref;
48
+ // invalid ref
49
+ if (typeof ref !== 'string' ||
50
+ ref.trim() === '' ||
51
+ ref.endsWith('/schemas/')) {
52
+ issues.push({ kind: 'INVALID_REF', ref, at });
53
+ // keep walking to collect every issue
54
+ }
55
+ else {
56
+ const resolved = getByJsonPointer(doc, ref);
57
+ if (!resolved) {
58
+ issues.push({ kind: 'UNRESOLVED_REF', ref, at });
59
+ }
60
+ }
61
+ }
62
+ if (Array.isArray(node)) {
63
+ for (let i = 0; i < node.length; i++) {
64
+ walk(node[i], `${at}[${i}]`);
65
+ }
66
+ return;
67
+ }
68
+ for (const [k, v] of Object.entries(node)) {
69
+ walk(v, at ? `${at}.${k}` : k);
70
+ }
71
+ }
72
+ walk(doc, 'doc');
73
+ if (issues.length) {
74
+ const knownSchemas = Object.keys(doc.components?.schemas ?? {});
75
+ const sampleSchemas = knownSchemas.slice(0, 50).join(', ');
76
+ const lines = issues.slice(0, 50).map((x, i) => {
77
+ if (x.kind === 'INVALID_REF') {
78
+ return `${i + 1}. [INVALID_REF] at=${x.at} ref=${JSON.stringify(x.ref)}`;
79
+ }
80
+ return `${i + 1}. [UNRESOLVED_REF] at=${x.at} ref=${x.ref}`;
81
+ });
82
+ const more = issues.length > 50 ? `\n...and ${issues.length - 50} more` : '';
83
+ throw new Error([
84
+ `OpenAPI $ref validation failed: ${issues.length} issue(s)`,
85
+ `Known components.schemas (sample): ${sampleSchemas}${knownSchemas.length > 50 ? ', ...' : ''}`,
86
+ '',
87
+ ...lines,
88
+ more,
89
+ ].join('\n'));
90
+ }
91
+ }
92
+ exports.assertOpenApiRefs = assertOpenApiRefs;
@@ -0,0 +1,2 @@
1
+ /** Loads an optional peer dependency only when the UI that needs it is chosen. */
2
+ export declare function optionalRequire<T = any>(pkg: string, usedBy: string): T;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.optionalRequire = void 0;
4
+ /** Loads an optional peer dependency only when the UI that needs it is chosen. */
5
+ function optionalRequire(pkg, usedBy) {
6
+ try {
7
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8
+ return require(pkg);
9
+ }
10
+ catch (e) {
11
+ if (e?.code === 'MODULE_NOT_FOUND') {
12
+ throw new Error(`[OpenApiModule] ${usedBy} needs "${pkg}". Install it: npm i ${pkg}`);
13
+ }
14
+ throw e;
15
+ }
16
+ }
17
+ exports.optionalRequire = optionalRequire;
@@ -0,0 +1,8 @@
1
+ export * from './openapi.types';
2
+ export * from './openapi.service';
3
+ export * from './openapi.module';
4
+ export * from './helpers/assert-openapi-refs';
5
+ export * from './uis/swagger.ui';
6
+ export * from './uis/redoc.ui';
7
+ export * from './uis/scalar.ui';
8
+ export * from './uis/spec-routes.ui';
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // @my-nestjs-kit/openapi — OpenAPI document + pluggable docs UIs (Swagger UI, Redoc, Scalar, raw spec routes).
18
+ // The property / controller decorators (ApiPropDescriptor, ControllerMeta, ...) live in @my-nestjs-kit/core.
19
+ __exportStar(require("./openapi.types"), exports);
20
+ __exportStar(require("./openapi.service"), exports);
21
+ __exportStar(require("./openapi.module"), exports);
22
+ __exportStar(require("./helpers/assert-openapi-refs"), exports);
23
+ __exportStar(require("./uis/swagger.ui"), exports);
24
+ __exportStar(require("./uis/redoc.ui"), exports);
25
+ __exportStar(require("./uis/scalar.ui"), exports);
26
+ __exportStar(require("./uis/spec-routes.ui"), exports);
@@ -0,0 +1,16 @@
1
+ import { DynamicModule, INestApplication } from '@nestjs/common';
2
+ import { OpenAPIObject } from '@nestjs/swagger';
3
+ import { OpenApiDocumentRoute, OpenApiModuleAsyncOptions, OpenApiModuleOptions } from './openapi.types';
4
+ export declare class OpenApiModule {
5
+ /**
6
+ * Legacy accessor for code outside DI (free functions). Prefer injecting `OpenApiService`.
7
+ */
8
+ static get document(): OpenAPIObject;
9
+ static forRoot(options: OpenApiModuleOptions & {
10
+ documentRoute?: OpenApiDocumentRoute;
11
+ }): DynamicModule;
12
+ static forRootAsync(options: OpenApiModuleAsyncOptions): DynamicModule;
13
+ /** Builds the document from the initialised app and mounts the chosen UIs. Call once in bootstrap, before `listen`. */
14
+ static setup(app: INestApplication): Promise<OpenAPIObject>;
15
+ private static build;
16
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var OpenApiModule_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.OpenApiModule = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const openapi_types_1 = require("./openapi.types");
16
+ const openapi_service_1 = require("./openapi.service");
17
+ let lastDocument;
18
+ let OpenApiModule = OpenApiModule_1 = class OpenApiModule {
19
+ /**
20
+ * Legacy accessor for code outside DI (free functions). Prefer injecting `OpenApiService`.
21
+ */
22
+ static get document() {
23
+ return lastDocument;
24
+ }
25
+ static forRoot(options) {
26
+ const { documentRoute, ...rest } = options;
27
+ return this.build({ provide: openapi_types_1.OPENAPI_MODULE_OPTIONS, useValue: rest }, documentRoute);
28
+ }
29
+ static forRootAsync(options) {
30
+ return this.build({
31
+ provide: openapi_types_1.OPENAPI_MODULE_OPTIONS,
32
+ useFactory: options.useFactory,
33
+ inject: options.inject ?? [],
34
+ }, options.documentRoute, options.imports);
35
+ }
36
+ /** Builds the document from the initialised app and mounts the chosen UIs. Call once in bootstrap, before `listen`. */
37
+ static async setup(app) {
38
+ lastDocument = await app.get(openapi_service_1.OpenApiService).setup(app);
39
+ return lastDocument;
40
+ }
41
+ static build(optionsProvider, documentRoute, imports) {
42
+ return {
43
+ module: OpenApiModule_1,
44
+ global: true,
45
+ imports,
46
+ controllers: documentRoute
47
+ ? [createDocumentController(documentRoute)]
48
+ : [],
49
+ providers: [optionsProvider, openapi_service_1.OpenApiService],
50
+ exports: [openapi_service_1.OpenApiService],
51
+ };
52
+ }
53
+ };
54
+ exports.OpenApiModule = OpenApiModule;
55
+ exports.OpenApiModule = OpenApiModule = OpenApiModule_1 = __decorate([
56
+ (0, common_1.Module)({})
57
+ ], OpenApiModule);
58
+ function createDocumentController(route) {
59
+ let OpenApiDocumentController = class OpenApiDocumentController {
60
+ constructor(_openApi) {
61
+ this._openApi = _openApi;
62
+ }
63
+ getDocument() {
64
+ return this._openApi.document;
65
+ }
66
+ };
67
+ __decorate([
68
+ (0, common_1.Get)(route.path),
69
+ __metadata("design:type", Function),
70
+ __metadata("design:paramtypes", []),
71
+ __metadata("design:returntype", void 0)
72
+ ], OpenApiDocumentController.prototype, "getDocument", null);
73
+ OpenApiDocumentController = __decorate([
74
+ (0, common_1.Controller)(),
75
+ __metadata("design:paramtypes", [openapi_service_1.OpenApiService])
76
+ ], OpenApiDocumentController);
77
+ const proto = OpenApiDocumentController.prototype;
78
+ for (const decorator of route.decorators ?? []) {
79
+ decorator(proto, 'getDocument', Object.getOwnPropertyDescriptor(proto, 'getDocument'));
80
+ }
81
+ return OpenApiDocumentController;
82
+ }
@@ -0,0 +1,10 @@
1
+ import { INestApplication } from '@nestjs/common';
2
+ import { OpenAPIObject } from '@nestjs/swagger';
3
+ import { OpenApiModuleOptions } from './openapi.types';
4
+ export declare class OpenApiService {
5
+ private readonly _options;
6
+ private _document?;
7
+ constructor(_options: OpenApiModuleOptions);
8
+ get document(): OpenAPIObject;
9
+ setup(app: INestApplication): Promise<OpenAPIObject>;
10
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OpenApiService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const swagger_1 = require("@nestjs/swagger");
18
+ const openapi_types_1 = require("./openapi.types");
19
+ const assert_openapi_refs_1 = require("./helpers/assert-openapi-refs");
20
+ let OpenApiService = class OpenApiService {
21
+ constructor(_options) {
22
+ this._options = _options;
23
+ }
24
+ get document() {
25
+ if (!this._document) {
26
+ throw new Error('[OpenApiModule] document is not built yet: call OpenApiModule.setup(app) in bootstrap');
27
+ }
28
+ return this._document;
29
+ }
30
+ async setup(app) {
31
+ const { document, documentOptions, uis = [], validateRefs = true } = this._options;
32
+ this._document = swagger_1.SwaggerModule.createDocument(app, document(new swagger_1.DocumentBuilder()).build(), documentOptions);
33
+ if (validateRefs)
34
+ (0, assert_openapi_refs_1.assertOpenApiRefs)(this._document);
35
+ for (const ui of uis) {
36
+ await ui.mount({ app, document: this._document });
37
+ }
38
+ return this._document;
39
+ }
40
+ };
41
+ exports.OpenApiService = OpenApiService;
42
+ exports.OpenApiService = OpenApiService = __decorate([
43
+ (0, common_1.Injectable)(),
44
+ __param(0, (0, common_1.Inject)(openapi_types_1.OPENAPI_MODULE_OPTIONS)),
45
+ __metadata("design:paramtypes", [Object])
46
+ ], OpenApiService);
@@ -0,0 +1,32 @@
1
+ import { INestApplication, ModuleMetadata } from '@nestjs/common';
2
+ import { DocumentBuilder, OpenAPIObject, SwaggerDocumentOptions } from '@nestjs/swagger';
3
+ export declare const OPENAPI_MODULE_OPTIONS: unique symbol;
4
+ export interface OpenApiUiContext {
5
+ app: INestApplication;
6
+ document: OpenAPIObject;
7
+ }
8
+ /** One pluggable docs surface (Swagger UI, Redoc, Scalar, raw spec routes, ...). Paths are absolute, the global prefix is not applied. */
9
+ export interface OpenApiUi {
10
+ readonly name: string;
11
+ mount(ctx: OpenApiUiContext): void | Promise<void>;
12
+ }
13
+ export interface OpenApiModuleOptions {
14
+ /** Fills a fresh `DocumentBuilder` (title, version, auth schemes). */
15
+ document: (builder: DocumentBuilder) => DocumentBuilder;
16
+ documentOptions?: SwaggerDocumentOptions;
17
+ /** UIs to mount on `OpenApiModule.setup(app)`; only the chosen ones load their libs. */
18
+ uis?: OpenApiUi[];
19
+ /** Throw on broken `$ref`s after the document is generated. Default `true`. */
20
+ validateRefs?: boolean;
21
+ }
22
+ /** Nest route that returns the generated document (goes through guards/interceptors, unlike UI middlewares). */
23
+ export interface OpenApiDocumentRoute {
24
+ path: string;
25
+ /** Method decorators applied to the route, e.g. the app's public-route marker. */
26
+ decorators?: MethodDecorator[];
27
+ }
28
+ export interface OpenApiModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
29
+ inject?: any[];
30
+ useFactory: (...args: any[]) => OpenApiModuleOptions | Promise<OpenApiModuleOptions>;
31
+ documentRoute?: OpenApiDocumentRoute;
32
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPENAPI_MODULE_OPTIONS = void 0;
4
+ exports.OPENAPI_MODULE_OPTIONS = Symbol('OPENAPI_MODULE_OPTIONS');
@@ -0,0 +1,11 @@
1
+ import { OpenApiUi } from '../openapi.types';
2
+ export interface RedocUiOptions {
3
+ path: string;
4
+ /** URL Redoc fetches the spec from, e.g. the Swagger UI `-json` route or a `specRoutes` path. */
5
+ specUrl: string;
6
+ title?: string;
7
+ /** Passed to Redoc as `redocOptions` (theme, ...). */
8
+ redocOptions?: Record<string, unknown>;
9
+ }
10
+ /** Needs `redoc-express`. */
11
+ export declare function redocUi({ path, specUrl, title, redocOptions, }: RedocUiOptions): OpenApiUi;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redocUi = void 0;
4
+ const optional_require_1 = require("../helpers/optional-require");
5
+ /** Needs `redoc-express`. */
6
+ function redocUi({ path, specUrl, title = 'API Reference', redocOptions, }) {
7
+ return {
8
+ name: 'redoc',
9
+ mount: ({ app }) => {
10
+ const mod = (0, optional_require_1.optionalRequire)('redoc-express', 'redocUi');
11
+ const redoc = mod.default ?? mod;
12
+ app.use(path, redoc({ title, specUrl, redocOptions }));
13
+ },
14
+ };
15
+ }
16
+ exports.redocUi = redocUi;
@@ -0,0 +1,10 @@
1
+ import { OpenApiUi } from '../openapi.types';
2
+ export interface ScalarUiOptions {
3
+ path: string;
4
+ /** Scalar theme name (`default`, `purple`, `saturn`, `kepler`, `mars`, `deepSpace`, ...). */
5
+ theme?: string;
6
+ /** Any other Scalar API reference configuration. */
7
+ options?: Record<string, unknown>;
8
+ }
9
+ /** Needs `@scalar/nestjs-api-reference`; the document is embedded, no spec URL required. */
10
+ export declare function scalarUi({ path, theme, options }: ScalarUiOptions): OpenApiUi;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scalarUi = void 0;
4
+ const optional_require_1 = require("../helpers/optional-require");
5
+ /** Needs `@scalar/nestjs-api-reference`; the document is embedded, no spec URL required. */
6
+ function scalarUi({ path, theme, options }) {
7
+ return {
8
+ name: 'scalar',
9
+ mount: ({ app, document }) => {
10
+ const { apiReference } = (0, optional_require_1.optionalRequire)('@scalar/nestjs-api-reference', 'scalarUi');
11
+ app.use(path, apiReference({ theme, ...options, content: document }));
12
+ },
13
+ };
14
+ }
15
+ exports.scalarUi = scalarUi;
@@ -0,0 +1,8 @@
1
+ import { OpenApiUi } from '../openapi.types';
2
+ export interface SpecRoutesOptions {
3
+ jsonPath?: string;
4
+ /** Needs `js-yaml` (already a dependency of `@nestjs/swagger`). */
5
+ yamlPath?: string;
6
+ }
7
+ /** Raw spec endpoints without any UI (for codegen, AI tooling, or a UI that fetches by URL). */
8
+ export declare function specRoutes({ jsonPath, yamlPath }: SpecRoutesOptions): OpenApiUi;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.specRoutes = void 0;
4
+ const optional_require_1 = require("../helpers/optional-require");
5
+ /** Raw spec endpoints without any UI (for codegen, AI tooling, or a UI that fetches by URL). */
6
+ function specRoutes({ jsonPath, yamlPath }) {
7
+ return {
8
+ name: 'spec-routes',
9
+ mount: ({ app, document }) => {
10
+ const http = app.getHttpAdapter();
11
+ if (jsonPath) {
12
+ http.get(jsonPath, (_req, res) => {
13
+ http.setHeader(res, 'Content-Type', 'application/json');
14
+ http.reply(res, document, 200);
15
+ });
16
+ }
17
+ if (yamlPath) {
18
+ const yaml = (0, optional_require_1.optionalRequire)('js-yaml', 'specRoutes.yamlPath');
19
+ const body = yaml.dump(document, { skipInvalid: true, noRefs: true });
20
+ http.get(yamlPath, (_req, res) => {
21
+ http.setHeader(res, 'Content-Type', 'text/yaml');
22
+ http.reply(res, body, 200);
23
+ });
24
+ }
25
+ },
26
+ };
27
+ }
28
+ exports.specRoutes = specRoutes;
@@ -0,0 +1,8 @@
1
+ import { SwaggerCustomOptions } from '@nestjs/swagger';
2
+ import { OpenApiUi } from '../openapi.types';
3
+ export interface SwaggerUiOptions {
4
+ /** UI at `/<path>`, spec at `/<path>-json` and `/<path>-yaml`. */
5
+ path: string;
6
+ options?: SwaggerCustomOptions;
7
+ }
8
+ export declare function swaggerUi({ path, options }: SwaggerUiOptions): OpenApiUi;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.swaggerUi = void 0;
4
+ const swagger_1 = require("@nestjs/swagger");
5
+ function swaggerUi({ path, options }) {
6
+ return {
7
+ name: 'swagger',
8
+ mount: ({ app, document }) => swagger_1.SwaggerModule.setup(path, app, document, options),
9
+ };
10
+ }
11
+ exports.swaggerUi = swaggerUi;
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
2
  "name": "@my-nestjs-kit/openapi",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-dev.20261129010337",
4
+ "description": "OpenAPI for NestJS: one document service and pluggable docs UIs (Swagger UI, Redoc, Scalar, raw spec routes).",
5
+ "keywords": [
6
+ "nestjs",
7
+ "nest",
8
+ "openapi",
9
+ "swagger",
10
+ "redoc",
11
+ "scalar"
12
+ ],
13
+ "license": "MIT",
14
+ "homepage": "https://github.com/sabationok/my-nestjs-kit/tree/main/packages/openapi#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/sabationok/my-nestjs-kit/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/sabationok/my-nestjs-kit.git",
21
+ "directory": "packages/openapi"
22
+ },
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "main": "dist/index.js",
30
+ "types": "dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "require": "./dist/index.js",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "!dist/**/*.spec.*",
42
+ "!dist/**/*.tsbuildinfo",
43
+ "README.md",
44
+ "LICENSE"
45
+ ],
46
+ "peerDependencies": {
47
+ "@nestjs/common": "^10.4.1",
48
+ "@nestjs/swagger": "^7.4.0",
49
+ "@scalar/nestjs-api-reference": ">=0.4.0",
50
+ "js-yaml": "^4.1.0",
51
+ "redoc-express": "^2.1.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "@scalar/nestjs-api-reference": {
55
+ "optional": true
56
+ },
57
+ "redoc-express": {
58
+ "optional": true
59
+ },
60
+ "js-yaml": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "devDependencies": {
65
+ "@nestjs/common": "10.4.20",
66
+ "@nestjs/core": "10.4.1",
67
+ "@nestjs/swagger": "7.4.0",
68
+ "@types/node": "20.11.28",
69
+ "class-transformer": "0.5.1",
70
+ "class-validator": "0.14.1",
71
+ "reflect-metadata": "0.2.2",
72
+ "rxjs": "7.8.1",
73
+ "typescript": "5.4.2"
74
+ },
75
+ "scripts": {
76
+ "build": "rm -rf dist && tsc -p tsconfig.json",
77
+ "build:watch": "tsc -p tsconfig.json --watch",
78
+ "typecheck": "tsc -p tsconfig.json --noEmit"
79
+ }
6
80
  }