@goast/core 0.7.0 → 0.7.1
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/dist/src/ast/node.d.ts +43 -0
- package/dist/src/ast/node.js +29 -0
- package/dist/src/codegen/config.d.ts +9 -0
- package/dist/src/codegen/config.js +4 -0
- package/dist/src/codegen/endpoints-generator.d.ts +32 -0
- package/dist/src/codegen/endpoints-generator.js +19 -0
- package/dist/src/codegen/generator.d.ts +108 -0
- package/dist/src/codegen/generator.js +103 -0
- package/dist/src/codegen/internal-utils.d.ts +8 -0
- package/dist/src/codegen/internal-utils.js +8 -0
- package/dist/src/codegen/schemas-generator.d.ts +33 -0
- package/dist/src/codegen/schemas-generator.js +20 -0
- package/dist/src/codegen/services-generator.d.ts +24 -0
- package/dist/src/codegen/services-generator.js +11 -0
- package/dist/src/codegen/types.d.ts +56 -0
- package/dist/src/collect/collector.d.ts +8 -0
- package/dist/src/collect/collector.js +8 -0
- package/dist/src/collect/helpers.d.ts +16 -0
- package/dist/src/collect/helpers.js +16 -0
- package/dist/src/collect/types.d.ts +28 -0
- package/dist/src/internal-utils.d.ts +7 -0
- package/dist/src/internal-utils.js +7 -0
- package/dist/src/parse/deref-proxy.d.ts +19 -0
- package/dist/src/parse/deref-proxy.js +19 -0
- package/dist/src/parse/openapi-types.d.ts +168 -0
- package/dist/src/parse/parser.d.ts +38 -0
- package/dist/src/parse/parser.js +38 -0
- package/dist/src/parse/types.d.ts +37 -0
- package/dist/src/parse/types.js +4 -0
- package/dist/src/transform/api-types.d.ts +408 -0
- package/dist/src/transform/helpers.d.ts +73 -0
- package/dist/src/transform/helpers.js +73 -0
- package/dist/src/transform/transform-document.d.ts +7 -0
- package/dist/src/transform/transform-document.js +7 -0
- package/dist/src/transform/transform-endpoint.d.ts +8 -0
- package/dist/src/transform/transform-endpoint.js +8 -0
- package/dist/src/transform/transform-schema.d.ts +10 -0
- package/dist/src/transform/transform-schema.js +10 -0
- package/dist/src/transform/transformer.d.ts +7 -0
- package/dist/src/transform/transformer.js +7 -0
- package/dist/src/transform/types.d.ts +61 -0
- package/dist/src/transform/types.js +4 -0
- package/dist/src/utils/action-provider.d.ts +38 -0
- package/dist/src/utils/action-provider.js +38 -0
- package/dist/src/utils/api-data.utils.d.ts +9 -0
- package/dist/src/utils/api-data.utils.js +9 -0
- package/dist/src/utils/array.utils.d.ts +7 -0
- package/dist/src/utils/array.utils.js +7 -0
- package/dist/src/utils/asset-manager.d.ts +22 -0
- package/dist/src/utils/asset-manager.js +22 -0
- package/dist/src/utils/class.utils.d.ts +22 -0
- package/dist/src/utils/class.utils.js +22 -0
- package/dist/src/utils/common.utils.d.ts +81 -0
- package/dist/src/utils/common.utils.js +81 -0
- package/dist/src/utils/condition.d.ts +22 -0
- package/dist/src/utils/endpoint.utils.d.ts +12 -0
- package/dist/src/utils/endpoint.utils.js +12 -0
- package/dist/src/utils/error.utils.d.ts +6 -0
- package/dist/src/utils/error.utils.js +6 -0
- package/dist/src/utils/factory.d.ts +45 -0
- package/dist/src/utils/factory.js +45 -0
- package/dist/src/utils/file-system.utils.d.ts +37 -0
- package/dist/src/utils/file-system.utils.js +20 -0
- package/dist/src/utils/generator.utils.d.ts +7 -0
- package/dist/src/utils/generator.utils.js +7 -0
- package/dist/src/utils/object.utils.d.ts +16 -0
- package/dist/src/utils/object.utils.js +16 -0
- package/dist/src/utils/schema-factory.d.ts +197 -0
- package/dist/src/utils/schema-factory.js +146 -0
- package/dist/src/utils/schema.utils.d.ts +15 -0
- package/dist/src/utils/schema.utils.js +15 -0
- package/dist/src/utils/source-builder.d.ts +103 -0
- package/dist/src/utils/source-builder.js +58 -0
- package/dist/src/utils/string-builder/string-builder.d.ts +24 -0
- package/dist/src/utils/string-builder/string-builder.js +11 -0
- package/dist/src/utils/string-builder/utils.d.ts +68 -0
- package/dist/src/utils/string-builder/utils.js +33 -0
- package/dist/src/utils/string.utils.d.ts +78 -0
- package/dist/src/utils/string.utils.js +64 -0
- package/dist/src/utils/string.utils.types.d.ts +34 -0
- package/dist/src/utils/type.utils.d.ts +132 -0
- package/dist/src/utils/type.utils.js +19 -0
- package/dist/src/utils/yaml-info.d.ts +35 -0
- package/dist/src/utils/yaml-info.js +25 -0
- package/package.json +1 -1
|
@@ -1,78 +1,301 @@
|
|
|
1
1
|
import type { KnownOpenApiParameterTarget, OpenApiDocument, OpenApiHeader, OpenApiHttpMethod, OpenApiMediaType, OpenApiOperation, OpenApiParameter, OpenApiPathItem, OpenApiRequestBody, OpenApiResponse, OpenApiSchema, OpenApiTag } from '../parse/openapi-types.ts';
|
|
2
2
|
import type { Deref, DerefSource } from '../parse/types.ts';
|
|
3
3
|
import type { OptionalProperties } from '../utils/type.utils.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The normalized result of transforming OpenAPI documents. Every generator works from this model.
|
|
6
|
+
* @see transformOpenApi
|
|
7
|
+
*/
|
|
4
8
|
export type ApiData = {
|
|
9
|
+
/**
|
|
10
|
+
* The parsed OpenAPI documents that the model was transformed from.
|
|
11
|
+
*/
|
|
5
12
|
documents: Deref<OpenApiDocument>[];
|
|
13
|
+
/**
|
|
14
|
+
* The services: one per document tag, plus implicit services for operation tags that no document declares.
|
|
15
|
+
*/
|
|
6
16
|
services: ApiService[];
|
|
17
|
+
/**
|
|
18
|
+
* Every operation of every path across all documents.
|
|
19
|
+
*/
|
|
7
20
|
endpoints: ApiEndpoint[];
|
|
21
|
+
/**
|
|
22
|
+
* Every schema reached from the documents, including inline and nested schemas.
|
|
23
|
+
*/
|
|
8
24
|
schemas: ApiSchema[];
|
|
9
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* The source information of a transformed entry: where its OpenAPI object is located, and the object itself.
|
|
28
|
+
* @template T The OpenAPI object type the entry was transformed from.
|
|
29
|
+
*/
|
|
10
30
|
export type ApiComponentSource<T> = DerefSource<T> & {
|
|
31
|
+
/**
|
|
32
|
+
* The parsed OpenAPI object that the entry was built from.
|
|
33
|
+
*/
|
|
11
34
|
component: Deref<T>;
|
|
12
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Maps an OpenAPI object type to the model type it is transformed into, or to `undefined` for types that are not
|
|
38
|
+
* modelled.
|
|
39
|
+
* @template T The OpenAPI object type.
|
|
40
|
+
*/
|
|
13
41
|
export type Transformed<T> = T extends OpenApiTag ? ApiService : T extends OpenApiPathItem ? ApiPath : T extends OpenApiParameter ? ApiParameter : T extends OpenApiRequestBody ? ApiRequestBody : T extends OpenApiResponse ? ApiResponse : T extends OpenApiMediaType ? ApiContent : T extends OpenApiHeader ? ApiHeader : T extends OpenApiSchema ? ApiSchema : undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The fields that every model entry originating from an OpenAPI object has.
|
|
44
|
+
* @template T The OpenAPI object type the entry was transformed from.
|
|
45
|
+
*/
|
|
14
46
|
export type ApiComponent<T> = {
|
|
47
|
+
/**
|
|
48
|
+
* A generated identifier such as `schema-3`. It is unique within one transform run, but it depends on traversal
|
|
49
|
+
* order and is not taken from the spec.
|
|
50
|
+
*/
|
|
15
51
|
id: string;
|
|
52
|
+
/**
|
|
53
|
+
* The source location of the OpenAPI object, including the parsed object itself as `component`.
|
|
54
|
+
*/
|
|
16
55
|
$src: ApiComponentSource<T>;
|
|
56
|
+
/**
|
|
57
|
+
* The entry that the source object refers to when it is a `$ref`, or `undefined` otherwise. Fields that the
|
|
58
|
+
* referencing object does not set are read from the target, except `title`.
|
|
59
|
+
*/
|
|
17
60
|
$ref: Transformed<T> | undefined;
|
|
18
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* An HTTP method, in lowercase, as it appears as a key of an OpenAPI path item.
|
|
64
|
+
* @see ApiPath
|
|
65
|
+
*/
|
|
19
66
|
export type ApiMethod = OpenApiHttpMethod;
|
|
67
|
+
/**
|
|
68
|
+
* Where a parameter is sent, taken verbatim from the `in` keyword, such as `path`, `query`, `header` or `cookie`.
|
|
69
|
+
* @see ApiParameter
|
|
70
|
+
*/
|
|
20
71
|
export type ApiParameterTarget = KnownOpenApiParameterTarget;
|
|
72
|
+
/**
|
|
73
|
+
* The component part of an `ApiService`. `$src` is absent for services that were created from operation tags without
|
|
74
|
+
* a matching document tag.
|
|
75
|
+
* @see ApiService
|
|
76
|
+
*/
|
|
21
77
|
export type ApiServiceComponent = OptionalProperties<ApiComponent<OpenApiTag>, '$src'>;
|
|
78
|
+
/**
|
|
79
|
+
* A named group of endpoints, typically one per OpenAPI tag.
|
|
80
|
+
* @see ApiEndpoint
|
|
81
|
+
*/
|
|
22
82
|
export type ApiService = ApiServiceComponent & {
|
|
83
|
+
/**
|
|
84
|
+
* The name of the service: the tag's `name`, or a generated identifier if the tag has none. Operations without tags
|
|
85
|
+
* are grouped under a generated name.
|
|
86
|
+
*/
|
|
23
87
|
name: string;
|
|
88
|
+
/**
|
|
89
|
+
* The `description` of the tag, or `undefined` for a service that was created implicitly.
|
|
90
|
+
*/
|
|
24
91
|
description: string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* The endpoints of this service. An operation with several tags appears in each of their services.
|
|
94
|
+
*/
|
|
25
95
|
endpoints: ApiEndpoint[];
|
|
26
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* The component fields of an `ApiPath`, built from an OpenAPI path item.
|
|
99
|
+
* @see ApiPath
|
|
100
|
+
*/
|
|
27
101
|
export type ApiPathComponent = ApiComponent<OpenApiPathItem>;
|
|
102
|
+
/**
|
|
103
|
+
* A path template, such as `/pets/{petId}`, with the parameters declared on it. One `ApiPath` is shared by all the
|
|
104
|
+
* operations of that path, which are stored under the method names (`get`, `post`, ...) that the path defines.
|
|
105
|
+
* @see ApiEndpoint
|
|
106
|
+
*/
|
|
28
107
|
export type ApiPath = ApiPathComponent & {
|
|
108
|
+
/**
|
|
109
|
+
* The `summary` of the path item, or `undefined`.
|
|
110
|
+
*/
|
|
29
111
|
summary: string | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* The `description` of the path item, or `undefined`.
|
|
114
|
+
*/
|
|
30
115
|
description: string | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* The path template exactly as it is written in the `paths` object.
|
|
118
|
+
*/
|
|
31
119
|
path: string;
|
|
120
|
+
/**
|
|
121
|
+
* The parameters declared on the path item. They apply to all its operations. Each endpoint's `parameters` merges
|
|
122
|
+
* them with the operation's own parameters.
|
|
123
|
+
*/
|
|
32
124
|
parameters: ApiParameter[];
|
|
33
125
|
} & {
|
|
34
126
|
[K in ApiMethod]: ApiEndpoint | undefined;
|
|
35
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* The component fields of an `ApiEndpoint`, built from an OpenAPI operation. `$ref` is always `undefined`, because
|
|
130
|
+
* operations cannot be referenced.
|
|
131
|
+
* @see ApiEndpoint
|
|
132
|
+
*/
|
|
36
133
|
export type ApiEndpointComponent = ApiComponent<OpenApiOperation>;
|
|
134
|
+
/**
|
|
135
|
+
* A single operation: one HTTP method on one path. Generators turn endpoints into client methods or handlers.
|
|
136
|
+
* @see ApiPath
|
|
137
|
+
*/
|
|
37
138
|
export type ApiEndpoint = ApiEndpointComponent & {
|
|
139
|
+
/**
|
|
140
|
+
* The `operationId` of the operation if it has one, otherwise a name built from the method and path, such as
|
|
141
|
+
* `get_pets_:id`.
|
|
142
|
+
*/
|
|
38
143
|
name: string;
|
|
144
|
+
/**
|
|
145
|
+
* The path template of the operation, such as `/pets/{petId}`.
|
|
146
|
+
*/
|
|
39
147
|
path: string;
|
|
148
|
+
/**
|
|
149
|
+
* The path entry this operation belongs to, which also holds the other operations of the same path.
|
|
150
|
+
*/
|
|
40
151
|
pathInfo: ApiPath;
|
|
152
|
+
/**
|
|
153
|
+
* The HTTP method of the operation.
|
|
154
|
+
*/
|
|
41
155
|
method: ApiMethod;
|
|
156
|
+
/**
|
|
157
|
+
* The `summary` of the operation, or `undefined`.
|
|
158
|
+
*/
|
|
42
159
|
summary: string | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* The `description` of the operation, or `undefined`.
|
|
162
|
+
*/
|
|
43
163
|
description: string | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* The effective parameters: the path item's parameters merged with the operation's own. An operation parameter
|
|
166
|
+
* replaces a path-level parameter with the same name, matched by name only.
|
|
167
|
+
*/
|
|
44
168
|
parameters: ApiParameter[];
|
|
169
|
+
/**
|
|
170
|
+
* Whether the operation is marked `deprecated`. Defaults to `false`.
|
|
171
|
+
*/
|
|
45
172
|
deprecated: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* The request body of an OpenAPI 3.x operation, or `undefined`. OpenAPI 2.0 body parameters are not converted into a
|
|
175
|
+
* request body; they stay in `parameters` with the target `body`.
|
|
176
|
+
*/
|
|
46
177
|
requestBody: ApiRequestBody | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* The responses of the operation, in the order they appear in the spec.
|
|
180
|
+
*/
|
|
47
181
|
responses: ApiResponse[];
|
|
182
|
+
/**
|
|
183
|
+
* The tags of the operation. Empty if it has none.
|
|
184
|
+
*/
|
|
48
185
|
tags: string[];
|
|
186
|
+
/**
|
|
187
|
+
* The `x-` extension fields of the operation, keyed without the `x-` prefix.
|
|
188
|
+
*/
|
|
49
189
|
custom: Record<string, unknown>;
|
|
50
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* The component fields of an `ApiParameter`, built from an OpenAPI parameter object.
|
|
193
|
+
* @see ApiParameter
|
|
194
|
+
*/
|
|
51
195
|
export type ApiParameterComponent = ApiComponent<OpenApiParameter>;
|
|
196
|
+
/**
|
|
197
|
+
* A parameter of an operation or path item, built from an OpenAPI parameter object. Response headers reuse this shape
|
|
198
|
+
* through `ApiHeader`.
|
|
199
|
+
* @see ApiEndpoint
|
|
200
|
+
*/
|
|
52
201
|
export type ApiParameter = ApiParameterComponent & {
|
|
202
|
+
/**
|
|
203
|
+
* The parameter name, exactly as the spec writes it. Names are case-sensitive.
|
|
204
|
+
*/
|
|
53
205
|
name: string;
|
|
206
|
+
/**
|
|
207
|
+
* Where the parameter is sent, taken from the `in` keyword.
|
|
208
|
+
* @see ApiParameterTarget
|
|
209
|
+
*/
|
|
54
210
|
target: ApiParameterTarget;
|
|
211
|
+
/**
|
|
212
|
+
* The `description` of the parameter, or `undefined`.
|
|
213
|
+
*/
|
|
55
214
|
description: string | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Whether the parameter is required, from the `required` keyword and defaulting to `false`. Path parameters are not
|
|
217
|
+
* forced to `true`, even though the spec requires them to be required.
|
|
218
|
+
*/
|
|
56
219
|
required: boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Whether the parameter is marked `deprecated`. Defaults to `false`.
|
|
222
|
+
*/
|
|
57
223
|
deprecated: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* The `allowEmptyValue` keyword as written, or `undefined` if absent. It is not defaulted.
|
|
226
|
+
*/
|
|
58
227
|
allowEmptyValue: boolean | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* The serialization `style` as written, such as `form` or `simple`, or `undefined` if absent.
|
|
230
|
+
*/
|
|
59
231
|
style: string | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* The `explode` keyword as written, or `undefined` if absent. Its default depends on `style`, which is not applied.
|
|
234
|
+
*/
|
|
60
235
|
explode: boolean | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* The `allowReserved` keyword as written, or `undefined` if absent.
|
|
238
|
+
*/
|
|
61
239
|
allowReserved: boolean | undefined;
|
|
240
|
+
/**
|
|
241
|
+
* The transformed `schema` of the parameter, or `undefined` if it has none. OpenAPI 2.0 non-body parameters declare
|
|
242
|
+
* their type inline rather than in `schema`, so this is `undefined` for them.
|
|
243
|
+
*/
|
|
62
244
|
schema: ApiSchema | undefined;
|
|
63
245
|
};
|
|
246
|
+
/**
|
|
247
|
+
* The component fields of an `ApiRequestBody`, built from an OpenAPI 3.x request body object.
|
|
248
|
+
* @see ApiRequestBody
|
|
249
|
+
*/
|
|
64
250
|
export type ApiRequestBodyComponent = ApiComponent<OpenApiRequestBody>;
|
|
251
|
+
/**
|
|
252
|
+
* The request body of an operation. OpenAPI 2.0 has no request body object; its body parameter is an `ApiParameter`.
|
|
253
|
+
* @see ApiEndpoint
|
|
254
|
+
*/
|
|
65
255
|
export type ApiRequestBody = ApiRequestBodyComponent & {
|
|
256
|
+
/**
|
|
257
|
+
* The `description` of the request body, or `undefined`.
|
|
258
|
+
*/
|
|
66
259
|
description: string | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* One entry per media type in the `content` map, in the order the spec lists them.
|
|
262
|
+
*/
|
|
67
263
|
content: ApiContent[];
|
|
264
|
+
/**
|
|
265
|
+
* Whether the body is required, from the `required` keyword and defaulting to `false`.
|
|
266
|
+
*/
|
|
68
267
|
required: boolean;
|
|
69
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* The component fields of an `ApiContent`, built from an OpenAPI media type object.
|
|
271
|
+
* @see ApiContent
|
|
272
|
+
*/
|
|
70
273
|
export type ApiContentComponent = ApiComponent<OpenApiMediaType>;
|
|
274
|
+
/**
|
|
275
|
+
* A media type entry of a request body or response, such as `application/json`, with the schema of its payload.
|
|
276
|
+
* @see ApiRequestBody
|
|
277
|
+
* @see ApiResponse
|
|
278
|
+
*/
|
|
71
279
|
export type ApiContent = ApiContentComponent & {
|
|
280
|
+
/**
|
|
281
|
+
* The media type key from the `content` map, such as `application/json`.
|
|
282
|
+
*/
|
|
72
283
|
type: string;
|
|
284
|
+
/**
|
|
285
|
+
* The transformed schema of the payload, or `undefined` if the media type has none.
|
|
286
|
+
*/
|
|
73
287
|
schema: ApiSchema | undefined;
|
|
74
288
|
};
|
|
289
|
+
/**
|
|
290
|
+
* The component fields of an `ApiResponse`, built from an OpenAPI response object.
|
|
291
|
+
* @see ApiResponse
|
|
292
|
+
*/
|
|
75
293
|
export type ApiExampleComponent = ApiComponent<OpenApiResponse>;
|
|
294
|
+
/**
|
|
295
|
+
* A response of an operation, one per key of its `responses` object. The status is kept both as written (`statusKey`)
|
|
296
|
+
* and as a number (`statusCode`).
|
|
297
|
+
* @see ApiEndpoint
|
|
298
|
+
*/
|
|
76
299
|
export type ApiResponse = ApiExampleComponent & {
|
|
77
300
|
/**
|
|
78
301
|
* The response key exactly as the spec wrote it: an exact code (`'200'`), a range (`'2XX'`), or
|
|
@@ -83,49 +306,179 @@ export type ApiResponse = ApiExampleComponent & {
|
|
|
83
306
|
* `undefined`. Anything that has to *emit* a status code needs this one.
|
|
84
307
|
*/
|
|
85
308
|
statusKey: string;
|
|
309
|
+
/**
|
|
310
|
+
* The numeric status code, or `undefined` if the key is not a plain number: `default`, a range such as `2XX`, or `0`.
|
|
311
|
+
*/
|
|
86
312
|
statusCode: number | undefined;
|
|
313
|
+
/**
|
|
314
|
+
* The `description` of the response, or `undefined`.
|
|
315
|
+
*/
|
|
87
316
|
description: string | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* The response headers, one entry per header name. OpenAPI 2.0 headers are schema-like objects and are read as such.
|
|
319
|
+
*/
|
|
88
320
|
headers: ApiHeader[];
|
|
321
|
+
/**
|
|
322
|
+
* The media types of the response, from its `content` map. OpenAPI 2.0 responses declare their payload schema at
|
|
323
|
+
* response level, which is not read, so this is empty for 2.0 responses.
|
|
324
|
+
*/
|
|
89
325
|
contentOptions: ApiContent[];
|
|
90
326
|
};
|
|
327
|
+
/**
|
|
328
|
+
* The component fields of an `ApiHeader`. Its `$ref` points to the referenced `ApiHeader`.
|
|
329
|
+
* @see ApiHeader
|
|
330
|
+
*/
|
|
91
331
|
export type ApiHeaderComponent = Omit<ApiComponent<OpenApiHeader> | ApiComponent<OpenApiSchema>, '$ref'> & {
|
|
332
|
+
/**
|
|
333
|
+
* The referenced header, if the source object is a `$ref`.
|
|
334
|
+
*/
|
|
92
335
|
$ref: ApiHeader | undefined;
|
|
93
336
|
};
|
|
337
|
+
/**
|
|
338
|
+
* A response header. An OpenAPI 3.x header object is read as written. An OpenAPI 2.0 header is a schema-like object,
|
|
339
|
+
* so it is treated as neither required nor deprecated, and its `schema` is the header object itself.
|
|
340
|
+
* @see ApiResponse
|
|
341
|
+
*/
|
|
94
342
|
export type ApiHeader = ApiHeaderComponent & Omit<ApiParameter, 'target'>;
|
|
343
|
+
/**
|
|
344
|
+
* The name of a JSON Schema type, such as `string` or `object`. The union includes `string`, so any other name is
|
|
345
|
+
* accepted as well.
|
|
346
|
+
*/
|
|
95
347
|
export type ApiSchemaType = 'string' | 'number' | 'integer' | 'array' | 'boolean' | 'null' | 'object' | string;
|
|
348
|
+
/**
|
|
349
|
+
* The shape of an `ApiSchema`, which selects the kind-specific fields in `ApiSchemaExtensions`. `multi-type` covers
|
|
350
|
+
* type arrays with more than one non-null member, `combined` covers `allOf`/`anyOf` without properties, and `unknown`
|
|
351
|
+
* covers schemas without a recognised type.
|
|
352
|
+
* @see ApiSchemaExtensions
|
|
353
|
+
*/
|
|
96
354
|
export type ApiSchemaKind = 'oneOf' | 'multi-type' | 'string' | 'number' | 'integer' | 'array' | 'boolean' | 'null' | 'object' | 'combined' | 'unknown';
|
|
355
|
+
/**
|
|
356
|
+
* Whether a schema applies to requests, responses or both, derived from its `readOnly` and `writeOnly` flags. `all` is
|
|
357
|
+
* used when neither flag is set, and `none` when both are set.
|
|
358
|
+
*/
|
|
97
359
|
export type ApiSchemaAccessibility = 'all' | 'readOnly' | 'writeOnly' | 'none';
|
|
360
|
+
/**
|
|
361
|
+
* A named property of an object schema.
|
|
362
|
+
* @see ApiSchemaExtensions
|
|
363
|
+
*/
|
|
98
364
|
export type ApiSchemaProperty = {
|
|
365
|
+
/**
|
|
366
|
+
* The property name, as the key in the `properties` keyword.
|
|
367
|
+
*/
|
|
99
368
|
name: string;
|
|
369
|
+
/**
|
|
370
|
+
* The transformed schema of the property.
|
|
371
|
+
*/
|
|
100
372
|
schema: ApiSchema;
|
|
101
373
|
};
|
|
374
|
+
/**
|
|
375
|
+
* The `discriminator` of a schema, which names the property that selects a subtype and maps its values to schemas.
|
|
376
|
+
* @see ApiSchemaBase
|
|
377
|
+
*/
|
|
102
378
|
export type ApiSchemaDiscriminator = {
|
|
379
|
+
/**
|
|
380
|
+
* The name of the discriminator property, from `discriminator.propertyName`.
|
|
381
|
+
*/
|
|
103
382
|
propertyName: string;
|
|
383
|
+
/**
|
|
384
|
+
* The schemas that the discriminator values map to. It starts from the explicit `discriminator.mapping` and also
|
|
385
|
+
* receives the named subtypes that inherit from this schema through `allOf`.
|
|
386
|
+
*/
|
|
104
387
|
mapping: Record<string, ApiSchema>;
|
|
105
388
|
};
|
|
389
|
+
/**
|
|
390
|
+
* The component fields of an `ApiSchema`, built from an OpenAPI schema object.
|
|
391
|
+
* @see ApiSchema
|
|
392
|
+
*/
|
|
106
393
|
export type ApiSchemaComponent = ApiComponent<OpenApiSchema>;
|
|
394
|
+
/**
|
|
395
|
+
* The fields that every `ApiSchema` has, whatever its kind. The fields that depend on the kind are in
|
|
396
|
+
* `ApiSchemaExtensions`.
|
|
397
|
+
* @see ApiSchema
|
|
398
|
+
*/
|
|
107
399
|
export type ApiSchemaBase = ApiSchemaComponent & {
|
|
400
|
+
/**
|
|
401
|
+
* The name of the schema: its `title` if set, otherwise a name derived from its place in the document. See
|
|
402
|
+
* `isNameGenerated`.
|
|
403
|
+
*/
|
|
108
404
|
name: string;
|
|
405
|
+
/**
|
|
406
|
+
* Whether `name` was synthesized from the location or the id of the schema, rather than taken from a `title` or from
|
|
407
|
+
* a component or `definitions` key.
|
|
408
|
+
*/
|
|
109
409
|
isNameGenerated: boolean;
|
|
410
|
+
/**
|
|
411
|
+
* The `description` of the schema, or `undefined`.
|
|
412
|
+
*/
|
|
110
413
|
description: string | undefined;
|
|
414
|
+
/**
|
|
415
|
+
* Whether the schema is marked `deprecated`. Defaults to `false`.
|
|
416
|
+
*/
|
|
111
417
|
deprecated: boolean;
|
|
418
|
+
/**
|
|
419
|
+
* Whether the schema applies to requests, responses or both, derived from `readOnly` and `writeOnly`.
|
|
420
|
+
*/
|
|
112
421
|
accessibility: ApiSchemaAccessibility;
|
|
422
|
+
/**
|
|
423
|
+
* The allowed values from the `enum` keyword, as written, or `undefined`.
|
|
424
|
+
*/
|
|
113
425
|
enum: unknown[] | undefined;
|
|
426
|
+
/**
|
|
427
|
+
* The fixed value from the `const` keyword, as written, or `undefined`.
|
|
428
|
+
*/
|
|
114
429
|
const: unknown | undefined;
|
|
430
|
+
/**
|
|
431
|
+
* The `default` value as written, or `undefined`.
|
|
432
|
+
*/
|
|
115
433
|
default: unknown | undefined;
|
|
434
|
+
/**
|
|
435
|
+
* The `example` value as written, or `undefined`. The plural `examples` keyword is not read.
|
|
436
|
+
*/
|
|
116
437
|
example: unknown | undefined;
|
|
438
|
+
/**
|
|
439
|
+
* Whether `null` is an allowed value. This is set when the `type` keyword lists `null` (OpenAPI 3.1), when the
|
|
440
|
+
* kind is `null`, or when the OpenAPI 3.0 `nullable` flag is `true`.
|
|
441
|
+
*/
|
|
117
442
|
nullable: boolean;
|
|
443
|
+
/**
|
|
444
|
+
* The names of the properties that the `required` keyword lists. Empty if the keyword is absent.
|
|
445
|
+
*/
|
|
118
446
|
required: Set<string>;
|
|
447
|
+
/**
|
|
448
|
+
* The `x-` extension fields of the schema, keyed without the `x-` prefix.
|
|
449
|
+
*/
|
|
119
450
|
custom: Record<string, unknown>;
|
|
451
|
+
/**
|
|
452
|
+
* The transformed `not` schema, or `undefined`.
|
|
453
|
+
*/
|
|
120
454
|
not: ApiSchema | undefined;
|
|
455
|
+
/**
|
|
456
|
+
* The discriminator of the schema, or `undefined` if it has none.
|
|
457
|
+
*/
|
|
121
458
|
discriminator: ApiSchemaDiscriminator | undefined;
|
|
459
|
+
/**
|
|
460
|
+
* The base schemas that this schema extends, found through `allOf` or through a discriminator mapping. Each base
|
|
461
|
+
* has a `discriminator`.
|
|
462
|
+
*/
|
|
122
463
|
inheritedSchemas: (ApiSchema & {
|
|
123
464
|
discriminator: NonNullable<ApiSchema['discriminator']>;
|
|
124
465
|
})[];
|
|
125
466
|
};
|
|
467
|
+
/**
|
|
468
|
+
* A normalized schema: the base fields, plus the fields that belong to its kind. Every schema reached from the
|
|
469
|
+
* documents becomes one `ApiSchema`.
|
|
470
|
+
* @template T The kind of the schema. Defaults to every kind.
|
|
471
|
+
* @see ApiSchemaExtensions
|
|
472
|
+
*/
|
|
126
473
|
export type ApiSchema<T extends ApiSchemaKind = ApiSchemaKind> = ApiSchemaBase & ApiSchemaExtensions<T>;
|
|
127
474
|
type AdditionalCombinedSchemaProperties = {
|
|
475
|
+
/**
|
|
476
|
+
* The transformed `allOf` schemas, or an empty array if the keyword is absent.
|
|
477
|
+
*/
|
|
128
478
|
allOf: ApiSchema[];
|
|
479
|
+
/**
|
|
480
|
+
* The transformed `anyOf` schemas, or an empty array if the keyword is absent.
|
|
481
|
+
*/
|
|
129
482
|
anyOf: ApiSchema[];
|
|
130
483
|
};
|
|
131
484
|
type AdditionalArraySchemaProperties = {
|
|
@@ -135,25 +488,62 @@ type AdditionalArraySchemaProperties = {
|
|
|
135
488
|
* modelled, so `items` is `undefined` for them even though the OpenAPI schema has an `items` keyword.
|
|
136
489
|
*/
|
|
137
490
|
items: ApiSchema | undefined;
|
|
491
|
+
/**
|
|
492
|
+
* The `minItems` bound, or `undefined` if the keyword is absent.
|
|
493
|
+
*/
|
|
138
494
|
minItems: number | undefined;
|
|
495
|
+
/**
|
|
496
|
+
* The `maxItems` bound, or `undefined` if the keyword is absent.
|
|
497
|
+
*/
|
|
139
498
|
maxItems: number | undefined;
|
|
140
499
|
};
|
|
141
500
|
type AdditionalObjectSchemaProperties = {
|
|
501
|
+
/**
|
|
502
|
+
* The properties of the object, keyed by property name. Empty if the schema declares none.
|
|
503
|
+
*/
|
|
142
504
|
properties: Map<string, ApiSchemaProperty>;
|
|
505
|
+
/**
|
|
506
|
+
* The `additionalProperties` keyword: a boolean as written, the transformed schema, or `undefined` if absent.
|
|
507
|
+
*/
|
|
143
508
|
additionalProperties: boolean | undefined | ApiSchema;
|
|
144
509
|
} & AdditionalCombinedSchemaProperties;
|
|
145
510
|
type AdditionalNumberSchemaProperties = {
|
|
511
|
+
/**
|
|
512
|
+
* The `minimum` bound, or `undefined` if the keyword is absent.
|
|
513
|
+
*/
|
|
146
514
|
minimum: number | undefined;
|
|
515
|
+
/**
|
|
516
|
+
* The `maximum` bound, or `undefined` if the keyword is absent.
|
|
517
|
+
*/
|
|
147
518
|
maximum: number | undefined;
|
|
148
519
|
};
|
|
149
520
|
type AdditionalStringSchemaProperties = {
|
|
521
|
+
/**
|
|
522
|
+
* The regular expression from the `pattern` keyword, or `undefined` if the keyword is absent.
|
|
523
|
+
*/
|
|
150
524
|
pattern: string | undefined;
|
|
525
|
+
/**
|
|
526
|
+
* The `minLength` bound, or `undefined` if the keyword is absent.
|
|
527
|
+
*/
|
|
151
528
|
minLength: number | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* The `maxLength` bound, or `undefined` if the keyword is absent.
|
|
531
|
+
*/
|
|
152
532
|
maxLength: number | undefined;
|
|
153
533
|
};
|
|
154
534
|
type AdditionalPrimitiveSchemaProperties = {
|
|
535
|
+
/**
|
|
536
|
+
* The `format` keyword, such as `date-time`, or `undefined` if the keyword is absent.
|
|
537
|
+
*/
|
|
155
538
|
format: string | undefined;
|
|
156
539
|
};
|
|
540
|
+
/**
|
|
541
|
+
* The fields that belong to a schema of kind `T`, selected by its `kind`. For `oneOf` the alternatives are listed in
|
|
542
|
+
* `oneOf`, and for `multi-type` the member types are listed in `type`. The remaining fields hold the transformed values
|
|
543
|
+
* of the keywords with the same names.
|
|
544
|
+
* @template T The kind of the schema.
|
|
545
|
+
* @see ApiSchemaKind
|
|
546
|
+
*/
|
|
157
547
|
export type ApiSchemaExtensions<T extends ApiSchemaKind> = T extends 'oneOf' ? {
|
|
158
548
|
kind: 'oneOf';
|
|
159
549
|
oneOf: ApiSchema[];
|
|
@@ -183,26 +573,44 @@ export type ApiSchemaExtensions<T extends ApiSchemaKind> = T extends 'oneOf' ? {
|
|
|
183
573
|
} & AdditionalCombinedSchemaProperties : {
|
|
184
574
|
kind: 'unknown';
|
|
185
575
|
};
|
|
576
|
+
/**
|
|
577
|
+
* An `ApiSchema` narrowed to the kinds that can have `allOf` and `anyOf`: `combined`, `object` and `multi-type`.
|
|
578
|
+
*/
|
|
186
579
|
export type CombinedLikeApiSchema = ApiSchemaBase & {
|
|
187
580
|
kind: 'combined' | 'object' | 'multi-type';
|
|
188
581
|
type?: 'object' | string[];
|
|
189
582
|
} & AdditionalCombinedSchemaProperties;
|
|
583
|
+
/**
|
|
584
|
+
* An `ApiSchema` narrowed to the numeric kinds: `number`, `integer` and `multi-type`, with their bounds and format.
|
|
585
|
+
*/
|
|
190
586
|
export type NumberLikeApiSchema = ApiSchemaBase & {
|
|
191
587
|
kind: 'number' | 'integer' | 'multi-type';
|
|
192
588
|
type: 'number' | 'integer' | string[];
|
|
193
589
|
} & AdditionalNumberSchemaProperties & AdditionalPrimitiveSchemaProperties;
|
|
590
|
+
/**
|
|
591
|
+
* An `ApiSchema` narrowed to the array kinds: `array` and `multi-type`, with `items` and the item count bounds.
|
|
592
|
+
*/
|
|
194
593
|
export type ArrayLikeApiSchema = ApiSchemaBase & {
|
|
195
594
|
kind: 'array' | 'multi-type';
|
|
196
595
|
type: 'array' | string[];
|
|
197
596
|
} & AdditionalArraySchemaProperties;
|
|
597
|
+
/**
|
|
598
|
+
* An `ApiSchema` narrowed to the object kinds: `object` and `multi-type`, with `properties` and `additionalProperties`.
|
|
599
|
+
*/
|
|
198
600
|
export type ObjectLikeApiSchema = ApiSchemaBase & {
|
|
199
601
|
kind: 'object' | 'multi-type';
|
|
200
602
|
type: 'object' | string[];
|
|
201
603
|
} & AdditionalObjectSchemaProperties;
|
|
604
|
+
/**
|
|
605
|
+
* An `ApiSchema` narrowed to the string kinds: `string` and `multi-type`, with length bounds, `pattern` and `format`.
|
|
606
|
+
*/
|
|
202
607
|
export type StringLikeApiSchema = ApiSchemaBase & {
|
|
203
608
|
kind: 'string' | 'multi-type';
|
|
204
609
|
type: 'string' | string[];
|
|
205
610
|
} & AdditionalStringSchemaProperties & AdditionalPrimitiveSchemaProperties;
|
|
611
|
+
/**
|
|
612
|
+
* An `ApiSchema` narrowed to the scalar kinds: `string`, `number`, `integer`, `boolean`, `null` and `multi-type`.
|
|
613
|
+
*/
|
|
206
614
|
export type PrimitiveLikeApiSchema = ApiSchemaBase & {
|
|
207
615
|
kind: 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'multi-type';
|
|
208
616
|
type: 'string' | 'number' | 'integer' | 'boolean' | 'null' | string[];
|