@digitaldefiance/node-express-suite 3.11.32 → 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 +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/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 +1 -0
- package/src/interfaces/openApi/index.d.ts.map +1 -1
- package/src/interfaces/openApi/index.js +23 -0
- package/src/interfaces/openApi/index.js.map +1 -1
- package/src/interfaces/openApi/parameter.d.ts +2 -0
- package/src/interfaces/openApi/parameter.d.ts.map +1 -1
- package/src/interfaces/openApi/parameter.js +3 -1
- package/src/interfaces/openApi/parameter.js.map +1 -1
- package/src/interfaces/openApi/parameterSchema.d.ts +2 -0
- package/src/interfaces/openApi/parameterSchema.d.ts.map +1 -1
- package/src/interfaces/openApi/parameterSchema.js +3 -0
- package/src/interfaces/openApi/parameterSchema.js.map +1 -1
- 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/types.d.ts +1 -0
- package/src/types.d.ts.map +1 -1
- package/src/types.js +1 -0
- package/src/types.js.map +1 -1
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Swagger UI middleware for serving interactive API documentation.
|
|
4
|
+
* Provides a configurable middleware that serves Swagger UI with the OpenAPI spec.
|
|
5
|
+
* @module openapi/middleware/swagger-ui
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.generateSwaggerUIHtml = generateSwaggerUIHtml;
|
|
9
|
+
exports.SwaggerUIMiddleware = SwaggerUIMiddleware;
|
|
10
|
+
exports.createSwaggerUIHandler = createSwaggerUIHandler;
|
|
11
|
+
const express_1 = require("express");
|
|
12
|
+
/**
|
|
13
|
+
* Default Swagger UI CDN URLs.
|
|
14
|
+
*/
|
|
15
|
+
const SWAGGER_UI_CDN = {
|
|
16
|
+
css: 'https://unpkg.com/swagger-ui-dist@5/swagger-ui.css',
|
|
17
|
+
bundle: 'https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js',
|
|
18
|
+
standalonePreset: 'https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js',
|
|
19
|
+
favicon: 'https://unpkg.com/swagger-ui-dist@5/favicon-32x32.png',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Generates the HTML page for Swagger UI.
|
|
23
|
+
* @param spec - The OpenAPI specification object
|
|
24
|
+
* @param options - Swagger UI customization options
|
|
25
|
+
* @returns HTML string for the Swagger UI page
|
|
26
|
+
*/
|
|
27
|
+
function generateSwaggerUIHtml(spec, options = {}) {
|
|
28
|
+
const title = options.siteTitle ?? options.title ?? spec.info.title;
|
|
29
|
+
const favicon = options.favicon ?? SWAGGER_UI_CDN.favicon;
|
|
30
|
+
const showTopBar = options.showTopBar !== false;
|
|
31
|
+
// Build Swagger UI config
|
|
32
|
+
const swaggerConfig = {
|
|
33
|
+
spec,
|
|
34
|
+
dom_id: '#swagger-ui',
|
|
35
|
+
presets: ['SwaggerUIBundle.presets.apis', 'SwaggerUIStandalonePreset'],
|
|
36
|
+
plugins: ['SwaggerUIBundle.plugins.DownloadUrl'],
|
|
37
|
+
layout: 'StandaloneLayout',
|
|
38
|
+
...options.swaggerOptions,
|
|
39
|
+
};
|
|
40
|
+
// Convert config to JavaScript object literal (not JSON)
|
|
41
|
+
const configString = objectToJsLiteral(swaggerConfig);
|
|
42
|
+
// Build custom CSS
|
|
43
|
+
let customStyles = '';
|
|
44
|
+
if (!showTopBar) {
|
|
45
|
+
customStyles += '.topbar { display: none; }';
|
|
46
|
+
}
|
|
47
|
+
if (options.customCss) {
|
|
48
|
+
customStyles += options.customCss;
|
|
49
|
+
}
|
|
50
|
+
return `<!DOCTYPE html>
|
|
51
|
+
<html lang="en">
|
|
52
|
+
<head>
|
|
53
|
+
<meta charset="UTF-8">
|
|
54
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
55
|
+
<title>${escapeHtml(title)}</title>
|
|
56
|
+
<link rel="icon" type="image/png" href="${escapeHtml(favicon)}">
|
|
57
|
+
<link rel="stylesheet" href="${SWAGGER_UI_CDN.css}">
|
|
58
|
+
${options.customCssUrl ? `<link rel="stylesheet" href="${escapeHtml(options.customCssUrl)}">` : ''}
|
|
59
|
+
${customStyles ? `<style>${customStyles}</style>` : ''}
|
|
60
|
+
</head>
|
|
61
|
+
<body>
|
|
62
|
+
<div id="swagger-ui"></div>
|
|
63
|
+
<script src="${SWAGGER_UI_CDN.bundle}"></script>
|
|
64
|
+
<script src="${SWAGGER_UI_CDN.standalonePreset}"></script>
|
|
65
|
+
${options.customJsUrl ? `<script src="${escapeHtml(options.customJsUrl)}"></script>` : ''}
|
|
66
|
+
<script>
|
|
67
|
+
window.onload = function() {
|
|
68
|
+
window.ui = SwaggerUIBundle(${configString});
|
|
69
|
+
};
|
|
70
|
+
</script>
|
|
71
|
+
${options.customJs ? `<script>${options.customJs}</script>` : ''}
|
|
72
|
+
</body>
|
|
73
|
+
</html>`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Converts a JavaScript object to a JS object literal string.
|
|
77
|
+
* Handles special cases like function references (presets, plugins).
|
|
78
|
+
* @param obj - Object to convert
|
|
79
|
+
* @returns JavaScript object literal string
|
|
80
|
+
*/
|
|
81
|
+
function objectToJsLiteral(obj) {
|
|
82
|
+
const entries = Object.entries(obj).map(([key, value]) => {
|
|
83
|
+
const formattedValue = formatValue(value);
|
|
84
|
+
return `${key}: ${formattedValue}`;
|
|
85
|
+
});
|
|
86
|
+
return `{\n ${entries.join(',\n ')}\n }`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Formats a value for JavaScript object literal.
|
|
90
|
+
* @param value - Value to format
|
|
91
|
+
* @returns Formatted string representation
|
|
92
|
+
*/
|
|
93
|
+
function formatValue(value) {
|
|
94
|
+
if (value === null || value === undefined) {
|
|
95
|
+
return 'null';
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === 'string') {
|
|
98
|
+
// Check if it's a reference to a global (like SwaggerUIBundle.presets.apis)
|
|
99
|
+
if (value.startsWith('SwaggerUIBundle.') ||
|
|
100
|
+
value.startsWith('SwaggerUIStandalonePreset')) {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
return JSON.stringify(value);
|
|
104
|
+
}
|
|
105
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
106
|
+
return String(value);
|
|
107
|
+
}
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
const items = value.map((item) => formatValue(item));
|
|
110
|
+
return `[${items.join(', ')}]`;
|
|
111
|
+
}
|
|
112
|
+
if (typeof value === 'object') {
|
|
113
|
+
// For nested objects (like spec), use JSON.stringify
|
|
114
|
+
return JSON.stringify(value);
|
|
115
|
+
}
|
|
116
|
+
return String(value);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Escapes HTML special characters to prevent XSS.
|
|
120
|
+
* @param str - String to escape
|
|
121
|
+
* @returns Escaped string
|
|
122
|
+
*/
|
|
123
|
+
function escapeHtml(str) {
|
|
124
|
+
const htmlEscapes = {
|
|
125
|
+
'&': '&',
|
|
126
|
+
'<': '<',
|
|
127
|
+
'>': '>',
|
|
128
|
+
'"': '"',
|
|
129
|
+
"'": ''',
|
|
130
|
+
};
|
|
131
|
+
return str.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Creates Express middleware that serves Swagger UI.
|
|
135
|
+
*
|
|
136
|
+
* @param specOrProvider - OpenAPI spec object or a function that returns the spec
|
|
137
|
+
* @param options - Swagger UI customization options
|
|
138
|
+
* @returns Express Router configured to serve Swagger UI
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // With static spec
|
|
143
|
+
* const spec = openApiBuilder.build();
|
|
144
|
+
* app.use('/docs', SwaggerUIMiddleware(spec));
|
|
145
|
+
*
|
|
146
|
+
* // With dynamic spec provider
|
|
147
|
+
* app.use('/docs', SwaggerUIMiddleware(() => openApiBuilder.build()));
|
|
148
|
+
*
|
|
149
|
+
* // With customization
|
|
150
|
+
* app.use('/docs', SwaggerUIMiddleware(spec, {
|
|
151
|
+
* title: 'My API Documentation',
|
|
152
|
+
* customCss: '.topbar { background-color: #333; }',
|
|
153
|
+
* swaggerOptions: {
|
|
154
|
+
* docExpansion: 'list',
|
|
155
|
+
* filter: true,
|
|
156
|
+
* persistAuthorization: true
|
|
157
|
+
* }
|
|
158
|
+
* }));
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
function SwaggerUIMiddleware(specOrProvider, options = {}) {
|
|
162
|
+
const router = (0, express_1.Router)();
|
|
163
|
+
// Determine if we have a static spec or a provider function
|
|
164
|
+
const isProvider = typeof specOrProvider === 'function';
|
|
165
|
+
/**
|
|
166
|
+
* Handler for serving the Swagger UI HTML page.
|
|
167
|
+
*/
|
|
168
|
+
const serveSwaggerUI = async (_req, res) => {
|
|
169
|
+
try {
|
|
170
|
+
const spec = isProvider
|
|
171
|
+
? await specOrProvider()
|
|
172
|
+
: specOrProvider;
|
|
173
|
+
const html = generateSwaggerUIHtml(spec, options);
|
|
174
|
+
res.type('html').send(html);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
res.status(500).json({
|
|
178
|
+
error: {
|
|
179
|
+
code: 'SWAGGER_UI_ERROR',
|
|
180
|
+
message: error instanceof Error
|
|
181
|
+
? error.message
|
|
182
|
+
: 'Failed to generate Swagger UI',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
// Serve Swagger UI at root and /index.html
|
|
188
|
+
router.get('/', serveSwaggerUI);
|
|
189
|
+
router.get('/index.html', serveSwaggerUI);
|
|
190
|
+
return router;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Creates a simple middleware function (not a router) for serving Swagger UI.
|
|
194
|
+
* Useful when you need more control over routing.
|
|
195
|
+
*
|
|
196
|
+
* @param specOrProvider - OpenAPI spec object or a function that returns the spec
|
|
197
|
+
* @param options - Swagger UI customization options
|
|
198
|
+
* @returns Express RequestHandler
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* app.get('/docs', createSwaggerUIHandler(spec));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
function createSwaggerUIHandler(specOrProvider, options = {}) {
|
|
206
|
+
const isProvider = typeof specOrProvider === 'function';
|
|
207
|
+
return async (_req, res) => {
|
|
208
|
+
try {
|
|
209
|
+
const spec = isProvider
|
|
210
|
+
? await specOrProvider()
|
|
211
|
+
: specOrProvider;
|
|
212
|
+
const html = generateSwaggerUIHtml(spec, options);
|
|
213
|
+
res.type('html').send(html);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
res.status(500).json({
|
|
217
|
+
error: {
|
|
218
|
+
code: 'SWAGGER_UI_ERROR',
|
|
219
|
+
message: error instanceof Error
|
|
220
|
+
? error.message
|
|
221
|
+
: 'Failed to generate Swagger UI',
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=swagger-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-ui.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-express-suite/src/openapi/middleware/swagger-ui.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA4FH,sDAsDC;AAwGD,kDAyCC;AAeD,wDA0BC;AA1UD,qCAAoE;AAyEpE;;GAEG;AACH,MAAM,cAAc,GAAG;IACrB,GAAG,EAAE,oDAAoD;IACzD,MAAM,EAAE,0DAA0D;IAClE,gBAAgB,EACd,qEAAqE;IACvE,OAAO,EAAE,uDAAuD;CACjE,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,qBAAqB,CACnC,IAAiB,EACjB,UAA4B,EAAE;IAE9B,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACpE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,c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AC,KAAK,CAAC,OAAO;wBACf,CAAC,CAAC,+BAA+B;iBACtC;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;IAEF,2CAA2C;IAC3C,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAE1C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,sBAAsB,CACpC,cAA0C,EAC1C,UAA4B,EAAE;IAE9B,MAAM,UAAU,GAAG,OAAO,cAAc,KAAK,UAAU,CAAC;IAExD,OAAO,KAAK,EAAE,IAAa,EAAE,GAAa,EAAiB,EAAE;QAC3D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,UAAU;gBACrB,CAAC,CAAC,MAAO,cAA+B,EAAE;gBAC1C,CAAC,CAAE,cAA8B,CAAC;YAEpC,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAClD,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE;oBACL,IAAI,EAAE,kBAAkB;oBACxB,OAAO,EACL,KAAK,YAAY,KAAK;wBACpB,CAAC,CAAC,KAAK,CAAC,OAAO;wBACf,CAAC,CAAC,+BAA+B;iBACtC;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OpenAPI schema registry for component schemas.
|
|
3
|
+
* Provides a centralized place to register and retrieve OpenAPI schemas.
|
|
4
|
+
* Supports schema validation, removal, and inheritance tracking.
|
|
5
|
+
* @module openapi/schemas
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Schema definition with optional metadata.
|
|
9
|
+
*/
|
|
10
|
+
export interface SchemaDefinition {
|
|
11
|
+
/** The OpenAPI schema object */
|
|
12
|
+
schema: Record<string, unknown>;
|
|
13
|
+
/** Optional description of the schema */
|
|
14
|
+
description?: string;
|
|
15
|
+
/** Optional parent schema name for inheritance tracking */
|
|
16
|
+
parent?: string;
|
|
17
|
+
/** Whether this schema was auto-generated from decorators */
|
|
18
|
+
autoGenerated?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Registry for OpenAPI component schemas.
|
|
22
|
+
* Schemas are referenced by name in route metadata and resolved here.
|
|
23
|
+
*/
|
|
24
|
+
declare class OpenAPISchemaRegistryClass {
|
|
25
|
+
private schemas;
|
|
26
|
+
private securitySchemes;
|
|
27
|
+
/**
|
|
28
|
+
* Register a schema.
|
|
29
|
+
* @param name - Schema name (used in $ref)
|
|
30
|
+
* @param schema - OpenAPI schema object
|
|
31
|
+
* @param options - Optional metadata for the schema
|
|
32
|
+
*/
|
|
33
|
+
registerSchema(name: string, schema: Record<string, unknown>, options?: {
|
|
34
|
+
description?: string;
|
|
35
|
+
parent?: string;
|
|
36
|
+
autoGenerated?: boolean;
|
|
37
|
+
}): void;
|
|
38
|
+
/**
|
|
39
|
+
* Register multiple schemas at once.
|
|
40
|
+
* @param schemas - Object mapping schema names to schema definitions
|
|
41
|
+
*/
|
|
42
|
+
registerSchemas(schemas: Record<string, Record<string, unknown>>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Unregister a schema.
|
|
45
|
+
* @param name - Schema name to remove
|
|
46
|
+
* @returns True if the schema was removed, false if it didn't exist
|
|
47
|
+
*/
|
|
48
|
+
unregisterSchema(name: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Get a schema by name.
|
|
51
|
+
* @param name - Schema name
|
|
52
|
+
* @returns The schema or undefined
|
|
53
|
+
*/
|
|
54
|
+
getSchema(name: string): Record<string, unknown> | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Get a schema definition with metadata.
|
|
57
|
+
* @param name - Schema name
|
|
58
|
+
* @returns The schema definition or undefined
|
|
59
|
+
*/
|
|
60
|
+
getSchemaDefinition(name: string): SchemaDefinition | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Get all registered schemas.
|
|
63
|
+
* @returns Object mapping schema names to definitions
|
|
64
|
+
*/
|
|
65
|
+
getAllSchemas(): Record<string, Record<string, unknown>>;
|
|
66
|
+
/**
|
|
67
|
+
* Get all schema definitions with metadata.
|
|
68
|
+
* @returns Object mapping schema names to full definitions
|
|
69
|
+
*/
|
|
70
|
+
getAllSchemaDefinitions(): Record<string, SchemaDefinition>;
|
|
71
|
+
/**
|
|
72
|
+
* Get schemas that inherit from a parent schema.
|
|
73
|
+
* @param parentName - Parent schema name
|
|
74
|
+
* @returns Array of child schema names
|
|
75
|
+
*/
|
|
76
|
+
getChildSchemas(parentName: string): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Register a security scheme.
|
|
79
|
+
* @param name - Security scheme name
|
|
80
|
+
* @param scheme - OpenAPI security scheme object
|
|
81
|
+
*/
|
|
82
|
+
registerSecurityScheme(name: string, scheme: Record<string, unknown>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Register multiple security schemes at once.
|
|
85
|
+
* @param schemes - Object mapping scheme names to definitions
|
|
86
|
+
*/
|
|
87
|
+
registerSecuritySchemes(schemes: Record<string, Record<string, unknown>>): void;
|
|
88
|
+
/**
|
|
89
|
+
* Unregister a security scheme.
|
|
90
|
+
* @param name - Security scheme name to remove
|
|
91
|
+
* @returns True if the scheme was removed, false if it didn't exist
|
|
92
|
+
*/
|
|
93
|
+
unregisterSecurityScheme(name: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Get a security scheme by name.
|
|
96
|
+
* @param name - Security scheme name
|
|
97
|
+
* @returns The security scheme or undefined
|
|
98
|
+
*/
|
|
99
|
+
getSecurityScheme(name: string): Record<string, unknown> | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Get all registered security schemes.
|
|
102
|
+
* @returns Object mapping scheme names to definitions
|
|
103
|
+
*/
|
|
104
|
+
getAllSecuritySchemes(): Record<string, Record<string, unknown>>;
|
|
105
|
+
/**
|
|
106
|
+
* Clear all registrations (useful for testing).
|
|
107
|
+
*/
|
|
108
|
+
clear(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Clear only auto-generated schemas.
|
|
111
|
+
* Useful when re-scanning decorated classes.
|
|
112
|
+
*/
|
|
113
|
+
clearAutoGenerated(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Get count of registered schemas.
|
|
116
|
+
*/
|
|
117
|
+
get schemaCount(): number;
|
|
118
|
+
/**
|
|
119
|
+
* Get count of registered security schemes.
|
|
120
|
+
*/
|
|
121
|
+
get securitySchemeCount(): number;
|
|
122
|
+
/**
|
|
123
|
+
* Check if a schema is registered.
|
|
124
|
+
* @param name - Schema name
|
|
125
|
+
* @returns True if the schema is registered
|
|
126
|
+
*/
|
|
127
|
+
hasSchema(name: string): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Check if a security scheme is registered.
|
|
130
|
+
* @param name - Security scheme name
|
|
131
|
+
* @returns True if the security scheme is registered
|
|
132
|
+
*/
|
|
133
|
+
hasSecurityScheme(name: string): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Validate that all schema references can be resolved.
|
|
136
|
+
* @returns Array of unresolved schema references
|
|
137
|
+
*/
|
|
138
|
+
validateSchemaReferences(): string[];
|
|
139
|
+
/**
|
|
140
|
+
* Extract schema references from a schema object.
|
|
141
|
+
* @param schema - Schema object to scan
|
|
142
|
+
* @returns Array of referenced schema names
|
|
143
|
+
*/
|
|
144
|
+
private extractSchemaRefs;
|
|
145
|
+
/**
|
|
146
|
+
* Get all schema names.
|
|
147
|
+
* @returns Array of registered schema names
|
|
148
|
+
*/
|
|
149
|
+
getSchemaNames(): string[];
|
|
150
|
+
/**
|
|
151
|
+
* Get all security scheme names.
|
|
152
|
+
* @returns Array of registered security scheme names
|
|
153
|
+
*/
|
|
154
|
+
getSecuritySchemeNames(): string[];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Singleton instance of the schema registry.
|
|
158
|
+
*/
|
|
159
|
+
export declare const OpenAPISchemaRegistry: OpenAPISchemaRegistryClass;
|
|
160
|
+
/**
|
|
161
|
+
* Common schemas that are typically needed.
|
|
162
|
+
* Applications can register these or define their own.
|
|
163
|
+
*/
|
|
164
|
+
export declare const CommonSchemas: Record<string, Record<string, unknown>>;
|
|
165
|
+
/**
|
|
166
|
+
* Common security schemes.
|
|
167
|
+
*/
|
|
168
|
+
export declare const CommonSecuritySchemes: Record<string, Record<string, unknown>>;
|
|
169
|
+
export {};
|
|
170
|
+
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/openapi/schemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;GAGG;AACH,cAAM,0BAA0B;IAC9B,OAAO,CAAC,OAAO,CAA4C;IAC3D,OAAO,CAAC,eAAe,CAAmD;IAE1E;;;;;OAKG;IACH,cAAc,CACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,MAAM,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