@zudojs/openapi 0.1.0 → 1.1.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/LICENSE +21 -0
- package/README.md +327 -21
- package/dist/index.d.ts +26 -21
- package/dist/index.js +31 -13
- package/dist/openApiComponents/index.d.ts +2 -2
- package/dist/openApiComponents/index.js +1 -1
- package/dist/openApiConstants/index.d.ts +1 -1
- package/dist/openApiConstants/index.js +1 -1
- package/dist/openApiConstants/openApiConstants.core.d.ts +15 -3
- package/dist/openApiConstants/openApiConstants.core.js +22 -3
- package/dist/openApiDocument/index.d.ts +1 -1
- package/dist/openApiDocument/index.js +1 -1
- package/dist/openApiDocument/openApiDocument.builder.d.ts +39 -52
- package/dist/openApiDocument/openApiDocument.builder.js +73 -72
- package/dist/openApiErrors/index.d.ts +2 -2
- package/dist/openApiErrors/index.js +2 -1
- package/dist/openApiErrors/openApiError.base.d.ts +9 -0
- package/dist/openApiErrors/openApiError.base.js +7 -0
- package/dist/openApiErrors/openApiError.types.d.ts +34 -14
- package/dist/openApiErrors/openApiError.types.js +83 -35
- package/dist/openApiHttp/index.d.ts +2 -2
- package/dist/openApiHttp/index.js +2 -2
- package/dist/openApiHttp/openApiHttpAdapter.core.d.ts +127 -25
- package/dist/openApiHttp/openApiHttpAdapter.core.js +212 -16
- package/dist/openApiRegistry/openApiRegistry.core.d.ts +38 -5
- package/dist/openApiRegistry/openApiRegistry.core.js +167 -66
- package/dist/openApiRegistry/openApiRegistry.type.d.ts +18 -13
- package/dist/openApiRegistry/openApiRegistry.type.js +1 -2
- package/dist/openApiRouting/index.d.ts +2 -2
- package/dist/openApiRouting/index.js +1 -1
- package/dist/openApiRouting/routeConverter.core.d.ts +25 -7
- package/dist/openApiRouting/routeConverter.core.js +104 -58
- package/dist/openApiRouting/routeMetadata.type.d.ts +40 -17
- package/dist/openApiRouting/routeMetadata.type.js +9 -0
- package/dist/openApiRouting/routeScanner.core.d.ts +17 -47
- package/dist/openApiRouting/routeScanner.core.js +40 -55
- package/dist/openApiSchema/index.d.ts +4 -4
- package/dist/openApiSchema/index.js +2 -2
- package/dist/openApiSchema/references.core.d.ts +18 -1
- package/dist/openApiSchema/references.core.js +21 -1
- package/dist/openApiSchema/schemaConverter.core.d.ts +51 -3
- package/dist/openApiSchema/schemaConverter.core.js +475 -118
- package/dist/openApiSchema/schemaRegistry.core.d.ts +27 -10
- package/dist/openApiSchema/schemaRegistry.core.js +33 -14
- package/dist/openApiSerialization/openApiSerializer.core.d.ts +10 -4
- package/dist/openApiSerialization/openApiSerializer.core.js +135 -9
- package/dist/openApiTypes/index.d.ts +1 -1
- package/dist/openApiTypes/openApiDocument.type.d.ts +16 -0
- package/dist/openApiTypes/openApiSchema.type.d.ts +24 -1
- package/dist/openApiTypes/openApiSchema.type.js +3 -0
- package/dist/openApiUi/index.d.ts +8 -0
- package/dist/openApiUi/index.js +8 -0
- package/dist/openApiUi/openApiUi.brand.d.ts +26 -0
- package/dist/openApiUi/openApiUi.brand.js +44 -0
- package/dist/openApiUi/openApiUi.core.d.ts +47 -0
- package/dist/openApiUi/openApiUi.core.js +143 -0
- package/dist/openApiValidation/index.d.ts +2 -2
- package/dist/openApiValidation/index.js +1 -1
- package/dist/openApiValidation/openApiValidator.core.d.ts +33 -11
- package/dist/openApiValidation/openApiValidator.core.js +274 -66
- package/package.json +25 -18
- package/dist/.tsbuildinfo +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/openApiComponents/index.d.ts.map +0 -1
- package/dist/openApiComponents/index.js.map +0 -1
- package/dist/openApiConstants/index.d.ts.map +0 -1
- package/dist/openApiConstants/index.js.map +0 -1
- package/dist/openApiConstants/openApiConstants.core.d.ts.map +0 -1
- package/dist/openApiConstants/openApiConstants.core.js.map +0 -1
- package/dist/openApiDocument/index.d.ts.map +0 -1
- package/dist/openApiDocument/index.js.map +0 -1
- package/dist/openApiDocument/openApiDocument.builder.d.ts.map +0 -1
- package/dist/openApiDocument/openApiDocument.builder.js.map +0 -1
- package/dist/openApiErrors/index.d.ts.map +0 -1
- package/dist/openApiErrors/index.js.map +0 -1
- package/dist/openApiErrors/openApiError.base.d.ts.map +0 -1
- package/dist/openApiErrors/openApiError.base.js.map +0 -1
- package/dist/openApiErrors/openApiError.core.d.ts.map +0 -1
- package/dist/openApiErrors/openApiError.core.js.map +0 -1
- package/dist/openApiErrors/openApiError.types.d.ts.map +0 -1
- package/dist/openApiErrors/openApiError.types.js.map +0 -1
- package/dist/openApiHttp/index.d.ts.map +0 -1
- package/dist/openApiHttp/index.js.map +0 -1
- package/dist/openApiHttp/openApiHttpAdapter.core.d.ts.map +0 -1
- package/dist/openApiHttp/openApiHttpAdapter.core.js.map +0 -1
- package/dist/openApiRegistry/index.d.ts.map +0 -1
- package/dist/openApiRegistry/index.js.map +0 -1
- package/dist/openApiRegistry/openApiRegistry.core.d.ts.map +0 -1
- package/dist/openApiRegistry/openApiRegistry.core.js.map +0 -1
- package/dist/openApiRegistry/openApiRegistry.type.d.ts.map +0 -1
- package/dist/openApiRegistry/openApiRegistry.type.js.map +0 -1
- package/dist/openApiRouting/index.d.ts.map +0 -1
- package/dist/openApiRouting/index.js.map +0 -1
- package/dist/openApiRouting/routeConverter.core.d.ts.map +0 -1
- package/dist/openApiRouting/routeConverter.core.js.map +0 -1
- package/dist/openApiRouting/routeMetadata.type.d.ts.map +0 -1
- package/dist/openApiRouting/routeMetadata.type.js.map +0 -1
- package/dist/openApiRouting/routeScanner.core.d.ts.map +0 -1
- package/dist/openApiRouting/routeScanner.core.js.map +0 -1
- package/dist/openApiSchema/index.d.ts.map +0 -1
- package/dist/openApiSchema/index.js.map +0 -1
- package/dist/openApiSchema/references.core.d.ts.map +0 -1
- package/dist/openApiSchema/references.core.js.map +0 -1
- package/dist/openApiSchema/schemaConverter.core.d.ts.map +0 -1
- package/dist/openApiSchema/schemaConverter.core.js.map +0 -1
- package/dist/openApiSchema/schemaRegistry.core.d.ts.map +0 -1
- package/dist/openApiSchema/schemaRegistry.core.js.map +0 -1
- package/dist/openApiSerialization/index.d.ts.map +0 -1
- package/dist/openApiSerialization/index.js.map +0 -1
- package/dist/openApiSerialization/openApiSerializer.core.d.ts.map +0 -1
- package/dist/openApiSerialization/openApiSerializer.core.js.map +0 -1
- package/dist/openApiTypes/index.d.ts.map +0 -1
- package/dist/openApiTypes/index.js.map +0 -1
- package/dist/openApiTypes/openApiComponent.type.d.ts.map +0 -1
- package/dist/openApiTypes/openApiComponent.type.js.map +0 -1
- package/dist/openApiTypes/openApiDocument.type.d.ts.map +0 -1
- package/dist/openApiTypes/openApiDocument.type.js.map +0 -1
- package/dist/openApiTypes/openApiPath.type.d.ts.map +0 -1
- package/dist/openApiTypes/openApiPath.type.js.map +0 -1
- package/dist/openApiTypes/openApiSchema.type.d.ts.map +0 -1
- package/dist/openApiTypes/openApiSchema.type.js.map +0 -1
- package/dist/openApiTypes/openApiSecurity.type.d.ts.map +0 -1
- package/dist/openApiTypes/openApiSecurity.type.js.map +0 -1
- package/dist/openApiTypes/openApiTypes.core.d.ts.map +0 -1
- package/dist/openApiTypes/openApiTypes.core.js.map +0 -1
- package/dist/openApiValidation/index.d.ts.map +0 -1
- package/dist/openApiValidation/index.js.map +0 -1
- package/dist/openApiValidation/openApiValidator.core.d.ts.map +0 -1
- package/dist/openApiValidation/openApiValidator.core.js.map +0 -1
|
@@ -8,7 +8,20 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export const DEFAULT_OPENAPI_VERSION = "3.1.0";
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Every specification version this package can emit and validate.
|
|
12
|
+
*/
|
|
13
|
+
export const SUPPORTED_OPENAPI_VERSIONS = [
|
|
14
|
+
"3.0.0",
|
|
15
|
+
"3.0.1",
|
|
16
|
+
"3.0.2",
|
|
17
|
+
"3.0.3",
|
|
18
|
+
"3.1.0",
|
|
19
|
+
"3.1.1",
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Maximum operation ID length. Not a specification limit — a practical one:
|
|
23
|
+
* operation IDs become function names in generated clients, and tooling
|
|
24
|
+
* routinely truncates beyond this.
|
|
12
25
|
*/
|
|
13
26
|
export const MAX_OPERATION_ID_LENGTH = 128;
|
|
14
27
|
/**
|
|
@@ -20,7 +33,7 @@ export const COMPONENT_REF_PREFIX = "#/components";
|
|
|
20
33
|
*/
|
|
21
34
|
export const DEFAULT_MEDIA_TYPE = "application/json";
|
|
22
35
|
/**
|
|
23
|
-
* Status code categories.
|
|
36
|
+
* Status code categories, usable as OpenAPI response keys.
|
|
24
37
|
*/
|
|
25
38
|
export const STATUS_CODE_CATEGORIES = {
|
|
26
39
|
INFORMATIONAL: "1XX",
|
|
@@ -29,12 +42,18 @@ export const STATUS_CODE_CATEGORIES = {
|
|
|
29
42
|
CLIENT_ERROR: "4XX",
|
|
30
43
|
SERVER_ERROR: "5XX",
|
|
31
44
|
};
|
|
45
|
+
/** A response key is valid when it is `default`, `NXX`, or a status code. */
|
|
46
|
+
export const RESPONSE_KEY_PATTERN = /^(default|[1-5](XX|\d{2}))$/;
|
|
47
|
+
/** OpenAPI path template parameter, e.g. `{orderId}`. */
|
|
48
|
+
export const PATH_TEMPLATE_PARAMETER = /\{([^{}]+)\}/g;
|
|
32
49
|
/**
|
|
33
50
|
* Default server URL.
|
|
34
51
|
*/
|
|
35
52
|
export const DEFAULT_SERVER_URL = "http://localhost";
|
|
36
53
|
/**
|
|
37
|
-
*
|
|
54
|
+
* Default time a generated document stays cached before it is rebuilt.
|
|
55
|
+
*
|
|
56
|
+
* Applied by `OpenAPIManager`; pass `cacheTtlMs` to change or disable it.
|
|
38
57
|
*/
|
|
39
58
|
export const DOCUMENT_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
40
59
|
//# sourceMappingURL=openApiConstants.core.js.map
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* OpenAPI document builder.
|
|
5
5
|
*/
|
|
6
6
|
export type { OpenAPIDocumentOptions } from "./openApiDocument.builder.js";
|
|
7
|
-
export { OpenAPIDocumentBuilder } from "./openApiDocument.builder.js";
|
|
7
|
+
export { OpenAPIDocumentBuilder, createOpenAPIDocumentBuilder, } from "./openApiDocument.builder.js";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,60 +1,47 @@
|
|
|
1
|
-
import type { OpenAPIDocument } from "../openApiTypes/openApiTypes.core.js";
|
|
1
|
+
import type { OpenAPIDocument, OpenAPIExample, OpenAPIHeader, OpenAPIInfo, OpenAPIParameter, OpenAPIPathItem, OpenAPIRequestBody, OpenAPIResponse, OpenAPISchema, OpenAPISecurityRequirement, OpenAPISecurityScheme, OpenAPIServer, OpenAPITag } from "../openApiTypes/openApiTypes.core.js";
|
|
2
|
+
import type { OpenAPIRoute } from "../openApiRegistry/openApiRegistry.type.js";
|
|
2
3
|
export interface OpenAPIDocumentOptions {
|
|
3
|
-
readonly info:
|
|
4
|
-
readonly title: string;
|
|
5
|
-
readonly version: string;
|
|
6
|
-
readonly description?: string;
|
|
7
|
-
readonly summary?: string;
|
|
8
|
-
readonly termsOfService?: string;
|
|
9
|
-
readonly contact?: {
|
|
10
|
-
readonly name?: string;
|
|
11
|
-
readonly url?: string;
|
|
12
|
-
readonly email?: string;
|
|
13
|
-
};
|
|
14
|
-
readonly license?: {
|
|
15
|
-
readonly name: string;
|
|
16
|
-
readonly url?: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
4
|
+
readonly info: OpenAPIInfo;
|
|
19
5
|
readonly openapi?: string;
|
|
20
|
-
readonly servers?: readonly
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
readonly variables?: Readonly<Record<string, {
|
|
24
|
-
readonly enum?: readonly string[];
|
|
25
|
-
readonly default: string;
|
|
26
|
-
readonly description?: string;
|
|
27
|
-
}>>;
|
|
28
|
-
}[];
|
|
29
|
-
readonly tags?: readonly {
|
|
30
|
-
readonly name: string;
|
|
31
|
-
readonly description?: string;
|
|
32
|
-
}[];
|
|
33
|
-
readonly security?: readonly Record<string, readonly string[]>[];
|
|
6
|
+
readonly servers?: readonly OpenAPIServer[];
|
|
7
|
+
readonly tags?: readonly OpenAPITag[];
|
|
8
|
+
readonly security?: readonly OpenAPISecurityRequirement[];
|
|
34
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Fluent builder for a document assembled by hand.
|
|
12
|
+
*
|
|
13
|
+
* It is a thin facade over {@link OpenAPIRegistryImpl}, so a document built
|
|
14
|
+
* this way and one generated from routes go through the same assembly and
|
|
15
|
+
* validation rules. Two independent assemblers is how the generated documents
|
|
16
|
+
* ended up unable to express servers, tags or security at all.
|
|
17
|
+
*/
|
|
35
18
|
export declare class OpenAPIDocumentBuilder {
|
|
36
|
-
private readonly
|
|
19
|
+
private readonly registry;
|
|
37
20
|
constructor(options: OpenAPIDocumentOptions);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
21
|
+
/** The document's `info` object. */
|
|
22
|
+
info(info: OpenAPIInfo): this;
|
|
23
|
+
addServer(server: OpenAPIServer): this;
|
|
24
|
+
addTag(tag: OpenAPITag): this;
|
|
25
|
+
addSecurity(security: OpenAPISecurityRequirement): this;
|
|
26
|
+
/** Adds one operation. Repeated method+path combinations replace. */
|
|
27
|
+
addRoute(route: OpenAPIRoute): this;
|
|
28
|
+
/**
|
|
29
|
+
* Adds a whole path item.
|
|
30
|
+
*
|
|
31
|
+
* Each operation on it is registered individually, so the document keeps
|
|
32
|
+
* one path entry per path with the methods merged, as the specification
|
|
33
|
+
* requires.
|
|
34
|
+
*/
|
|
35
|
+
addPath(path: string, pathItem: OpenAPIPathItem): this;
|
|
36
|
+
addSchema(name: string, schema: OpenAPISchema): this;
|
|
37
|
+
addResponse(name: string, response: OpenAPIResponse): this;
|
|
38
|
+
addParameter(name: string, parameter: OpenAPIParameter): this;
|
|
39
|
+
addRequestBody(name: string, body: OpenAPIRequestBody): this;
|
|
40
|
+
addHeader(name: string, header: OpenAPIHeader): this;
|
|
41
|
+
addExample(name: string, example: OpenAPIExample): this;
|
|
42
|
+
addSecurityScheme(name: string, scheme: OpenAPISecurityScheme): this;
|
|
58
43
|
build(): Readonly<OpenAPIDocument>;
|
|
59
44
|
}
|
|
45
|
+
/** Creates a document builder. */
|
|
46
|
+
export declare function createOpenAPIDocumentBuilder(options: OpenAPIDocumentOptions): OpenAPIDocumentBuilder;
|
|
60
47
|
//# sourceMappingURL=openApiDocument.builder.d.ts.map
|
|
@@ -1,106 +1,107 @@
|
|
|
1
|
+
import { OpenAPIRegistryImpl } from "../openApiRegistry/openApiRegistry.core.js";
|
|
1
2
|
import { DEFAULT_OPENAPI_VERSION } from "../openApiConstants/openApiConstants.core.js";
|
|
3
|
+
/**
|
|
4
|
+
* Fluent builder for a document assembled by hand.
|
|
5
|
+
*
|
|
6
|
+
* It is a thin facade over {@link OpenAPIRegistryImpl}, so a document built
|
|
7
|
+
* this way and one generated from routes go through the same assembly and
|
|
8
|
+
* validation rules. Two independent assemblers is how the generated documents
|
|
9
|
+
* ended up unable to express servers, tags or security at all.
|
|
10
|
+
*/
|
|
2
11
|
export class OpenAPIDocumentBuilder {
|
|
3
|
-
|
|
12
|
+
registry;
|
|
4
13
|
constructor(options) {
|
|
5
|
-
this.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
+
this.registry = new OpenAPIRegistryImpl(options.openapi ?? DEFAULT_OPENAPI_VERSION);
|
|
15
|
+
this.registry.setInfo(options.info);
|
|
16
|
+
for (const server of options.servers ?? [])
|
|
17
|
+
this.registry.addServer(server);
|
|
18
|
+
for (const tag of options.tags ?? [])
|
|
19
|
+
this.registry.setTag(tag);
|
|
20
|
+
for (const requirement of options.security ?? []) {
|
|
21
|
+
this.registry.addSecurityRequirement(requirement);
|
|
22
|
+
}
|
|
14
23
|
}
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
/** The document's `info` object. */
|
|
25
|
+
info(info) {
|
|
26
|
+
this.registry.setInfo(info);
|
|
17
27
|
return this;
|
|
18
28
|
}
|
|
19
29
|
addServer(server) {
|
|
20
|
-
this.
|
|
30
|
+
this.registry.addServer(server);
|
|
21
31
|
return this;
|
|
22
32
|
}
|
|
23
33
|
addTag(tag) {
|
|
24
|
-
this.
|
|
34
|
+
this.registry.setTag(tag);
|
|
25
35
|
return this;
|
|
26
36
|
}
|
|
27
37
|
addSecurity(security) {
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
this.registry.addSecurityRequirement(security);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/** Adds one operation. Repeated method+path combinations replace. */
|
|
42
|
+
addRoute(route) {
|
|
43
|
+
this.registry.setRoute(route);
|
|
32
44
|
return this;
|
|
33
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Adds a whole path item.
|
|
48
|
+
*
|
|
49
|
+
* Each operation on it is registered individually, so the document keeps
|
|
50
|
+
* one path entry per path with the methods merged, as the specification
|
|
51
|
+
* requires.
|
|
52
|
+
*/
|
|
34
53
|
addPath(path, pathItem) {
|
|
35
|
-
|
|
54
|
+
const methods = [
|
|
55
|
+
"get",
|
|
56
|
+
"put",
|
|
57
|
+
"post",
|
|
58
|
+
"delete",
|
|
59
|
+
"options",
|
|
60
|
+
"head",
|
|
61
|
+
"patch",
|
|
62
|
+
"trace",
|
|
63
|
+
];
|
|
64
|
+
for (const method of methods) {
|
|
65
|
+
const operation = pathItem[method];
|
|
66
|
+
if (operation)
|
|
67
|
+
this.registry.setRoute({ method, path, operation });
|
|
68
|
+
}
|
|
36
69
|
return this;
|
|
37
70
|
}
|
|
38
71
|
addSchema(name, schema) {
|
|
39
|
-
|
|
40
|
-
this.document.components = {
|
|
41
|
-
...components,
|
|
42
|
-
schemas: { ...(components.schemas ?? {}), [name]: schema },
|
|
43
|
-
};
|
|
72
|
+
this.registry.registerSchema(name, schema);
|
|
44
73
|
return this;
|
|
45
74
|
}
|
|
46
75
|
addResponse(name, response) {
|
|
47
|
-
|
|
48
|
-
this.document.components = {
|
|
49
|
-
...components,
|
|
50
|
-
responses: { ...(components.responses ?? {}), [name]: response },
|
|
51
|
-
};
|
|
76
|
+
this.registry.registerResponse(name, response);
|
|
52
77
|
return this;
|
|
53
78
|
}
|
|
54
79
|
addParameter(name, parameter) {
|
|
55
|
-
|
|
56
|
-
this
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
80
|
+
this.registry.registerParameter(name, parameter);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
addRequestBody(name, body) {
|
|
84
|
+
this.registry.registerRequestBody(name, body);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
addHeader(name, header) {
|
|
88
|
+
this.registry.registerHeader(name, header);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
addExample(name, example) {
|
|
92
|
+
this.registry.registerExample(name, example);
|
|
60
93
|
return this;
|
|
61
94
|
}
|
|
62
95
|
addSecurityScheme(name, scheme) {
|
|
63
|
-
|
|
64
|
-
this.document.components = {
|
|
65
|
-
...components,
|
|
66
|
-
securitySchemes: {
|
|
67
|
-
...(components.securitySchemes ?? {}),
|
|
68
|
-
[name]: scheme,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
96
|
+
this.registry.registerSecurityScheme(name, scheme);
|
|
71
97
|
return this;
|
|
72
98
|
}
|
|
73
99
|
build() {
|
|
74
|
-
|
|
75
|
-
? {}
|
|
76
|
-
: this.document.paths;
|
|
77
|
-
const components = {};
|
|
78
|
-
if (this.document.components) {
|
|
79
|
-
for (const [key, value] of Object.entries(this.document.components)) {
|
|
80
|
-
if (value &&
|
|
81
|
-
typeof value === "object" &&
|
|
82
|
-
Object.keys(value).length > 0) {
|
|
83
|
-
components[key] = Object.freeze({ ...value });
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return Object.freeze({
|
|
88
|
-
openapi: this.document.openapi,
|
|
89
|
-
info: Object.freeze(this.document.info),
|
|
90
|
-
servers: this.document.servers?.length
|
|
91
|
-
? Object.freeze(this.document.servers)
|
|
92
|
-
: undefined,
|
|
93
|
-
paths: Object.freeze(paths),
|
|
94
|
-
...(Object.keys(components).length > 0
|
|
95
|
-
? { components: Object.freeze(components) }
|
|
96
|
-
: {}),
|
|
97
|
-
security: this.document.security?.length
|
|
98
|
-
? Object.freeze(this.document.security)
|
|
99
|
-
: undefined,
|
|
100
|
-
tags: this.document.tags?.length
|
|
101
|
-
? Object.freeze(this.document.tags)
|
|
102
|
-
: undefined,
|
|
103
|
-
});
|
|
100
|
+
return this.registry.generate();
|
|
104
101
|
}
|
|
105
102
|
}
|
|
103
|
+
/** Creates a document builder. */
|
|
104
|
+
export function createOpenAPIDocumentBuilder(options) {
|
|
105
|
+
return new OpenAPIDocumentBuilder(options);
|
|
106
|
+
}
|
|
106
107
|
//# sourceMappingURL=openApiDocument.builder.js.map
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* OpenAPI-specific error classes.
|
|
5
5
|
*/
|
|
6
|
-
export { OpenAPIError,
|
|
7
|
-
export
|
|
6
|
+
export { OpenAPIError, createOpenAPIError, isOpenAPIError, type OpenAPIErrorOptions, } from "./openApiError.base.js";
|
|
7
|
+
export { OpenAPIValidationError, OpenAPIDocumentError, OpenAPIComponentError, OpenAPIComponentConflictError, OpenAPIReferenceError, OpenAPIRouteError, OpenAPISchemaError, OpenAPISerializationError, OpenAPIVersionError, OpenAPIOperationError, formatIssuePath, type OpenAPIValidationIssue, } from "./openApiError.types.js";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* OpenAPI-specific error classes.
|
|
5
5
|
*/
|
|
6
|
-
export { OpenAPIError,
|
|
6
|
+
export { OpenAPIError, createOpenAPIError, isOpenAPIError, } from "./openApiError.base.js";
|
|
7
|
+
export { OpenAPIValidationError, OpenAPIDocumentError, OpenAPIComponentError, OpenAPIComponentConflictError, OpenAPIReferenceError, OpenAPIRouteError, OpenAPISchemaError, OpenAPISerializationError, OpenAPIVersionError, OpenAPIOperationError, formatIssuePath, } from "./openApiError.types.js";
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base OpenAPI error and factory functions.
|
|
3
|
+
*
|
|
4
|
+
* Everything in this package runs while a service builds or validates its own
|
|
5
|
+
* specification — none of it is triggered by a client request. So the
|
|
6
|
+
* defaults are the server-side ones: status 500, not exposed. A document that
|
|
7
|
+
* fails to build is an operator's problem, and leaking component names or
|
|
8
|
+
* version mismatches into a client-visible body tells an attacker about the
|
|
9
|
+
* shape of the API rather than telling the operator anything.
|
|
3
10
|
*/
|
|
4
11
|
import { BaseError } from "@zudojs/errors";
|
|
5
12
|
/** Options for creating an OpenAPI error. */
|
|
6
13
|
export interface OpenAPIErrorOptions {
|
|
7
14
|
readonly code?: string;
|
|
15
|
+
/** Overrides the subclass's default status. */
|
|
8
16
|
readonly statusCode?: number;
|
|
17
|
+
/** Overrides the subclass's default exposure. */
|
|
9
18
|
readonly expose?: boolean;
|
|
10
19
|
readonly cause?: unknown;
|
|
11
20
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base OpenAPI error and factory functions.
|
|
3
|
+
*
|
|
4
|
+
* Everything in this package runs while a service builds or validates its own
|
|
5
|
+
* specification — none of it is triggered by a client request. So the
|
|
6
|
+
* defaults are the server-side ones: status 500, not exposed. A document that
|
|
7
|
+
* fails to build is an operator's problem, and leaking component names or
|
|
8
|
+
* version mismatches into a client-visible body tells an attacker about the
|
|
9
|
+
* shape of the API rather than telling the operator anything.
|
|
3
10
|
*/
|
|
4
11
|
import { BaseError, ErrorCode, ErrorCategory, ErrorSeverity, } from "@zudojs/errors";
|
|
5
12
|
/** Base error for all OpenAPI subsystem failures. */
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Specific OpenAPI error subclasses.
|
|
3
|
+
*
|
|
4
|
+
* Each subclass supplies a default `code`, `statusCode` and `expose`, and each
|
|
5
|
+
* lets the caller override them — the options are spread *after* the defaults,
|
|
6
|
+
* so a value passed in is the value used.
|
|
3
7
|
*/
|
|
4
8
|
import { OpenAPIError, type OpenAPIErrorOptions } from "./openApiError.base.js";
|
|
5
|
-
/**
|
|
9
|
+
/** A single validation issue. */
|
|
10
|
+
export interface OpenAPIValidationIssue {
|
|
11
|
+
/** Location of the problem, as a path through the document. */
|
|
12
|
+
readonly path: readonly (string | number)[];
|
|
13
|
+
readonly message: string;
|
|
14
|
+
readonly severity: "error" | "warning";
|
|
15
|
+
}
|
|
16
|
+
/** Renders an issue path the way a reader would write it. */
|
|
17
|
+
export declare function formatIssuePath(path: readonly (string | number)[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Error thrown when OpenAPI validation fails.
|
|
20
|
+
*
|
|
21
|
+
* The issues are kept on the error. Discarding them left callers with the
|
|
22
|
+
* message "OpenAPI validation failed." and no way to learn what was wrong
|
|
23
|
+
* short of re-running the validator.
|
|
24
|
+
*/
|
|
6
25
|
export declare class OpenAPIValidationError extends OpenAPIError {
|
|
7
|
-
|
|
26
|
+
readonly issues: readonly OpenAPIValidationIssue[];
|
|
27
|
+
constructor(message: string, issues?: readonly OpenAPIValidationIssue[], options?: OpenAPIErrorOptions);
|
|
28
|
+
/** A multi-line summary suitable for a log line or a CLI. */
|
|
29
|
+
format(): string;
|
|
8
30
|
}
|
|
9
31
|
/** Error thrown when the OpenAPI document is invalid. */
|
|
10
32
|
export declare class OpenAPIDocumentError extends OpenAPIError {
|
|
@@ -14,15 +36,18 @@ export declare class OpenAPIDocumentError extends OpenAPIError {
|
|
|
14
36
|
export declare class OpenAPIComponentError extends OpenAPIError {
|
|
15
37
|
constructor(message: string, options?: OpenAPIErrorOptions);
|
|
16
38
|
}
|
|
17
|
-
/** Error thrown when
|
|
39
|
+
/** Error thrown when a component name is already registered. */
|
|
18
40
|
export declare class OpenAPIComponentConflictError extends OpenAPIError {
|
|
19
|
-
|
|
41
|
+
readonly section: string;
|
|
42
|
+
readonly componentName: string;
|
|
43
|
+
constructor(section: string, componentName: string, options?: OpenAPIErrorOptions);
|
|
20
44
|
}
|
|
21
|
-
/** Error thrown when an OpenAPI reference is invalid. */
|
|
45
|
+
/** Error thrown when an OpenAPI reference is invalid or cannot be resolved. */
|
|
22
46
|
export declare class OpenAPIReferenceError extends OpenAPIError {
|
|
23
|
-
|
|
47
|
+
readonly reference: string;
|
|
48
|
+
constructor(reference: string, options?: OpenAPIErrorOptions);
|
|
24
49
|
}
|
|
25
|
-
/** Error thrown when an OpenAPI route
|
|
50
|
+
/** Error thrown when an OpenAPI route cannot be converted. */
|
|
26
51
|
export declare class OpenAPIRouteError extends OpenAPIError {
|
|
27
52
|
constructor(message: string, options?: OpenAPIErrorOptions);
|
|
28
53
|
}
|
|
@@ -36,16 +61,11 @@ export declare class OpenAPISerializationError extends OpenAPIError {
|
|
|
36
61
|
}
|
|
37
62
|
/** Error thrown when the OpenAPI version is unsupported. */
|
|
38
63
|
export declare class OpenAPIVersionError extends OpenAPIError {
|
|
39
|
-
|
|
64
|
+
readonly version: string;
|
|
65
|
+
constructor(version: string, supported?: readonly string[], options?: OpenAPIErrorOptions);
|
|
40
66
|
}
|
|
41
67
|
/** Error thrown when an OpenAPI operation is invalid. */
|
|
42
68
|
export declare class OpenAPIOperationError extends OpenAPIError {
|
|
43
69
|
constructor(message: string, options?: OpenAPIErrorOptions);
|
|
44
70
|
}
|
|
45
|
-
/** A single validation issue. */
|
|
46
|
-
export interface OpenAPIValidationIssue {
|
|
47
|
-
readonly path: readonly (string | number)[];
|
|
48
|
-
readonly message: string;
|
|
49
|
-
readonly severity: "error" | "warning";
|
|
50
|
-
}
|
|
51
71
|
//# sourceMappingURL=openApiError.types.d.ts.map
|