@digitaldefiance/node-express-suite 3.11.31 → 3.12.0
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/README.md +858 -0
- package/package.json +1 -1
- package/src/controllers/openapi.d.ts +67 -0
- package/src/controllers/openapi.d.ts.map +1 -0
- package/src/controllers/openapi.js +89 -0
- package/src/controllers/openapi.js.map +1 -0
- package/src/decorators/auth.d.ts +128 -0
- package/src/decorators/auth.d.ts.map +1 -0
- package/src/decorators/auth.js +230 -0
- package/src/decorators/auth.js.map +1 -0
- package/src/decorators/base-controller.d.ts +144 -6
- package/src/decorators/base-controller.d.ts.map +1 -1
- package/src/decorators/base-controller.js +487 -31
- package/src/decorators/base-controller.js.map +1 -1
- package/src/decorators/controller.d.ts +63 -7
- package/src/decorators/controller.d.ts.map +1 -1
- package/src/decorators/controller.js +70 -39
- package/src/decorators/controller.js.map +1 -1
- package/src/decorators/handler-args.d.ts +68 -0
- package/src/decorators/handler-args.d.ts.map +1 -0
- package/src/decorators/handler-args.js +83 -0
- package/src/decorators/handler-args.js.map +1 -0
- package/src/decorators/http-methods.d.ts +143 -0
- package/src/decorators/http-methods.d.ts.map +1 -0
- package/src/decorators/http-methods.js +265 -0
- package/src/decorators/http-methods.js.map +1 -0
- package/src/decorators/index.d.ts +22 -0
- package/src/decorators/index.d.ts.map +1 -1
- package/src/decorators/index.js +56 -0
- package/src/decorators/index.js.map +1 -1
- package/src/decorators/lifecycle.d.ts +248 -0
- package/src/decorators/lifecycle.d.ts.map +1 -0
- package/src/decorators/lifecycle.js +301 -0
- package/src/decorators/lifecycle.js.map +1 -0
- package/src/decorators/metadata-collector.d.ts +175 -0
- package/src/decorators/metadata-collector.d.ts.map +1 -0
- package/src/decorators/metadata-collector.js +272 -0
- package/src/decorators/metadata-collector.js.map +1 -0
- package/src/decorators/metadata-keys.d.ts +121 -0
- package/src/decorators/metadata-keys.d.ts.map +1 -0
- package/src/decorators/metadata-keys.js +116 -0
- package/src/decorators/metadata-keys.js.map +1 -0
- package/src/decorators/middleware.d.ts +181 -0
- package/src/decorators/middleware.d.ts.map +1 -0
- package/src/decorators/middleware.js +400 -0
- package/src/decorators/middleware.js.map +1 -0
- package/src/decorators/openapi-params.d.ts +192 -0
- package/src/decorators/openapi-params.d.ts.map +1 -0
- package/src/decorators/openapi-params.js +332 -0
- package/src/decorators/openapi-params.js.map +1 -0
- package/src/decorators/openapi.d.ts +201 -0
- package/src/decorators/openapi.d.ts.map +1 -0
- package/src/decorators/openapi.js +334 -0
- package/src/decorators/openapi.js.map +1 -0
- package/src/decorators/params.d.ts +217 -0
- package/src/decorators/params.d.ts.map +1 -0
- package/src/decorators/params.js +323 -0
- package/src/decorators/params.js.map +1 -0
- package/src/decorators/response.d.ts +200 -0
- package/src/decorators/response.d.ts.map +1 -0
- package/src/decorators/response.js +315 -0
- package/src/decorators/response.js.map +1 -0
- package/src/decorators/schema.d.ts +99 -0
- package/src/decorators/schema.d.ts.map +1 -0
- package/src/decorators/schema.js +329 -0
- package/src/decorators/schema.js.map +1 -0
- package/src/decorators/transaction.d.ts +69 -0
- package/src/decorators/transaction.d.ts.map +1 -0
- package/src/decorators/transaction.js +80 -0
- package/src/decorators/transaction.js.map +1 -0
- package/src/decorators/validation.d.ts +188 -0
- package/src/decorators/validation.d.ts.map +1 -0
- package/src/decorators/validation.js +269 -0
- package/src/decorators/validation.js.map +1 -0
- package/src/decorators/zod-validation.d.ts +164 -4
- package/src/decorators/zod-validation.d.ts.map +1 -1
- package/src/decorators/zod-validation.js +692 -13
- package/src/decorators/zod-validation.js.map +1 -1
- package/src/index.d.ts +2 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/interfaces/api-message-response.d.ts +1 -1
- package/src/interfaces/api-message-response.d.ts.map +1 -1
- package/src/interfaces/index.d.ts +1 -0
- package/src/interfaces/index.d.ts.map +1 -1
- package/src/interfaces/index.js +1 -0
- package/src/interfaces/index.js.map +1 -1
- package/src/interfaces/openApi/decoratorOptions.d.ts +760 -0
- package/src/interfaces/openApi/decoratorOptions.d.ts.map +1 -0
- package/src/interfaces/openApi/decoratorOptions.js +734 -0
- package/src/interfaces/openApi/decoratorOptions.js.map +1 -0
- package/src/interfaces/openApi/index.d.ts +8 -0
- package/src/interfaces/openApi/index.d.ts.map +1 -0
- package/src/interfaces/openApi/index.js +32 -0
- package/src/interfaces/openApi/index.js.map +1 -0
- package/src/interfaces/openApi/parameter.d.ts +41 -0
- package/src/interfaces/openApi/parameter.d.ts.map +1 -0
- package/src/interfaces/openApi/parameter.js +60 -0
- package/src/interfaces/openApi/parameter.js.map +1 -0
- package/src/interfaces/openApi/parameterSchema.d.ts +39 -0
- package/src/interfaces/openApi/parameterSchema.d.ts.map +1 -0
- package/src/interfaces/openApi/parameterSchema.js +51 -0
- package/src/interfaces/openApi/parameterSchema.js.map +1 -0
- package/src/interfaces/openApi/requestBody.d.ts +25 -0
- package/src/interfaces/openApi/requestBody.d.ts.map +1 -0
- package/src/interfaces/openApi/requestBody.js +31 -0
- package/src/interfaces/openApi/requestBody.js.map +1 -0
- package/src/interfaces/openApi/responseDef.d.ts +23 -0
- package/src/interfaces/openApi/responseDef.d.ts.map +1 -0
- package/src/interfaces/openApi/responseDef.js +29 -0
- package/src/interfaces/openApi/responseDef.js.map +1 -0
- package/src/interfaces/openApi/routeMetadata.d.ts +43 -0
- package/src/interfaces/openApi/routeMetadata.d.ts.map +1 -0
- package/src/interfaces/openApi/routeMetadata.js +85 -0
- package/src/interfaces/openApi/routeMetadata.js.map +1 -0
- package/src/openapi/builder.d.ts +249 -0
- package/src/openapi/builder.d.ts.map +1 -0
- package/src/openapi/builder.js +352 -0
- package/src/openapi/builder.js.map +1 -0
- package/src/openapi/controller.d.ts +153 -0
- package/src/openapi/controller.d.ts.map +1 -0
- package/src/openapi/controller.js +331 -0
- package/src/openapi/controller.js.map +1 -0
- package/src/openapi/index.d.ts +12 -0
- package/src/openapi/index.d.ts.map +1 -0
- package/src/openapi/index.js +20 -0
- package/src/openapi/index.js.map +1 -0
- package/src/openapi/markdown-generator.d.ts +52 -0
- package/src/openapi/markdown-generator.d.ts.map +1 -0
- package/src/openapi/markdown-generator.js +569 -0
- package/src/openapi/markdown-generator.js.map +1 -0
- package/src/openapi/middleware/index.d.ts +9 -0
- package/src/openapi/middleware/index.d.ts.map +1 -0
- package/src/openapi/middleware/index.js +15 -0
- package/src/openapi/middleware/index.js.map +1 -0
- package/src/openapi/middleware/redoc.d.ts +314 -0
- package/src/openapi/middleware/redoc.d.ts.map +1 -0
- package/src/openapi/middleware/redoc.js +181 -0
- package/src/openapi/middleware/redoc.js.map +1 -0
- package/src/openapi/middleware/swagger-ui.d.ts +123 -0
- package/src/openapi/middleware/swagger-ui.d.ts.map +1 -0
- package/src/openapi/middleware/swagger-ui.js +227 -0
- package/src/openapi/middleware/swagger-ui.js.map +1 -0
- package/src/openapi/schemas.d.ts +170 -0
- package/src/openapi/schemas.d.ts.map +1 -0
- package/src/openapi/schemas.js +340 -0
- package/src/openapi/schemas.js.map +1 -0
- package/src/registry/controller-registry.d.ts +78 -0
- package/src/registry/controller-registry.d.ts.map +1 -0
- package/src/registry/controller-registry.js +86 -0
- package/src/registry/controller-registry.js.map +1 -0
- package/src/registry/index.d.ts +2 -0
- package/src/registry/index.d.ts.map +1 -1
- package/src/registry/index.js +3 -1
- package/src/registry/index.js.map +1 -1
- package/src/routers/api.d.ts +2 -1
- package/src/routers/api.d.ts.map +1 -1
- package/src/routers/api.js +7 -1
- package/src/routers/api.js.map +1 -1
- package/src/routing/route-builder.d.ts +4 -4
- package/src/routing/route-builder.d.ts.map +1 -1
- package/src/routing/route-builder.js +1 -1
- package/src/types.d.ts +3 -1
- package/src/types.d.ts.map +1 -1
- package/src/types.js +1 -0
- package/src/types.js.map +1 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Generic OpenAPI documentation controller.
|
|
3
|
+
* Serves the OpenAPI specification built from registered controllers.
|
|
4
|
+
* Supports JSON and YAML formats, tag filtering, and external documentation.
|
|
5
|
+
* @module openapi/controller
|
|
6
|
+
*/
|
|
7
|
+
import { PlatformID } from '@digitaldefiance/node-ecies-lib';
|
|
8
|
+
import { Router } from 'express';
|
|
9
|
+
import { IApplication } from '../interfaces/application';
|
|
10
|
+
import { OpenAPIBuilder, OpenAPIBuilderConfig, OpenAPISpec } from './builder';
|
|
11
|
+
/**
|
|
12
|
+
* Response type for the OpenAPI endpoint.
|
|
13
|
+
*/
|
|
14
|
+
export interface OpenAPIResponse {
|
|
15
|
+
message: string;
|
|
16
|
+
openapi: string;
|
|
17
|
+
info: OpenAPISpec['info'];
|
|
18
|
+
servers: OpenAPISpec['servers'];
|
|
19
|
+
paths: OpenAPISpec['paths'];
|
|
20
|
+
components: OpenAPISpec['components'];
|
|
21
|
+
externalDocs?: OpenAPISpec['externalDocs'];
|
|
22
|
+
tags?: OpenAPISpec['tags'];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for configuring the OpenAPI controller.
|
|
26
|
+
*/
|
|
27
|
+
export interface OpenAPIControllerOptions {
|
|
28
|
+
/** Whether to cache the spec (default: true in production) */
|
|
29
|
+
cacheSpec?: boolean;
|
|
30
|
+
/** Enable YAML format endpoint at /yaml (default: false) */
|
|
31
|
+
enableYaml?: boolean;
|
|
32
|
+
/** Enable tag filtering via ?tags query parameter (default: true) */
|
|
33
|
+
enableTagFiltering?: boolean;
|
|
34
|
+
/** Custom base path for the spec endpoints (default: '') */
|
|
35
|
+
basePath?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generic OpenAPI documentation controller.
|
|
39
|
+
* Serves the OpenAPI specification at the configured endpoint.
|
|
40
|
+
*
|
|
41
|
+
* Unlike other controllers, this one doesn't extend BaseController to avoid
|
|
42
|
+
* circular dependencies and keep it lightweight. It's designed to be mounted
|
|
43
|
+
* directly on a router.
|
|
44
|
+
*
|
|
45
|
+
* Features:
|
|
46
|
+
* - JSON format at / and /json
|
|
47
|
+
* - Optional YAML format at /yaml
|
|
48
|
+
* - Tag filtering via ?tags=tag1,tag2 query parameter
|
|
49
|
+
* - Caching support for production environments
|
|
50
|
+
* - External documentation support
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // In your API router setup:
|
|
55
|
+
* const openApiController = new OpenAPIController(application, {
|
|
56
|
+
* title: 'My API',
|
|
57
|
+
* version: '1.0.0',
|
|
58
|
+
* description: 'My awesome API',
|
|
59
|
+
* externalDocs: {
|
|
60
|
+
* description: 'Full documentation',
|
|
61
|
+
* url: 'https://docs.example.com'
|
|
62
|
+
* }
|
|
63
|
+
* }, {
|
|
64
|
+
* enableYaml: true,
|
|
65
|
+
* enableTagFiltering: true
|
|
66
|
+
* });
|
|
67
|
+
* router.use('/openapi', openApiController.router);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare class OpenAPIController<TID extends PlatformID = Buffer> {
|
|
71
|
+
readonly router: Router;
|
|
72
|
+
private readonly builder;
|
|
73
|
+
private readonly applicationRef;
|
|
74
|
+
private cachedSpec;
|
|
75
|
+
private readonly cacheEnabled;
|
|
76
|
+
private readonly enableYaml;
|
|
77
|
+
private readonly enableTagFiltering;
|
|
78
|
+
/**
|
|
79
|
+
* Create a new OpenAPI controller.
|
|
80
|
+
* @param application - The application instance
|
|
81
|
+
* @param config - OpenAPI builder configuration
|
|
82
|
+
* @param options - Controller options
|
|
83
|
+
*/
|
|
84
|
+
constructor(application: IApplication<TID>, config: OpenAPIBuilderConfig, options?: OpenAPIControllerOptions);
|
|
85
|
+
/**
|
|
86
|
+
* Get the application instance.
|
|
87
|
+
* Useful for accessing application configuration or services.
|
|
88
|
+
*/
|
|
89
|
+
get application(): IApplication<TID>;
|
|
90
|
+
/**
|
|
91
|
+
* Initialize the routes.
|
|
92
|
+
*/
|
|
93
|
+
private initializeRoutes;
|
|
94
|
+
/**
|
|
95
|
+
* Handle GET request for the OpenAPI specification in JSON format.
|
|
96
|
+
*/
|
|
97
|
+
private handleGetSpec;
|
|
98
|
+
/**
|
|
99
|
+
* Handle GET request for the raw OpenAPI specification without wrapper.
|
|
100
|
+
*/
|
|
101
|
+
private handleGetRawSpec;
|
|
102
|
+
/**
|
|
103
|
+
* Handle GET request for the OpenAPI specification in YAML format.
|
|
104
|
+
*/
|
|
105
|
+
private handleGetSpecYaml;
|
|
106
|
+
/**
|
|
107
|
+
* Filter the OpenAPI spec to only include paths with specified tags.
|
|
108
|
+
* @param spec - The full OpenAPI spec
|
|
109
|
+
* @param tags - Tags to filter by
|
|
110
|
+
* @returns Filtered spec
|
|
111
|
+
*/
|
|
112
|
+
private filterSpecByTags;
|
|
113
|
+
/**
|
|
114
|
+
* Convert the OpenAPI spec to YAML format.
|
|
115
|
+
* Uses a simple JSON-to-YAML conversion without external dependencies.
|
|
116
|
+
* @param spec - The OpenAPI spec object
|
|
117
|
+
* @returns YAML string representation
|
|
118
|
+
*/
|
|
119
|
+
private convertToYaml;
|
|
120
|
+
/**
|
|
121
|
+
* Simple JSON to YAML converter.
|
|
122
|
+
* @param obj - Object to convert
|
|
123
|
+
* @param indent - Current indentation level
|
|
124
|
+
* @returns YAML string
|
|
125
|
+
*/
|
|
126
|
+
private jsonToYaml;
|
|
127
|
+
/**
|
|
128
|
+
* Get the OpenAPI specification, using cache if enabled.
|
|
129
|
+
*/
|
|
130
|
+
private getSpec;
|
|
131
|
+
/**
|
|
132
|
+
* Clear the cached specification.
|
|
133
|
+
* Useful when routes are dynamically added.
|
|
134
|
+
*/
|
|
135
|
+
clearCache(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Get the raw OpenAPI specification object.
|
|
138
|
+
* Useful for programmatic access or testing.
|
|
139
|
+
*/
|
|
140
|
+
getSpecification(): OpenAPISpec;
|
|
141
|
+
/**
|
|
142
|
+
* Get the OpenAPI specification filtered by tags.
|
|
143
|
+
* @param tags - Tags to filter by
|
|
144
|
+
* @returns Filtered OpenAPI spec
|
|
145
|
+
*/
|
|
146
|
+
getSpecificationByTags(tags: string[]): OpenAPISpec;
|
|
147
|
+
/**
|
|
148
|
+
* Get the OpenAPI builder instance.
|
|
149
|
+
* Useful for advanced customization.
|
|
150
|
+
*/
|
|
151
|
+
getBuilder(): OpenAPIBuilder;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/openapi/controller.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1B,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,UAAU,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACtC,YAAY,CAAC,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,8DAA8D;IAC9D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qEAAqE;IACrE,kBAAkB,CAAC,E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
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Generic OpenAPI documentation controller.
|
|
4
|
+
* Serves the OpenAPI specification built from registered controllers.
|
|
5
|
+
* Supports JSON and YAML formats, tag filtering, and external documentation.
|
|
6
|
+
* @module openapi/controller
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.OpenAPIController = void 0;
|
|
10
|
+
const express_1 = require("express");
|
|
11
|
+
const builder_1 = require("./builder");
|
|
12
|
+
/**
|
|
13
|
+
* Generic OpenAPI documentation controller.
|
|
14
|
+
* Serves the OpenAPI specification at the configured endpoint.
|
|
15
|
+
*
|
|
16
|
+
* Unlike other controllers, this one doesn't extend BaseController to avoid
|
|
17
|
+
* circular dependencies and keep it lightweight. It's designed to be mounted
|
|
18
|
+
* directly on a router.
|
|
19
|
+
*
|
|
20
|
+
* Features:
|
|
21
|
+
* - JSON format at / and /json
|
|
22
|
+
* - Optional YAML format at /yaml
|
|
23
|
+
* - Tag filtering via ?tags=tag1,tag2 query parameter
|
|
24
|
+
* - Caching support for production environments
|
|
25
|
+
* - External documentation support
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // In your API router setup:
|
|
30
|
+
* const openApiController = new OpenAPIController(application, {
|
|
31
|
+
* title: 'My API',
|
|
32
|
+
* version: '1.0.0',
|
|
33
|
+
* description: 'My awesome API',
|
|
34
|
+
* externalDocs: {
|
|
35
|
+
* description: 'Full documentation',
|
|
36
|
+
* url: 'https://docs.example.com'
|
|
37
|
+
* }
|
|
38
|
+
* }, {
|
|
39
|
+
* enableYaml: true,
|
|
40
|
+
* enableTagFiltering: true
|
|
41
|
+
* });
|
|
42
|
+
* router.use('/openapi', openApiController.router);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
class OpenAPIController {
|
|
46
|
+
router;
|
|
47
|
+
builder;
|
|
48
|
+
applicationRef;
|
|
49
|
+
cachedSpec = null;
|
|
50
|
+
cacheEnabled;
|
|
51
|
+
enableYaml;
|
|
52
|
+
enableTagFiltering;
|
|
53
|
+
/**
|
|
54
|
+
* Create a new OpenAPI controller.
|
|
55
|
+
* @param application - The application instance
|
|
56
|
+
* @param config - OpenAPI builder configuration
|
|
57
|
+
* @param options - Controller options
|
|
58
|
+
*/
|
|
59
|
+
constructor(application, config, options) {
|
|
60
|
+
this.applicationRef = application;
|
|
61
|
+
this.builder = new builder_1.OpenAPIBuilder(config);
|
|
62
|
+
this.router = (0, express_1.Router)();
|
|
63
|
+
this.cacheEnabled =
|
|
64
|
+
options?.cacheSpec ?? process.env.NODE_ENV === 'production';
|
|
65
|
+
this.enableYaml = options?.enableYaml ?? false;
|
|
66
|
+
this.enableTagFiltering = options?.enableTagFiltering ?? true;
|
|
67
|
+
this.initializeRoutes();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the application instance.
|
|
71
|
+
* Useful for accessing application configuration or services.
|
|
72
|
+
*/
|
|
73
|
+
get application() {
|
|
74
|
+
return this.applicationRef;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Initialize the routes.
|
|
78
|
+
*/
|
|
79
|
+
initializeRoutes() {
|
|
80
|
+
// GET / - Returns the OpenAPI specification in JSON
|
|
81
|
+
this.router.get('/', this.handleGetSpec.bind(this));
|
|
82
|
+
// GET /json - Alias for the spec in JSON
|
|
83
|
+
this.router.get('/json', this.handleGetSpec.bind(this));
|
|
84
|
+
// GET /yaml - Returns the OpenAPI specification in YAML (if enabled)
|
|
85
|
+
if (this.enableYaml) {
|
|
86
|
+
this.router.get('/yaml', this.handleGetSpecYaml.bind(this));
|
|
87
|
+
}
|
|
88
|
+
// GET /raw - Returns the raw spec without wrapper
|
|
89
|
+
this.router.get('/raw', this.handleGetRawSpec.bind(this));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Handle GET request for the OpenAPI specification in JSON format.
|
|
93
|
+
*/
|
|
94
|
+
handleGetSpec(req, res) {
|
|
95
|
+
try {
|
|
96
|
+
let spec = this.getSpec();
|
|
97
|
+
// Apply tag filtering if enabled and tags query param is present
|
|
98
|
+
if (this.enableTagFiltering && req.query.tags) {
|
|
99
|
+
const tags = String(req.query.tags)
|
|
100
|
+
.split(',')
|
|
101
|
+
.map((t) => t.trim());
|
|
102
|
+
spec = this.filterSpecByTags(spec, tags);
|
|
103
|
+
}
|
|
104
|
+
const response = {
|
|
105
|
+
message: 'OpenAPI specification',
|
|
106
|
+
openapi: spec.openapi,
|
|
107
|
+
info: spec.info,
|
|
108
|
+
servers: spec.servers,
|
|
109
|
+
paths: spec.paths,
|
|
110
|
+
components: spec.components,
|
|
111
|
+
};
|
|
112
|
+
// Include optional fields if present
|
|
113
|
+
if (spec.externalDocs) {
|
|
114
|
+
response.externalDocs = spec.externalDocs;
|
|
115
|
+
}
|
|
116
|
+
if (spec.tags && spec.tags.length > 0) {
|
|
117
|
+
response.tags = spec.tags;
|
|
118
|
+
}
|
|
119
|
+
res.status(200).json(response);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
res.status(500).json({
|
|
123
|
+
error: {
|
|
124
|
+
code: 'OPENAPI_BUILD_ERROR',
|
|
125
|
+
message: error instanceof Error
|
|
126
|
+
? error.message
|
|
127
|
+
: 'Failed to build OpenAPI spec',
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Handle GET request for the raw OpenAPI specification without wrapper.
|
|
134
|
+
*/
|
|
135
|
+
handleGetRawSpec(req, res) {
|
|
136
|
+
try {
|
|
137
|
+
let spec = this.getSpec();
|
|
138
|
+
// Apply tag filtering if enabled and tags query param is present
|
|
139
|
+
if (this.enableTagFiltering && req.query.tags) {
|
|
140
|
+
const tags = String(req.query.tags)
|
|
141
|
+
.split(',')
|
|
142
|
+
.map((t) => t.trim());
|
|
143
|
+
spec = this.filterSpecByTags(spec, tags);
|
|
144
|
+
}
|
|
145
|
+
res.status(200).json(spec);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
res.status(500).json({
|
|
149
|
+
error: {
|
|
150
|
+
code: 'OPENAPI_BUILD_ERROR',
|
|
151
|
+
message: error instanceof Error
|
|
152
|
+
? error.message
|
|
153
|
+
: 'Failed to build OpenAPI spec',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Handle GET request for the OpenAPI specification in YAML format.
|
|
160
|
+
*/
|
|
161
|
+
handleGetSpecYaml(req, res) {
|
|
162
|
+
try {
|
|
163
|
+
let spec = this.getSpec();
|
|
164
|
+
// Apply tag filtering if enabled and tags query param is present
|
|
165
|
+
if (this.enableTagFiltering && req.query.tags) {
|
|
166
|
+
const tags = String(req.query.tags)
|
|
167
|
+
.split(',')
|
|
168
|
+
.map((t) => t.trim());
|
|
169
|
+
spec = this.filterSpecByTags(spec, tags);
|
|
170
|
+
}
|
|
171
|
+
const yaml = this.convertToYaml(spec);
|
|
172
|
+
res.status(200).type('text/yaml').send(yaml);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
res.status(500).json({
|
|
176
|
+
error: {
|
|
177
|
+
code: 'OPENAPI_BUILD_ERROR',
|
|
178
|
+
message: error instanceof Error
|
|
179
|
+
? error.message
|
|
180
|
+
: 'Failed to build OpenAPI spec',
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Filter the OpenAPI spec to only include paths with specified tags.
|
|
187
|
+
* @param spec - The full OpenAPI spec
|
|
188
|
+
* @param tags - Tags to filter by
|
|
189
|
+
* @returns Filtered spec
|
|
190
|
+
*/
|
|
191
|
+
filterSpecByTags(spec, tags) {
|
|
192
|
+
const tagSet = new Set(tags.map((t) => t.toLowerCase()));
|
|
193
|
+
const filteredPaths = {};
|
|
194
|
+
for (const [path, methods] of Object.entries(spec.paths)) {
|
|
195
|
+
const filteredMethods = {};
|
|
196
|
+
for (const [method, operation] of Object.entries(methods)) {
|
|
197
|
+
const op = operation;
|
|
198
|
+
if (op.tags && op.tags.some((t) => tagSet.has(t.toLowerCase()))) {
|
|
199
|
+
filteredMethods[method] = operation;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (Object.keys(filteredMethods).length > 0) {
|
|
203
|
+
filteredPaths[path] = filteredMethods;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
...spec,
|
|
208
|
+
paths: filteredPaths,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Convert the OpenAPI spec to YAML format.
|
|
213
|
+
* Uses a simple JSON-to-YAML conversion without external dependencies.
|
|
214
|
+
* @param spec - The OpenAPI spec object
|
|
215
|
+
* @returns YAML string representation
|
|
216
|
+
*/
|
|
217
|
+
convertToYaml(spec) {
|
|
218
|
+
return this.jsonToYaml(spec, 0);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Simple JSON to YAML converter.
|
|
222
|
+
* @param obj - Object to convert
|
|
223
|
+
* @param indent - Current indentation level
|
|
224
|
+
* @returns YAML string
|
|
225
|
+
*/
|
|
226
|
+
jsonToYaml(obj, indent) {
|
|
227
|
+
const spaces = ' '.repeat(indent);
|
|
228
|
+
if (obj === null || obj === undefined) {
|
|
229
|
+
return 'null';
|
|
230
|
+
}
|
|
231
|
+
if (typeof obj === 'string') {
|
|
232
|
+
// Check if string needs quoting
|
|
233
|
+
if (obj.includes('\n') ||
|
|
234
|
+
obj.includes(':') ||
|
|
235
|
+
obj.includes('#') ||
|
|
236
|
+
obj.startsWith(' ') ||
|
|
237
|
+
obj.endsWith(' ') ||
|
|
238
|
+
/^[0-9]/.test(obj) ||
|
|
239
|
+
obj === '' ||
|
|
240
|
+
['true', 'false', 'null', 'yes', 'no'].includes(obj.toLowerCase())) {
|
|
241
|
+
return JSON.stringify(obj);
|
|
242
|
+
}
|
|
243
|
+
return obj;
|
|
244
|
+
}
|
|
245
|
+
if (typeof obj === 'number' || typeof obj === 'boolean') {
|
|
246
|
+
return String(obj);
|
|
247
|
+
}
|
|
248
|
+
if (Array.isArray(obj)) {
|
|
249
|
+
if (obj.length === 0) {
|
|
250
|
+
return '[]';
|
|
251
|
+
}
|
|
252
|
+
return obj
|
|
253
|
+
.map((item) => {
|
|
254
|
+
const itemYaml = this.jsonToYaml(item, indent + 1);
|
|
255
|
+
if (typeof item === 'object' &&
|
|
256
|
+
item !== null &&
|
|
257
|
+
!Array.isArray(item)) {
|
|
258
|
+
return `${spaces}- ${itemYaml.trimStart()}`;
|
|
259
|
+
}
|
|
260
|
+
return `${spaces}- ${itemYaml}`;
|
|
261
|
+
})
|
|
262
|
+
.join('\n');
|
|
263
|
+
}
|
|
264
|
+
if (typeof obj === 'object') {
|
|
265
|
+
const entries = Object.entries(obj);
|
|
266
|
+
if (entries.length === 0) {
|
|
267
|
+
return '{}';
|
|
268
|
+
}
|
|
269
|
+
return entries
|
|
270
|
+
.map(([key, value]) => {
|
|
271
|
+
const valueYaml = this.jsonToYaml(value, indent + 1);
|
|
272
|
+
if (typeof value === 'object' &&
|
|
273
|
+
value !== null &&
|
|
274
|
+
!Array.isArray(value) &&
|
|
275
|
+
Object.keys(value).length > 0) {
|
|
276
|
+
return `${spaces}${key}:\n${valueYaml}`;
|
|
277
|
+
}
|
|
278
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
279
|
+
return `${spaces}${key}:\n${valueYaml}`;
|
|
280
|
+
}
|
|
281
|
+
return `${spaces}${key}: ${valueYaml}`;
|
|
282
|
+
})
|
|
283
|
+
.join('\n');
|
|
284
|
+
}
|
|
285
|
+
return String(obj);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get the OpenAPI specification, using cache if enabled.
|
|
289
|
+
*/
|
|
290
|
+
getSpec() {
|
|
291
|
+
if (this.cacheEnabled && this.cachedSpec) {
|
|
292
|
+
return this.cachedSpec;
|
|
293
|
+
}
|
|
294
|
+
const spec = this.builder.build();
|
|
295
|
+
if (this.cacheEnabled) {
|
|
296
|
+
this.cachedSpec = spec;
|
|
297
|
+
}
|
|
298
|
+
return spec;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Clear the cached specification.
|
|
302
|
+
* Useful when routes are dynamically added.
|
|
303
|
+
*/
|
|
304
|
+
clearCache() {
|
|
305
|
+
this.cachedSpec = null;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get the raw OpenAPI specification object.
|
|
309
|
+
* Useful for programmatic access or testing.
|
|
310
|
+
*/
|
|
311
|
+
getSpecification() {
|
|
312
|
+
return this.getSpec();
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get the OpenAPI specification filtered by tags.
|
|
316
|
+
* @param tags - Tags to filter by
|
|
317
|
+
* @returns Filtered OpenAPI spec
|
|
318
|
+
*/
|
|
319
|
+
getSpecificationByTags(tags) {
|
|
320
|
+
return this.filterSpecByTags(this.getSpec(), tags);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Get the OpenAPI builder instance.
|
|
324
|
+
* Useful for advanced customization.
|
|
325
|
+
*/
|
|
326
|
+
getBuilder() {
|
|
327
|
+
return this.builder;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
exports.OpenAPIController = OpenAPIController;
|
|
331
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/openapi/controller.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,qCAAoD;AAEpD,uCAA8E;AA8B9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAa,iBAAiB;IACZ,MAAM,CAAS;IACd,OAAO,CAAiB;IACxB,cAAc,CAAoB;IAC3C,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,CAAC;IAED;;;OAGG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,sBAAsB,CAAC,IAAc;QAC1C,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA7UD,8CA6UC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OpenAPI module exports.
|
|
3
|
+
* Provides OpenAPI builder, controller, schemas, middleware, and documentation generators.
|
|
4
|
+
* @module openapi
|
|
5
|
+
*/
|
|
6
|
+
export { OpenAPIBuilder } from './builder';
|
|
7
|
+
export type { OpenAPIBuilderConfig, OpenAPISpec, OpenAPIExternalDocs, OpenAPITagDefinition, OpenAPIOperationMetadata, OpenAPIParameter as BuilderOpenAPIParameter, OpenAPIParameterSchema as BuilderOpenAPIParameterSchema, OpenAPIRequestBody as BuilderOpenAPIRequestBody, OpenAPIResponse as BuilderOpenAPIResponse, } from './builder';
|
|
8
|
+
export { OpenAPIController } from './controller';
|
|
9
|
+
export type { OpenAPIControllerOptions, OpenAPIResponse as ControllerOpenAPIResponse, } from './controller';
|
|
10
|
+
export * from './schemas';
|
|
11
|
+
export * from './middleware';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/openapi/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,YAAY,EACV,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EAExB,gBAAgB,IAAI,uBAAuB,EAC3C,sBAAsB,IAAI,6BAA6B,EACvD,kBAAkB,IAAI,yBAAyB,EAC/C,eAAe,IAAI,sBAAsB,GAC1C,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,YAAY,EACV,wBAAwB,EACxB,eAAe,IAAI,yBAAyB,GAC7C,MAAM,cAAc,CAAC;AAGtB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview OpenAPI module exports.
|
|
4
|
+
* Provides OpenAPI builder, controller, schemas, middleware, and documentation generators.
|
|
5
|
+
* @module openapi
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.OpenAPIController = exports.OpenAPIBuilder = void 0;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
// Re-export builder class
|
|
11
|
+
var builder_1 = require("./builder");
|
|
12
|
+
Object.defineProperty(exports, "OpenAPIBuilder", { enumerable: true, get: function () { return builder_1.OpenAPIBuilder; } });
|
|
13
|
+
// Re-export controller class
|
|
14
|
+
var controller_1 = require("./controller");
|
|
15
|
+
Object.defineProperty(exports, "OpenAPIController", { enumerable: true, get: function () { return controller_1.OpenAPIController; } });
|
|
16
|
+
// Schema registry
|
|
17
|
+
tslib_1.__exportStar(require("./schemas"), exports);
|
|
18
|
+
// Middleware (Swagger UI, ReDoc) and documentation generators
|
|
19
|
+
tslib_1.__exportStar(require("./middleware"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/openapi/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;AAEH,0BAA0B;AAC1B,qCAA2C;AAAlC,yGAAA,cAAc,OAAA;AAgBvB,6BAA6B;AAC7B,2CAAiD;AAAxC,+GAAA,iBAAiB,OAAA;AAQ1B,kBAAkB;AAClB,oDAA0B;AAE1B,8DAA8D;AAC9D,uDAA6B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Markdown documentation generator from OpenAPI specification.
|
|
3
|
+
* Generates comprehensive markdown documentation including table of contents,
|
|
4
|
+
* endpoints grouped by tag, parameters, and responses.
|
|
5
|
+
* @module openapi/markdown-generator
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAPISpec } from './builder';
|
|
8
|
+
/**
|
|
9
|
+
* Options for markdown documentation generation.
|
|
10
|
+
*/
|
|
11
|
+
export interface MarkdownGeneratorOptions {
|
|
12
|
+
/** Include table of contents (default: true) */
|
|
13
|
+
includeToc?: boolean;
|
|
14
|
+
/** Include API info section (default: true) */
|
|
15
|
+
includeInfo?: boolean;
|
|
16
|
+
/** Include server information (default: true) */
|
|
17
|
+
includeServers?: boolean;
|
|
18
|
+
/** Include authentication section (default: true) */
|
|
19
|
+
includeAuthentication?: boolean;
|
|
20
|
+
/** Include schema definitions (default: true) */
|
|
21
|
+
includeSchemas?: boolean;
|
|
22
|
+
/** Custom title override (uses spec title if not provided) */
|
|
23
|
+
title?: string;
|
|
24
|
+
/** Add anchor links to headings (default: true) */
|
|
25
|
+
anchorLinks?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generate markdown documentation from an OpenAPI specification.
|
|
29
|
+
*
|
|
30
|
+
* @param spec - The OpenAPI specification object
|
|
31
|
+
* @param options - Generation options
|
|
32
|
+
* @returns Generated markdown string
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const spec = builder.build();
|
|
37
|
+
* const markdown = generateMarkdownDocs(spec);
|
|
38
|
+
* fs.writeFileSync('API.md', markdown);
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // With custom options
|
|
44
|
+
* const markdown = generateMarkdownDocs(spec, {
|
|
45
|
+
* title: 'My Custom API Documentation',
|
|
46
|
+
* includeToc: true,
|
|
47
|
+
* includeSchemas: false,
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function generateMarkdownDocs(spec: OpenAPISpec, options?: MarkdownGeneratorOptions): string;
|
|
52
|
+
//# sourceMappingURL=markdown-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-generator.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/openapi/markdown-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAA0C,MAAM,WAAW,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,gDAAgD;IAChD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iDAAiD;IACjD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qDAAqD;IACrD,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iDAAiD;IACjD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AA0DD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,wBAA6B,GACrC,MAAM,CAqCR"}
|