@spinajs/http-swagger 2.0.471 → 2.0.472
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/lib/cjs/cli/GenerateSwaggerCache.d.ts +10 -0
- package/lib/cjs/cli/GenerateSwaggerCache.d.ts.map +1 -0
- package/lib/cjs/cli/GenerateSwaggerCache.js +43 -0
- package/lib/cjs/cli/GenerateSwaggerCache.js.map +1 -0
- package/lib/cjs/config/http-swagger.d.ts +42 -0
- package/lib/cjs/config/http-swagger.d.ts.map +1 -0
- package/lib/cjs/config/http-swagger.js +84 -0
- package/lib/cjs/config/http-swagger.js.map +1 -0
- package/lib/cjs/controllers/SwaggerController.d.ts +26 -0
- package/lib/cjs/controllers/SwaggerController.d.ts.map +1 -0
- package/lib/cjs/controllers/SwaggerController.js +74 -0
- package/lib/cjs/controllers/SwaggerController.js.map +1 -0
- package/lib/cjs/index.d.ts +7 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +23 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces.d.ts +211 -0
- package/lib/cjs/interfaces.d.ts.map +1 -0
- package/lib/cjs/interfaces.js +3 -0
- package/lib/cjs/interfaces.js.map +1 -0
- package/lib/cjs/openapi-builder.d.ts +153 -0
- package/lib/cjs/openapi-builder.d.ts.map +1 -0
- package/lib/cjs/openapi-builder.js +844 -0
- package/lib/cjs/openapi-builder.js.map +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/swagger-cache.d.ts +18 -0
- package/lib/cjs/swagger-cache.d.ts.map +1 -0
- package/lib/cjs/swagger-cache.js +110 -0
- package/lib/cjs/swagger-cache.js.map +1 -0
- package/lib/cjs/swagger-service.d.ts +24 -0
- package/lib/cjs/swagger-service.d.ts.map +1 -0
- package/lib/cjs/swagger-service.js +88 -0
- package/lib/cjs/swagger-service.js.map +1 -0
- package/lib/mjs/cli/GenerateSwaggerCache.d.ts +10 -0
- package/lib/mjs/cli/GenerateSwaggerCache.d.ts.map +1 -0
- package/lib/mjs/cli/GenerateSwaggerCache.js +40 -0
- package/lib/mjs/cli/GenerateSwaggerCache.js.map +1 -0
- package/lib/mjs/config/http-swagger.d.ts +42 -0
- package/lib/mjs/config/http-swagger.d.ts.map +1 -0
- package/lib/mjs/config/http-swagger.js +82 -0
- package/lib/mjs/config/http-swagger.js.map +1 -0
- package/lib/mjs/controllers/SwaggerController.d.ts +26 -0
- package/lib/mjs/controllers/SwaggerController.d.ts.map +1 -0
- package/lib/mjs/controllers/SwaggerController.js +71 -0
- package/lib/mjs/controllers/SwaggerController.js.map +1 -0
- package/lib/mjs/index.d.ts +7 -0
- package/lib/mjs/index.d.ts.map +1 -0
- package/lib/mjs/index.js +7 -0
- package/lib/mjs/index.js.map +1 -0
- package/lib/mjs/interfaces.d.ts +211 -0
- package/lib/mjs/interfaces.d.ts.map +1 -0
- package/lib/mjs/interfaces.js +2 -0
- package/lib/mjs/interfaces.js.map +1 -0
- package/lib/mjs/openapi-builder.d.ts +153 -0
- package/lib/mjs/openapi-builder.d.ts.map +1 -0
- package/lib/mjs/openapi-builder.js +840 -0
- package/lib/mjs/openapi-builder.js.map +1 -0
- package/lib/mjs/package.json +1 -0
- package/lib/mjs/swagger-cache.d.ts +18 -0
- package/lib/mjs/swagger-cache.d.ts.map +1 -0
- package/lib/mjs/swagger-cache.js +107 -0
- package/lib/mjs/swagger-cache.js.map +1 -0
- package/lib/mjs/swagger-service.d.ts +24 -0
- package/lib/mjs/swagger-service.d.ts.map +1 -0
- package/lib/mjs/swagger-service.js +85 -0
- package/lib/mjs/swagger-service.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -0
- package/lib/tsconfig.mjs.tsbuildinfo +1 -0
- package/lib/views/swagger-ui-init.js +11 -0
- package/lib/views/swagger.pug +16 -0
- package/package.json +11 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC"}
|
package/lib/mjs/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './interfaces.js';
|
|
2
|
+
export * from './swagger-cache.js';
|
|
3
|
+
export * from './swagger-service.js';
|
|
4
|
+
export * from './controllers/SwaggerController.js';
|
|
5
|
+
export * from './openapi-builder.js';
|
|
6
|
+
export * from './cli/GenerateSwaggerCache.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for Swagger/OpenAPI documentation generation.
|
|
3
|
+
* Read from application configuration at path `http.swagger`
|
|
4
|
+
*/
|
|
5
|
+
export interface ISwaggerConfig {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
title: string;
|
|
8
|
+
version: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
basePath?: string;
|
|
11
|
+
servers?: ISwaggerServer[];
|
|
12
|
+
securitySchemes?: Record<string, ISecurityScheme>;
|
|
13
|
+
security?: Record<string, string[]>[];
|
|
14
|
+
ui?: ISwaggerUiConfig;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for Swagger UI rendering
|
|
18
|
+
*/
|
|
19
|
+
export interface ISwaggerUiConfig {
|
|
20
|
+
/**
|
|
21
|
+
* URL to swagger-ui CSS file
|
|
22
|
+
*/
|
|
23
|
+
cssUrl: string;
|
|
24
|
+
/**
|
|
25
|
+
* URL to swagger-ui-bundle.js
|
|
26
|
+
*/
|
|
27
|
+
bundleUrl: string;
|
|
28
|
+
/**
|
|
29
|
+
* URL to swagger-ui-standalone-preset.js
|
|
30
|
+
*/
|
|
31
|
+
presetUrl: string;
|
|
32
|
+
/**
|
|
33
|
+
* URL to the OpenAPI JSON spec endpoint (used by Swagger UI to load the spec)
|
|
34
|
+
*/
|
|
35
|
+
specUrl: string;
|
|
36
|
+
/**
|
|
37
|
+
* Custom page title for the Swagger UI page
|
|
38
|
+
*/
|
|
39
|
+
pageTitle?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ISwaggerServer {
|
|
42
|
+
url: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ISecurityScheme {
|
|
46
|
+
type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
|
|
47
|
+
scheme?: string;
|
|
48
|
+
bearerFormat?: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
in?: 'query' | 'header' | 'cookie';
|
|
51
|
+
description?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* JSDoc documentation extracted from a controller method
|
|
55
|
+
*/
|
|
56
|
+
export interface IMethodDocumentation {
|
|
57
|
+
summary?: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
params: Record<string, IParamDocumentation>;
|
|
60
|
+
returns?: IReturnDocumentation;
|
|
61
|
+
responses?: Record<string, IResponseDocumentation>;
|
|
62
|
+
examples?: IExampleDocumentation[];
|
|
63
|
+
tags?: string[];
|
|
64
|
+
deprecated?: boolean;
|
|
65
|
+
security?: Array<Record<string, string[]>>;
|
|
66
|
+
}
|
|
67
|
+
export interface IParamDocumentation {
|
|
68
|
+
name: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
type?: string;
|
|
71
|
+
required?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface IReturnDocumentation {
|
|
74
|
+
description?: string;
|
|
75
|
+
type?: string;
|
|
76
|
+
schema?: IOpenApiSchema;
|
|
77
|
+
}
|
|
78
|
+
export interface IResponseDocumentation {
|
|
79
|
+
description: string;
|
|
80
|
+
type?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface IExampleDocumentation {
|
|
83
|
+
name?: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
value?: string;
|
|
86
|
+
}
|
|
87
|
+
/** JSDoc-extracted documentation for a policy class */
|
|
88
|
+
export interface IPolicyDocumentation {
|
|
89
|
+
/** File where the policy is defined (for traceability) */
|
|
90
|
+
file?: string;
|
|
91
|
+
/** Class-level JSDoc description, if present */
|
|
92
|
+
description?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Cache entry for a single controller's JSDoc documentation
|
|
96
|
+
*/
|
|
97
|
+
export interface ISwaggerCacheEntry {
|
|
98
|
+
className: string;
|
|
99
|
+
classDescription?: string;
|
|
100
|
+
classTags?: string[];
|
|
101
|
+
methods: Record<string, IMethodDocumentation>;
|
|
102
|
+
/** Controller-level policies (applied to every route on the controller) */
|
|
103
|
+
controllerPolicies?: string[];
|
|
104
|
+
/** Per-route policy class names */
|
|
105
|
+
routePolicies?: Record<string, string[]>;
|
|
106
|
+
/** Docs for each referenced policy class, keyed by class name */
|
|
107
|
+
policies?: Record<string, IPolicyDocumentation>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* OpenAPI 3.0 document structure
|
|
111
|
+
*/
|
|
112
|
+
export interface IOpenApiDocument {
|
|
113
|
+
openapi: string;
|
|
114
|
+
info: IOpenApiInfo;
|
|
115
|
+
servers?: IOpenApiServer[];
|
|
116
|
+
paths: Record<string, IOpenApiPathItem>;
|
|
117
|
+
components?: IOpenApiComponents;
|
|
118
|
+
security?: Record<string, string[]>[];
|
|
119
|
+
tags?: IOpenApiTag[];
|
|
120
|
+
}
|
|
121
|
+
export interface IOpenApiInfo {
|
|
122
|
+
title: string;
|
|
123
|
+
version: string;
|
|
124
|
+
description?: string;
|
|
125
|
+
}
|
|
126
|
+
export interface IOpenApiServer {
|
|
127
|
+
url: string;
|
|
128
|
+
description?: string;
|
|
129
|
+
}
|
|
130
|
+
export interface IOpenApiTag {
|
|
131
|
+
name: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface IOpenApiPathItem {
|
|
135
|
+
[method: string]: IOpenApiOperation;
|
|
136
|
+
}
|
|
137
|
+
export interface IOpenApiOperation {
|
|
138
|
+
operationId?: string;
|
|
139
|
+
summary?: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
tags?: string[];
|
|
142
|
+
deprecated?: boolean;
|
|
143
|
+
parameters?: IOpenApiParameter[];
|
|
144
|
+
requestBody?: IOpenApiRequestBody;
|
|
145
|
+
responses: Record<string, IOpenApiResponse>;
|
|
146
|
+
security?: Record<string, string[]>[];
|
|
147
|
+
/** RBAC resource name (from rbac-http @Resource) */
|
|
148
|
+
'x-rbac-resource'?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Permissions accepted for this route (accesscontrol actions:
|
|
151
|
+
* readAny|readOwn|updateAny|updateOwn|createAny|createOwn|deleteAny|deleteOwn).
|
|
152
|
+
* Access is granted if the caller's role(s) have at least one.
|
|
153
|
+
*/
|
|
154
|
+
'x-rbac-permissions'?: string[];
|
|
155
|
+
/** Policy class names applied to this route (controller-level + route-level, in execution order) */
|
|
156
|
+
'x-policies'?: string[];
|
|
157
|
+
}
|
|
158
|
+
export interface IOpenApiParameter {
|
|
159
|
+
name: string;
|
|
160
|
+
in: 'query' | 'path' | 'header' | 'cookie';
|
|
161
|
+
description?: string;
|
|
162
|
+
required?: boolean;
|
|
163
|
+
schema?: IOpenApiSchema;
|
|
164
|
+
style?: string;
|
|
165
|
+
explode?: boolean;
|
|
166
|
+
}
|
|
167
|
+
export interface IOpenApiRequestBody {
|
|
168
|
+
description?: string;
|
|
169
|
+
required?: boolean;
|
|
170
|
+
content: Record<string, IOpenApiMediaType>;
|
|
171
|
+
}
|
|
172
|
+
export interface IOpenApiMediaType {
|
|
173
|
+
schema?: IOpenApiSchema;
|
|
174
|
+
examples?: Record<string, IOpenApiExample>;
|
|
175
|
+
}
|
|
176
|
+
export interface IOpenApiExample {
|
|
177
|
+
summary?: string;
|
|
178
|
+
description?: string;
|
|
179
|
+
value?: any;
|
|
180
|
+
}
|
|
181
|
+
export interface IOpenApiResponse {
|
|
182
|
+
description?: string;
|
|
183
|
+
content?: Record<string, IOpenApiMediaType>;
|
|
184
|
+
$ref?: string;
|
|
185
|
+
}
|
|
186
|
+
export interface IOpenApiSchema {
|
|
187
|
+
type?: string;
|
|
188
|
+
format?: string;
|
|
189
|
+
items?: IOpenApiSchema;
|
|
190
|
+
properties?: Record<string, IOpenApiSchema>;
|
|
191
|
+
required?: string[];
|
|
192
|
+
$ref?: string;
|
|
193
|
+
description?: string;
|
|
194
|
+
enum?: any[];
|
|
195
|
+
minimum?: number;
|
|
196
|
+
maximum?: number;
|
|
197
|
+
minLength?: number;
|
|
198
|
+
maxLength?: number;
|
|
199
|
+
pattern?: string;
|
|
200
|
+
nullable?: boolean;
|
|
201
|
+
oneOf?: IOpenApiSchema[];
|
|
202
|
+
anyOf?: IOpenApiSchema[];
|
|
203
|
+
allOf?: IOpenApiSchema[];
|
|
204
|
+
example?: unknown;
|
|
205
|
+
}
|
|
206
|
+
export interface IOpenApiComponents {
|
|
207
|
+
schemas?: Record<string, IOpenApiSchema>;
|
|
208
|
+
securitySchemes?: Record<string, ISecurityScheme>;
|
|
209
|
+
responses?: Record<string, IOpenApiResponse>;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACj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,CAAC;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { ClassInfo } from '@spinajs/di';
|
|
2
|
+
import { BaseController } from '@spinajs/http';
|
|
3
|
+
import { IOpenApiDocument, ISwaggerCacheEntry, ISwaggerConfig } from './interfaces.js';
|
|
4
|
+
export declare class OpenApiBuilder {
|
|
5
|
+
private config;
|
|
6
|
+
private document;
|
|
7
|
+
private tags;
|
|
8
|
+
private registeredResponses;
|
|
9
|
+
private errorSchemaRegistered;
|
|
10
|
+
private registeredPolicies;
|
|
11
|
+
private policySectionEntries;
|
|
12
|
+
private infoDescriptionBase;
|
|
13
|
+
constructor(config: ISwaggerConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Add a controller's routes to the OpenAPI document.
|
|
16
|
+
*/
|
|
17
|
+
addController(controller: ClassInfo<BaseController>, docCache: ISwaggerCacheEntry): void;
|
|
18
|
+
/**
|
|
19
|
+
* Surface policy information on an operation:
|
|
20
|
+
* - merge controller-level and route-level policies (controller policies run first)
|
|
21
|
+
* - vendor extension `x-policies` for tooling
|
|
22
|
+
* - human-readable line appended to `description`; each policy links to the
|
|
23
|
+
* reusable "Policies" section appended to `info.description`
|
|
24
|
+
*
|
|
25
|
+
* The JSDoc descriptions for each unique policy are registered once on the
|
|
26
|
+
* document via `registerPolicyReference()`.
|
|
27
|
+
*/
|
|
28
|
+
private applyPolicies;
|
|
29
|
+
/**
|
|
30
|
+
* Lazily register a policy in the document-level "Policies" section.
|
|
31
|
+
* OpenAPI 3.0 has no first-class "policies" components bucket, so we render
|
|
32
|
+
* them into `info.description` as a markdown anchor that Swagger UI can
|
|
33
|
+
* link to from operation descriptions.
|
|
34
|
+
*/
|
|
35
|
+
private registerPolicyReference;
|
|
36
|
+
private policyAnchor;
|
|
37
|
+
private firstSentence;
|
|
38
|
+
/**
|
|
39
|
+
* Read rbac-http's controller descriptor via the global metadata symbol.
|
|
40
|
+
* Returns undefined when the controller isn't RBAC-decorated.
|
|
41
|
+
*/
|
|
42
|
+
private readRbacDescriptor;
|
|
43
|
+
/**
|
|
44
|
+
* Attach RBAC info to an operation:
|
|
45
|
+
* - vendor extensions `x-rbac-resource` and `x-rbac-permissions` for
|
|
46
|
+
* tooling / code-gen consumers
|
|
47
|
+
* - a human-readable line appended to the description for Swagger UI
|
|
48
|
+
*/
|
|
49
|
+
private applyRbac;
|
|
50
|
+
/**
|
|
51
|
+
* Build the final OpenAPI document.
|
|
52
|
+
*/
|
|
53
|
+
build(): IOpenApiDocument;
|
|
54
|
+
/**
|
|
55
|
+
* Build the full URL path for a route.
|
|
56
|
+
*/
|
|
57
|
+
private buildPath;
|
|
58
|
+
/**
|
|
59
|
+
* Map SpineJS RouteType to OpenAPI HTTP method string.
|
|
60
|
+
*/
|
|
61
|
+
private mapRouteType;
|
|
62
|
+
/**
|
|
63
|
+
* Build an OpenAPI operation from a route and its documentation.
|
|
64
|
+
*/
|
|
65
|
+
private buildOperation;
|
|
66
|
+
/**
|
|
67
|
+
* Describe the JSON filter envelope used by orm-http's @Filter decorator.
|
|
68
|
+
*
|
|
69
|
+
* @Filter accepts either:
|
|
70
|
+
* - a Model constructor — @Filterable on its columns stores the filterable
|
|
71
|
+
* column map on the model descriptor (Reflect metadata under
|
|
72
|
+
* Symbol.for('MODEL_DESCRIPTOR')) at class-load time. We read it directly
|
|
73
|
+
* so the schema is available even before orm-http's runtime mixin attaches.
|
|
74
|
+
* - an IColumnFilter[] — we build the same envelope shape inline from the
|
|
75
|
+
* column descriptors.
|
|
76
|
+
*
|
|
77
|
+
* Both cases produce the same { op, filters: [...] } envelope as the runtime
|
|
78
|
+
* builder in packages/orm-http/src/{model.ts,route-arg.ts}.
|
|
79
|
+
*/
|
|
80
|
+
private buildFilterSchema;
|
|
81
|
+
/**
|
|
82
|
+
* Read the FilterableColumns map from a model constructor via the orm model
|
|
83
|
+
* descriptor metadata. Keeps http-swagger free of a hard @spinajs/orm dep —
|
|
84
|
+
* the symbol is global (`Symbol.for('MODEL_DESCRIPTOR')`).
|
|
85
|
+
*/
|
|
86
|
+
private extractFilterableColumns;
|
|
87
|
+
/**
|
|
88
|
+
* Build the { op, filters: [...] } envelope schema given a list of filterable columns.
|
|
89
|
+
*
|
|
90
|
+
* OAS 3.0.3 (the doc version we emit) does NOT support multi-type arrays for
|
|
91
|
+
* `type` — that's an OAS 3.1 feature. Swagger UI renders such schemas as
|
|
92
|
+
* "Unknown Type: ...". We emit `oneOf` for the Value union and single-typed
|
|
93
|
+
* sub-schemas for everything else.
|
|
94
|
+
*/
|
|
95
|
+
private filterEnvelopeSchema;
|
|
96
|
+
/**
|
|
97
|
+
* Resolve the effective OpenAPI location for orm-http's @FromModel param.
|
|
98
|
+
* Mirrors FromDbModel.extract(): paramType decides where the PK is read from
|
|
99
|
+
* (defaults to path/req.params).
|
|
100
|
+
*/
|
|
101
|
+
private fromDbModelLocation;
|
|
102
|
+
/**
|
|
103
|
+
* Build an OpenAPI parameter from route parameter info.
|
|
104
|
+
*/
|
|
105
|
+
private buildParameter;
|
|
106
|
+
/**
|
|
107
|
+
* Resolve the best schema for a route parameter.
|
|
108
|
+
* Priority: JSDoc type → decorator schema (param.Schema) → auto-detected primitive (param.RouteParamSchema) → @Schema metadata on DTO class → runtime type inference
|
|
109
|
+
*/
|
|
110
|
+
private schemaFromParam;
|
|
111
|
+
/**
|
|
112
|
+
* Convert a JSON Schema object to an OpenAPI schema, mapping known keywords.
|
|
113
|
+
*/
|
|
114
|
+
private convertJsonSchema;
|
|
115
|
+
/**
|
|
116
|
+
* Build an OpenAPI request body from body-type parameters.
|
|
117
|
+
*/
|
|
118
|
+
private buildRequestBody;
|
|
119
|
+
/**
|
|
120
|
+
* Build response definitions from JSDoc @returns and @response tags.
|
|
121
|
+
* Only responses explicitly documented in JSDoc are included.
|
|
122
|
+
*/
|
|
123
|
+
private buildResponses;
|
|
124
|
+
/**
|
|
125
|
+
* Lazily register a reusable response component for a standard HTTP status
|
|
126
|
+
* code (e.g. 401 → `#/components/responses/Unauthorized`) and the shared
|
|
127
|
+
* Error schema. Returns the component name to $ref, or undefined if the code
|
|
128
|
+
* isn't in our standard set.
|
|
129
|
+
*
|
|
130
|
+
* JSDoc description overrides the default; first JSDoc description wins per
|
|
131
|
+
* status code so the component stays stable across operations.
|
|
132
|
+
*/
|
|
133
|
+
private registerStandardResponse;
|
|
134
|
+
/**
|
|
135
|
+
* Register the shared Error schema once. Matches the runtime error envelope
|
|
136
|
+
* built in packages/http/src/error.ts (spread of the Error instance + message,
|
|
137
|
+
* with optional stack in dev).
|
|
138
|
+
*/
|
|
139
|
+
private ensureErrorSchema;
|
|
140
|
+
/**
|
|
141
|
+
* Infer an OpenAPI schema from a TypeScript runtime type.
|
|
142
|
+
*/
|
|
143
|
+
private inferSchema;
|
|
144
|
+
/**
|
|
145
|
+
* Infer schema from a JSDoc type string like {string}, {number}, {MyDto}
|
|
146
|
+
*/
|
|
147
|
+
private inferSchemaFromString;
|
|
148
|
+
/**
|
|
149
|
+
* Try to parse a string as JSON, return as-is if not valid JSON.
|
|
150
|
+
*/
|
|
151
|
+
private tryParseJson;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=openapi-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi-builder.d.ts","sourceRoot":"","sources":["../../src/openapi-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,cAAc,EAAqD,MAAM,eAAe,CAAC;AAElG,OAAO,EACL,gBAAgB,EAOhB,kBAAkB,EAClB,cAAc,EAEf,MAAM,iBAAiB,CAAC;AA6FzB,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,IAAI,CAAuC;IACnD,OAAO,CAAC,mBAAmB,CAA0B;IACrD,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,kBAAkB,CAA0B;IACpD,OAAO,CAAC,oBAAoB,CAAgB;IAC5C,OAAO,CAAC,mBAAmB,CAAc;gBAE7B,MAAM,EAAE,cAAc;IA2BlC;;OAEG;IACI,aAAa,C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