@e22m4u/js-openapi 0.0.5
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/.c8rc +9 -0
- package/.commitlintrc +5 -0
- package/.editorconfig +13 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +6 -0
- package/.mocharc.json +4 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/README.md +510 -0
- package/build-cjs.js +16 -0
- package/dist/cjs/index.cjs +2695 -0
- package/eslint.config.js +41 -0
- package/package.json +64 -0
- package/src/data-type/index.d.ts +1 -0
- package/src/data-type/index.js +1 -0
- package/src/data-type/infer-openapi-data-type.d.ts +30 -0
- package/src/data-type/infer-openapi-data-type.js +38 -0
- package/src/data-validation/data-format-validator-map.d.ts +13 -0
- package/src/data-validation/data-format-validator-map.js +36 -0
- package/src/data-validation/data-format-validator-map.spec.js +39 -0
- package/src/data-validation/data-format-validators.d.ts +84 -0
- package/src/data-validation/data-format-validators.js +217 -0
- package/src/data-validation/index.d.ts +3 -0
- package/src/data-validation/index.js +3 -0
- package/src/data-validation/validate-data-with-openapi-schema.d.ts +46 -0
- package/src/data-validation/validate-data-with-openapi-schema.js +1913 -0
- package/src/data-validation/validate-data-with-openapi-schema.spec.js +6953 -0
- package/src/errors/index.d.ts +1 -0
- package/src/errors/index.js +1 -0
- package/src/errors/oa-data-validation-error.d.ts +6 -0
- package/src/errors/oa-data-validation-error.js +6 -0
- package/src/errors/oa-data-validation-error.spec.js +17 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +9 -0
- package/src/json-pointer/escape-json-pointer.d.ts +7 -0
- package/src/json-pointer/escape-json-pointer.js +18 -0
- package/src/json-pointer/escape-json-pointer.spec.js +36 -0
- package/src/json-pointer/index.d.ts +3 -0
- package/src/json-pointer/index.js +3 -0
- package/src/json-pointer/resolve-json-pointer.d.ts +10 -0
- package/src/json-pointer/resolve-json-pointer.js +83 -0
- package/src/json-pointer/resolve-json-pointer.spec.js +103 -0
- package/src/json-pointer/unescape-json-pointer.d.ts +8 -0
- package/src/json-pointer/unescape-json-pointer.js +18 -0
- package/src/json-pointer/unescape-json-pointer.spec.js +32 -0
- package/src/oa-document-builder.d.ts +312 -0
- package/src/oa-document-builder.js +450 -0
- package/src/oa-document-object/index.d.ts +1 -0
- package/src/oa-document-object/index.js +1 -0
- package/src/oa-document-object/validate-shallow-oa-document.d.ts +10 -0
- package/src/oa-document-object/validate-shallow-oa-document.js +209 -0
- package/src/oa-document-object/validate-shallow-oa-document.spec.js +362 -0
- package/src/oa-document-scope.d.ts +52 -0
- package/src/oa-document-scope.js +228 -0
- package/src/oa-reference-object/index.d.ts +3 -0
- package/src/oa-reference-object/index.js +3 -0
- package/src/oa-reference-object/is-oa-reference-object.d.ts +9 -0
- package/src/oa-reference-object/is-oa-reference-object.js +14 -0
- package/src/oa-reference-object/is-oa-reference-object.spec.js +19 -0
- package/src/oa-reference-object/oa-ref.d.ts +11 -0
- package/src/oa-reference-object/oa-ref.js +31 -0
- package/src/oa-reference-object/oa-ref.spec.js +56 -0
- package/src/oa-reference-object/resolve-oa-reference-object.d.ts +18 -0
- package/src/oa-reference-object/resolve-oa-reference-object.js +113 -0
- package/src/oa-reference-object/resolve-oa-reference-object.spec.js +233 -0
- package/src/oa-specification.d.ts +767 -0
- package/src/oa-specification.js +153 -0
- package/src/types.d.ts +4 -0
- package/src/utils/count-unicode.d.ts +11 -0
- package/src/utils/count-unicode.js +15 -0
- package/src/utils/index.d.ts +5 -0
- package/src/utils/index.js +5 -0
- package/src/utils/join-path.d.ts +6 -0
- package/src/utils/join-path.js +36 -0
- package/src/utils/join-path.spec.js +104 -0
- package/src/utils/normalize-path.d.ts +12 -0
- package/src/utils/normalize-path.js +22 -0
- package/src/utils/normalize-path.spec.js +56 -0
- package/src/utils/to-pascal-case.d.ts +6 -0
- package/src/utils/to-pascal-case.js +26 -0
- package/src/utils/to-pascal-case.spec.js +15 -0
- package/src/utils/to-spaced-json.d.ts +17 -0
- package/src/utils/to-spaced-json.js +27 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import {Optional} from './types.js';
|
|
2
|
+
import {Service, ServiceContainer} from '@e22m4u/js-service';
|
|
3
|
+
import {OADocumentScope, OADocumentScopeOptions} from './oa-document-scope.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
OADocumentObject,
|
|
7
|
+
OAOperationMethod,
|
|
8
|
+
OAOperationObject,
|
|
9
|
+
} from './oa-specification.js';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
OALinkObject,
|
|
13
|
+
OASchemaObject,
|
|
14
|
+
OAHeaderObject,
|
|
15
|
+
OAExampleObject,
|
|
16
|
+
OACallbackObject,
|
|
17
|
+
OAResponseObject,
|
|
18
|
+
OAPathItemObject,
|
|
19
|
+
OAReferenceObject,
|
|
20
|
+
OAParameterObject,
|
|
21
|
+
OARequestBodyObject,
|
|
22
|
+
OASecuritySchemeObject,
|
|
23
|
+
} from './oa-specification.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Component type.
|
|
27
|
+
*/
|
|
28
|
+
export declare const OAComponentType: {
|
|
29
|
+
SCHEMA: 'schema';
|
|
30
|
+
RESPONSE: 'response';
|
|
31
|
+
PARAMETER: 'parameter';
|
|
32
|
+
EXAMPLE: 'example';
|
|
33
|
+
REQUEST_BODY: 'requestBody';
|
|
34
|
+
HEADER: 'header';
|
|
35
|
+
SECURITY_SCHEME: 'securityScheme';
|
|
36
|
+
LINK: 'link';
|
|
37
|
+
CALLBACK: 'callback';
|
|
38
|
+
PATH_ITEM: 'pathItem';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type OAComponentType =
|
|
42
|
+
(typeof OAComponentType)[keyof typeof OAComponentType];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Component types.
|
|
46
|
+
*/
|
|
47
|
+
export declare const OA_COMPONENT_TYPES: OAComponentType[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Component type to components key map.
|
|
51
|
+
*/
|
|
52
|
+
export declare const OA_COMPONENT_TYPE_TO_COMPONENTS_KEY_MAP: {
|
|
53
|
+
[OAComponentType.SCHEMA]: 'schemas';
|
|
54
|
+
[OAComponentType.RESPONSE]: 'responses';
|
|
55
|
+
[OAComponentType.PARAMETER]: 'parameters';
|
|
56
|
+
[OAComponentType.EXAMPLE]: 'examples';
|
|
57
|
+
[OAComponentType.REQUEST_BODY]: 'requestBodies';
|
|
58
|
+
[OAComponentType.HEADER]: 'headers';
|
|
59
|
+
[OAComponentType.SECURITY_SCHEME]: 'securitySchemes';
|
|
60
|
+
[OAComponentType.LINK]: 'links';
|
|
61
|
+
[OAComponentType.CALLBACK]: 'callbacks';
|
|
62
|
+
[OAComponentType.PATH_ITEM]: 'pathItems';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Schema component definition.
|
|
67
|
+
*/
|
|
68
|
+
export type OASchemaComponentDefinition = {
|
|
69
|
+
name: string;
|
|
70
|
+
schema: OASchemaObject;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Response component definition.
|
|
75
|
+
*/
|
|
76
|
+
export type OAResponseComponentDefinition = {
|
|
77
|
+
name: string;
|
|
78
|
+
response: OAResponseObject | OAReferenceObject;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Parameter component definition.
|
|
83
|
+
*/
|
|
84
|
+
export type OAParameterComponentDefinition = {
|
|
85
|
+
name: string;
|
|
86
|
+
parameter: OAParameterObject | OAReferenceObject;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Example component definition.
|
|
91
|
+
*/
|
|
92
|
+
export type OAExampleComponentDefinition = {
|
|
93
|
+
name: string;
|
|
94
|
+
example: OAExampleObject | OAReferenceObject;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Request body component definition.
|
|
99
|
+
*/
|
|
100
|
+
export type OARequestBodyComponentDefinition = {
|
|
101
|
+
name: string;
|
|
102
|
+
requestBody: OARequestBodyObject | OAReferenceObject;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Header component definition.
|
|
107
|
+
*/
|
|
108
|
+
export type OAHeaderComponentDefinition = {
|
|
109
|
+
name: string;
|
|
110
|
+
header: OAHeaderObject | OAReferenceObject;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Security scheme component definition.
|
|
115
|
+
*/
|
|
116
|
+
export type OASecuritySchemeComponentDefinition = {
|
|
117
|
+
name: string;
|
|
118
|
+
securityScheme: OASecuritySchemeObject | OAReferenceObject;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Link component definition.
|
|
123
|
+
*/
|
|
124
|
+
export type OALinkComponentDefinition = {
|
|
125
|
+
name: string;
|
|
126
|
+
link: OALinkObject | OAReferenceObject;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Callback component definition.
|
|
131
|
+
*/
|
|
132
|
+
export type OACallbackComponentDefinition = {
|
|
133
|
+
name: string;
|
|
134
|
+
callback: OACallbackObject | OAReferenceObject;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Path item component definition.
|
|
139
|
+
*/
|
|
140
|
+
export type OAPathItemComponentDefinition = {
|
|
141
|
+
name: string;
|
|
142
|
+
pathItem: OAPathItemObject | OAReferenceObject;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Operation definition.
|
|
147
|
+
*/
|
|
148
|
+
export type OAOperationDefinition = {
|
|
149
|
+
path: string;
|
|
150
|
+
method: OAOperationMethod;
|
|
151
|
+
operation: OAOperationObject;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Document input.
|
|
156
|
+
*/
|
|
157
|
+
export type OADocumentInput = Optional<OADocumentObject, 'openapi' | 'info'>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Document builder.
|
|
161
|
+
*/
|
|
162
|
+
export declare class OADocumentBuilder extends Service {
|
|
163
|
+
/**
|
|
164
|
+
* Constructor.
|
|
165
|
+
*
|
|
166
|
+
* @param container
|
|
167
|
+
* @param document
|
|
168
|
+
*/
|
|
169
|
+
constructor(container: ServiceContainer, document?: OADocumentInput);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Constructor.
|
|
173
|
+
*
|
|
174
|
+
* @param document
|
|
175
|
+
*/
|
|
176
|
+
constructor(document?: OADocumentInput);
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Constructor.
|
|
180
|
+
*
|
|
181
|
+
* @param containerOrDocument
|
|
182
|
+
* @param document
|
|
183
|
+
*/
|
|
184
|
+
constructor(
|
|
185
|
+
containerOrDocument?: ServiceContainer | OADocumentInput,
|
|
186
|
+
document?: OADocumentInput,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Define component.
|
|
191
|
+
*
|
|
192
|
+
* @param type
|
|
193
|
+
* @param definition
|
|
194
|
+
*/
|
|
195
|
+
defineComponent(type: OAComponentType, definition: object): this;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Has component.
|
|
199
|
+
*
|
|
200
|
+
* @param type
|
|
201
|
+
* @param name
|
|
202
|
+
*/
|
|
203
|
+
hasComponent(type: OAComponentType, name: string): boolean;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get component.
|
|
207
|
+
*
|
|
208
|
+
* @param type
|
|
209
|
+
* @param name
|
|
210
|
+
*/
|
|
211
|
+
getComponent<T = any>(type: OAComponentType, name: string): T;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Define schema component.
|
|
215
|
+
*
|
|
216
|
+
* @param schemaDef
|
|
217
|
+
*/
|
|
218
|
+
defineSchemaComponent(schemaDef: OASchemaComponentDefinition): this;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Define response component.
|
|
222
|
+
*
|
|
223
|
+
* @param responseDef
|
|
224
|
+
*/
|
|
225
|
+
defineResponseComponent(responseDef: OAResponseComponentDefinition): this;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Define parameter component.
|
|
229
|
+
*
|
|
230
|
+
* @param parameterDef
|
|
231
|
+
*/
|
|
232
|
+
defineParameterComponent(parameterDef: OAParameterComponentDefinition): this;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Define example component.
|
|
236
|
+
*
|
|
237
|
+
* @param exampleDef
|
|
238
|
+
*/
|
|
239
|
+
defineExampleComponent(exampleDef: OAExampleComponentDefinition): this;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Define request body component.
|
|
243
|
+
*
|
|
244
|
+
* @param requestBodyDef
|
|
245
|
+
*/
|
|
246
|
+
defineRequestBodyComponent(
|
|
247
|
+
requestBodyDef: OARequestBodyComponentDefinition,
|
|
248
|
+
): this;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Define header component.
|
|
252
|
+
*
|
|
253
|
+
* @param headerDef
|
|
254
|
+
*/
|
|
255
|
+
defineHeaderComponent(headerDef: OAHeaderComponentDefinition): this;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Define security scheme component.
|
|
259
|
+
*
|
|
260
|
+
* @param securitySchemeDef
|
|
261
|
+
*/
|
|
262
|
+
defineSecuritySchemeComponent(
|
|
263
|
+
securitySchemeDef: OASecuritySchemeComponentDefinition,
|
|
264
|
+
): this;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Define link component.
|
|
268
|
+
*
|
|
269
|
+
* @param linkDef
|
|
270
|
+
*/
|
|
271
|
+
defineLinkComponent(linkDef: OALinkComponentDefinition): this;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Define callback component.
|
|
275
|
+
*
|
|
276
|
+
* @param callbackDef
|
|
277
|
+
*/
|
|
278
|
+
defineCallbackComponent(callbackDef: OACallbackComponentDefinition): this;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Define path item component.
|
|
282
|
+
*
|
|
283
|
+
* @param pathItemDef
|
|
284
|
+
*/
|
|
285
|
+
definePathItemComponent(pathItemDef: OAPathItemComponentDefinition): this;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Define operation.
|
|
289
|
+
*
|
|
290
|
+
* @param operationDef
|
|
291
|
+
*/
|
|
292
|
+
defineOperation(operationDef: OAOperationDefinition): this;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Create scope.
|
|
296
|
+
*
|
|
297
|
+
* @param options
|
|
298
|
+
*/
|
|
299
|
+
createScope(options?: OADocumentScopeOptions): OADocumentScope;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Build.
|
|
303
|
+
*/
|
|
304
|
+
build(): OADocumentObject;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Build JSON.
|
|
308
|
+
*
|
|
309
|
+
* @param space
|
|
310
|
+
*/
|
|
311
|
+
buildJson(space?: string | number): string;
|
|
312
|
+
}
|