@kubb/oas 3.0.0-alpha.3 → 3.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/{Oas-BEe7KZDj.d.cts → Oas-Br0yKhGF.d.cts} +3 -0
- package/dist/{Oas-BEe7KZDj.d.ts → Oas-Br0yKhGF.d.ts} +3 -0
- package/dist/chunk-JAZKMYLT.cjs +244 -0
- package/dist/chunk-JAZKMYLT.cjs.map +1 -0
- package/dist/chunk-PHE7X6W6.js +230 -0
- package/dist/chunk-PHE7X6W6.js.map +1 -0
- package/dist/index.cjs +37 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -432
- package/dist/index.d.ts +7 -432
- package/dist/index.js +4 -21
- package/dist/index.js.map +1 -1
- package/dist/infer.cjs +4 -0
- package/dist/infer.cjs.map +1 -0
- package/dist/infer.d.cts +380 -0
- package/dist/infer.d.ts +380 -0
- package/dist/infer.js +3 -0
- package/dist/infer.js.map +1 -0
- package/dist/parser.cjs +18 -18
- package/dist/parser.cjs.map +1 -1
- package/dist/parser.d.cts +3 -44
- package/dist/parser.d.ts +3 -44
- package/dist/parser.js +11 -18
- package/dist/parser.js.map +1 -1
- package/package.json +19 -12
- package/src/Oas.ts +69 -5
- package/src/index.ts +0 -2
- package/src/parser/index.ts +6 -52
- package/src/utils.ts +1 -49
- package/dist/chunk-7D7ASOLY.js +0 -242
- package/dist/chunk-7D7ASOLY.js.map +0 -1
- package/dist/chunk-UIWP4KHB.cjs +0 -242
- package/dist/chunk-UIWP4KHB.cjs.map +0 -1
- package/src/typings.d.ts +0 -51
package/dist/infer.d.ts
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { Call, Tuples, Objects, Booleans, Strings, Pipe, Fn } from 'hotscript';
|
|
2
|
+
import { Object as Object$1 } from 'ts-toolbelt';
|
|
3
|
+
import { JSONSchema, FromSchema } from 'json-schema-to-ts';
|
|
4
|
+
import * as OasTypes from 'oas/types';
|
|
5
|
+
|
|
6
|
+
type Checks$5 = {
|
|
7
|
+
AllOFf: {
|
|
8
|
+
allOf: any[];
|
|
9
|
+
};
|
|
10
|
+
Object: {
|
|
11
|
+
type: 'object';
|
|
12
|
+
properties: any;
|
|
13
|
+
};
|
|
14
|
+
Properties: {
|
|
15
|
+
properties: any;
|
|
16
|
+
};
|
|
17
|
+
PropertiesRequired: {
|
|
18
|
+
properties: Record<string, any>;
|
|
19
|
+
required: string[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type FixAdditionalPropertiesForAllOf<T> = T extends Checks$5['AllOFf'] ? Omit<T, 'allOf'> & {
|
|
23
|
+
allOf: Call<Tuples.Map<Objects.Omit<'additionalProperties'>>, T['allOf']>;
|
|
24
|
+
} : T;
|
|
25
|
+
type FixMissingAdditionalProperties<T> = T extends Checks$5['Object'] ? Omit<T, 'additionalProperties'> & {
|
|
26
|
+
additionalProperties: false;
|
|
27
|
+
} : T;
|
|
28
|
+
type FixMissingTypeObject<T> = T extends Checks$5['Properties'] ? T & {
|
|
29
|
+
type: 'object';
|
|
30
|
+
} : T;
|
|
31
|
+
type FixExtraRequiredFields<T> = T extends Checks$5['PropertiesRequired'] ? Omit<T, 'required'> & {
|
|
32
|
+
required: Call<Tuples.Filter<Booleans.Extends<keyof T['properties']>>, T['required']>;
|
|
33
|
+
} : T;
|
|
34
|
+
type FixJSONSchema<T> = FixAdditionalPropertiesForAllOf<FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>>;
|
|
35
|
+
type Mutable<Type> = FixJSONSchema<{
|
|
36
|
+
-readonly [Key in keyof Type]: Mutable<Type[Key]>;
|
|
37
|
+
}>;
|
|
38
|
+
type RefToPath<T extends string> = T extends `#/${infer Ref}` ? Call<Strings.Split<'/'>, Ref> : never;
|
|
39
|
+
type ResolveRef<TObj, TRef extends string> = {
|
|
40
|
+
$id: TRef;
|
|
41
|
+
} & Object$1.Path<TObj, RefToPath<TRef>>;
|
|
42
|
+
type ResolveRefInObj<T, TBase> = T extends {
|
|
43
|
+
$ref: infer Ref;
|
|
44
|
+
} ? (Ref extends string ? ResolveRef<TBase, Ref> : T) : T;
|
|
45
|
+
type ResolveRefsInObj<T, TBase = T> = {
|
|
46
|
+
[K in keyof T]: ResolveRefsInObj<ResolveRefInObj<T[K], TBase>, TBase>;
|
|
47
|
+
};
|
|
48
|
+
type Infer<TOas> = Mutable<ResolveRefsInObj<TOas>>;
|
|
49
|
+
|
|
50
|
+
type Checks$4<TParamType = never> = {
|
|
51
|
+
Required: {
|
|
52
|
+
required: true;
|
|
53
|
+
};
|
|
54
|
+
Schemas: {
|
|
55
|
+
schema: JSONSchema;
|
|
56
|
+
};
|
|
57
|
+
Enum: {
|
|
58
|
+
type: JSONSchemaTypeName;
|
|
59
|
+
enum?: any[];
|
|
60
|
+
};
|
|
61
|
+
Parameters: {
|
|
62
|
+
in: string;
|
|
63
|
+
required?: boolean;
|
|
64
|
+
}[];
|
|
65
|
+
SingleParameter: [{
|
|
66
|
+
in: TParamType;
|
|
67
|
+
required?: true;
|
|
68
|
+
}];
|
|
69
|
+
Responses: {
|
|
70
|
+
responses: any;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
type PathMap<TOAS extends OasTypes.OASDocument> = TOAS['paths'];
|
|
74
|
+
interface ParamPropMap {
|
|
75
|
+
query: 'query';
|
|
76
|
+
path: 'params';
|
|
77
|
+
header: 'headers';
|
|
78
|
+
}
|
|
79
|
+
type JSONSchemaTypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
80
|
+
type ParamObj<TParameter extends {
|
|
81
|
+
name: string;
|
|
82
|
+
}> = TParameter extends Checks$4['Required'] ? {
|
|
83
|
+
[TName in TParameter['name']]: TParameter extends Checks$4['Schemas'] ? FromSchema<TParameter['schema']> : TParameter extends Checks$4['Enum'] ? FromSchema<{
|
|
84
|
+
type: TParameter['type'];
|
|
85
|
+
enum: TParameter['enum'];
|
|
86
|
+
}> : unknown;
|
|
87
|
+
} : {
|
|
88
|
+
[TName in TParameter['name']]?: TParameter extends Checks$4['Schemas'] ? FromSchema<TParameter['schema']> : TParameter extends Checks$4['Enum'] ? FromSchema<{
|
|
89
|
+
type: TParameter['type'];
|
|
90
|
+
enum: TParameter['enum'];
|
|
91
|
+
}> : unknown;
|
|
92
|
+
};
|
|
93
|
+
interface ParamToRequestParam<TParameters extends Checks$4['Parameters']> extends Fn {
|
|
94
|
+
return: this['arg0'] extends {
|
|
95
|
+
name: string;
|
|
96
|
+
in: infer TParamType;
|
|
97
|
+
} ? TParameters extends Checks$4<TParamType>['SingleParameter'] ? {
|
|
98
|
+
[TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]: ParamObj<this['arg0']>;
|
|
99
|
+
} : {
|
|
100
|
+
[TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]?: ParamObj<this['arg0']>;
|
|
101
|
+
} : {};
|
|
102
|
+
}
|
|
103
|
+
type ParamMap<TParameters extends Checks$4['Parameters']> = Pipe<TParameters, [Tuples.Map<ParamToRequestParam<TParameters>>, Tuples.ToIntersection]>;
|
|
104
|
+
type MethodMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>> = PathMap<TOAS>[TPath];
|
|
105
|
+
type StatusMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = MethodMap<TOAS, TPath>[TMethod] extends Checks$4['Responses'] ? MethodMap<TOAS, TPath>[TMethod]['responses'] : never;
|
|
106
|
+
|
|
107
|
+
type Checks$3<TName extends string | number | symbol = never> = {
|
|
108
|
+
ModelWithSchemas: {
|
|
109
|
+
components: {
|
|
110
|
+
schemas: Record<string, JSONSchema>;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
ModelWithSchemasNamed: {
|
|
114
|
+
components: {
|
|
115
|
+
schemas: {
|
|
116
|
+
[TModelName in TName]: JSONSchema;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
ModelWithDefinitions: {
|
|
121
|
+
definitions: Record<string, JSONSchema>;
|
|
122
|
+
};
|
|
123
|
+
ModelWithDefinitionsNamed: {
|
|
124
|
+
definitions: {
|
|
125
|
+
[TModelName in TName]: JSONSchema;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
type Model<TOAS extends OasTypes.OASDocument, TName extends TOAS extends Checks$3['ModelWithSchemas'] ? keyof TOAS['components']['schemas'] : TOAS extends Checks$3['ModelWithDefinitions'] ? keyof TOAS['definitions'] : never> = TOAS extends Checks$3<TName>['ModelWithSchemasNamed'] ? FromSchema<TOAS['components']['schemas'][TName]> : TOAS extends Checks$3<TName>['ModelWithDefinitionsNamed'] ? FromSchema<TOAS['definitions'][TName]> : never;
|
|
130
|
+
|
|
131
|
+
type TupleToUnion<T> = T extends any[] ? T[number] : never;
|
|
132
|
+
type SplitByDelimiter<T extends string, D extends string> = T extends `${infer P}${D}${infer Q}` ? [P, ...SplitByDelimiter<Q, D>] : [T];
|
|
133
|
+
|
|
134
|
+
type Checks$2 = {
|
|
135
|
+
Security: {
|
|
136
|
+
security: {
|
|
137
|
+
[key: string]: any;
|
|
138
|
+
}[];
|
|
139
|
+
};
|
|
140
|
+
AuthParams: {
|
|
141
|
+
Basic: {
|
|
142
|
+
type: 'http';
|
|
143
|
+
scheme: 'basic';
|
|
144
|
+
} | {
|
|
145
|
+
type: 'basic';
|
|
146
|
+
};
|
|
147
|
+
Bearer: {
|
|
148
|
+
type: 'http';
|
|
149
|
+
scheme: 'bearer';
|
|
150
|
+
} | {
|
|
151
|
+
type: 'bearer';
|
|
152
|
+
};
|
|
153
|
+
OAuth2: {
|
|
154
|
+
type: 'oauth2';
|
|
155
|
+
};
|
|
156
|
+
ApiKey: {
|
|
157
|
+
type: 'apiKey';
|
|
158
|
+
in: 'header';
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
AuthName: {
|
|
162
|
+
Basic: `basic${string}`;
|
|
163
|
+
Bearer: `bearer${string}`;
|
|
164
|
+
OAuth2: `oauth${string}`;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
type SecuritySchemeName<T extends Checks$2['Security']> = Call<Tuples.Map<Objects.Keys>, T['security']>[number];
|
|
168
|
+
declare namespace AuthParams {
|
|
169
|
+
type Basic<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['Basic'] ? {
|
|
170
|
+
headers: {
|
|
171
|
+
/**
|
|
172
|
+
* `Authorization` header is required for basic authentication
|
|
173
|
+
* @see https://en.wikipedia.org/wiki/Basic_access_authentication
|
|
174
|
+
*
|
|
175
|
+
* It contains the word `Basic` followed by a space and a base64-encoded string `username:password`
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```
|
|
179
|
+
* Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
Authorization: `Basic ${string}`;
|
|
183
|
+
};
|
|
184
|
+
} : {};
|
|
185
|
+
type Bearer<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['Bearer'] ? {
|
|
186
|
+
/**
|
|
187
|
+
* `Authorization` header is required for bearer authentication
|
|
188
|
+
* @see https://swagger.io/docs/specification/authentication/bearer-authentication/
|
|
189
|
+
*/
|
|
190
|
+
headers: {
|
|
191
|
+
/**
|
|
192
|
+
* It contains the word `Bearer` followed by a space and the token
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```
|
|
196
|
+
* Authorization: Bearer {token}
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
Authorization: `Bearer ${string}`;
|
|
200
|
+
};
|
|
201
|
+
} : {};
|
|
202
|
+
type ApiKey<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['ApiKey'] & {
|
|
203
|
+
name: infer TApiKeyHeaderName;
|
|
204
|
+
} ? {
|
|
205
|
+
headers: {
|
|
206
|
+
[THeaderName in TApiKeyHeaderName extends string ? TApiKeyHeaderName : never]: string;
|
|
207
|
+
};
|
|
208
|
+
} : TSecurityScheme extends {
|
|
209
|
+
type: 'apiKey';
|
|
210
|
+
in: 'query';
|
|
211
|
+
name: infer TApiKeyQueryName;
|
|
212
|
+
} ? {
|
|
213
|
+
query: {
|
|
214
|
+
[TQueryName in TApiKeyQueryName extends string ? TApiKeyQueryName : never]: string;
|
|
215
|
+
};
|
|
216
|
+
} : {};
|
|
217
|
+
type OAuth2<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['OAuth2'] ? {
|
|
218
|
+
/**
|
|
219
|
+
* `Authorization` header is required for OAuth2.
|
|
220
|
+
*/
|
|
221
|
+
headers: {
|
|
222
|
+
/**
|
|
223
|
+
* The access token string as issued by the authorization server.
|
|
224
|
+
* @example `Authorization: Bearer <access_token>`
|
|
225
|
+
*/
|
|
226
|
+
Authorization: `Bearer ${string}`;
|
|
227
|
+
};
|
|
228
|
+
} : {};
|
|
229
|
+
}
|
|
230
|
+
type OASSecurityParams<TSecurityScheme> = AuthParams.Basic<TSecurityScheme> & AuthParams.Bearer<TSecurityScheme> & AuthParams.ApiKey<TSecurityScheme> & AuthParams.OAuth2<TSecurityScheme>;
|
|
231
|
+
type SecurityParamsBySecurityRef<TOAS, TSecurityObj> = TSecurityObj extends Checks$2['Security'] ? TOAS extends {
|
|
232
|
+
components: {
|
|
233
|
+
securitySchemes: {
|
|
234
|
+
[TSecuritySchemeNameKey in SecuritySchemeName<TSecurityObj> extends string ? SecuritySchemeName<TSecurityObj> : never]: infer TSecurityScheme;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
} | {
|
|
238
|
+
securityDefinitions: {
|
|
239
|
+
[TSecuritySchemeNameKey in SecuritySchemeName<TSecurityObj> extends string ? SecuritySchemeName<TSecurityObj> : never]: infer TSecurityScheme;
|
|
240
|
+
};
|
|
241
|
+
} ? OASSecurityParams<TSecurityScheme> : SecuritySchemeName<TSecurityObj> extends Checks$2['AuthName']['Basic'] ? AuthParams.Basic<{
|
|
242
|
+
type: 'http';
|
|
243
|
+
scheme: 'basic';
|
|
244
|
+
}> : SecuritySchemeName<TSecurityObj> extends Checks$2['AuthName']['Bearer'] ? AuthParams.Bearer<{
|
|
245
|
+
type: 'http';
|
|
246
|
+
scheme: 'bearer';
|
|
247
|
+
}> : SecuritySchemeName<TSecurityObj> extends Checks$2['AuthName']['OAuth2'] ? AuthParams.OAuth2<{
|
|
248
|
+
type: 'oauth2';
|
|
249
|
+
}> : {} : {};
|
|
250
|
+
|
|
251
|
+
type Checks$1 = {
|
|
252
|
+
RequestBodyJson: {
|
|
253
|
+
requestBody: {
|
|
254
|
+
content: {
|
|
255
|
+
'application/json': {
|
|
256
|
+
schema: JSONSchema;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
RequestBodyFormData: {
|
|
262
|
+
requestBody: {
|
|
263
|
+
content: {
|
|
264
|
+
'multipart/form-data': {
|
|
265
|
+
schema: JSONSchema;
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
RequestBodyFormEncoded: {
|
|
271
|
+
requestBody: {
|
|
272
|
+
content: {
|
|
273
|
+
'application/x-www-form-urlencoded': {
|
|
274
|
+
schema: JSONSchema;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
Parameters: {
|
|
280
|
+
parameters: {
|
|
281
|
+
name: string;
|
|
282
|
+
in: string;
|
|
283
|
+
}[];
|
|
284
|
+
};
|
|
285
|
+
PathBrackets: `${string}{${string}}${string}`;
|
|
286
|
+
PathPattern: `${string}:${string}${string}`;
|
|
287
|
+
Required: {
|
|
288
|
+
required: true;
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
type ExtractPathParamsWithPattern<TPath extends string> = Pipe<TPath, [
|
|
292
|
+
Strings.Split<'/'>,
|
|
293
|
+
Tuples.Filter<Strings.StartsWith<':'>>,
|
|
294
|
+
Tuples.Map<Strings.Trim<':'>>,
|
|
295
|
+
Tuples.ToUnion
|
|
296
|
+
]>;
|
|
297
|
+
type IsPathParameter<T extends string> = T extends `{${infer U}}` ? U : never;
|
|
298
|
+
type ExtractPathParameters<T extends any[]> = {
|
|
299
|
+
[K in keyof T]: IsPathParameter<T[K]>;
|
|
300
|
+
};
|
|
301
|
+
type ExtractSegments<TPath extends string> = SplitByDelimiter<TPath, '/'>;
|
|
302
|
+
type ExtractSubSegments<T extends any[]> = {
|
|
303
|
+
[K in keyof T]: SplitByDelimiter<T[K], ';'>;
|
|
304
|
+
};
|
|
305
|
+
type ExtractPathParamsWithBrackets<TPath extends string> = TupleToUnion<ExtractPathParameters<ExtractSubSegments<ExtractSegments<TPath>>[number]>>;
|
|
306
|
+
type RequestParams<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = (MethodMap<TOAS, TPath>[TMethod] extends Checks$1['RequestBodyJson'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks$1['Required'] ? {
|
|
307
|
+
/**
|
|
308
|
+
* The request body in JSON is required for this request.
|
|
309
|
+
*
|
|
310
|
+
* The value of `json` will be stringified and sent as the request body with `Content-Type: application/json`.
|
|
311
|
+
*/
|
|
312
|
+
json: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']>;
|
|
313
|
+
} : {
|
|
314
|
+
/**
|
|
315
|
+
* The request body in JSON is optional for this request.
|
|
316
|
+
*
|
|
317
|
+
* The value of `json` will be stringified and sent as the request body with `Content-Type: application/json`.
|
|
318
|
+
*/
|
|
319
|
+
json?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']>;
|
|
320
|
+
} : MethodMap<TOAS, TPath>[TMethod] extends Checks$1['RequestBodyFormData'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks$1['Required'] ? {
|
|
321
|
+
/**
|
|
322
|
+
* The request body in multipart/form-data is required for this request.
|
|
323
|
+
*
|
|
324
|
+
* The value of `formData` will be sent as the request body with `Content-Type: multipart/form-data`.
|
|
325
|
+
*/
|
|
326
|
+
formData: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['multipart/form-data']['schema']>;
|
|
327
|
+
} : {
|
|
328
|
+
/**
|
|
329
|
+
* The request body in multipart/form-data is optional for this request.
|
|
330
|
+
*
|
|
331
|
+
* The value of `formData` will be sent as the request body with `Content-Type: multipart/form-data`.
|
|
332
|
+
*/
|
|
333
|
+
formData?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['multipart/form-data']['schema']>;
|
|
334
|
+
} : MethodMap<TOAS, TPath>[TMethod] extends Checks$1['RequestBodyFormEncoded'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks$1['Required'] ? {
|
|
335
|
+
/**
|
|
336
|
+
* The request body in application/x-www-form-urlencoded is required for this request.
|
|
337
|
+
*
|
|
338
|
+
* The value of `formUrlEncoded` will be sent as the request body with `Content-Type: application/x-www-form-urlencoded`.
|
|
339
|
+
*/
|
|
340
|
+
formUrlEncoded: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']>;
|
|
341
|
+
} : {
|
|
342
|
+
/**
|
|
343
|
+
* The request body in application/x-www-form-urlencoded is optional for this request.
|
|
344
|
+
*
|
|
345
|
+
* The value of `formUrlEncoded` will be sent as the request body with `Content-Type: application/x-www-form-urlencoded`.
|
|
346
|
+
*/
|
|
347
|
+
formUrlEncoded?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']>;
|
|
348
|
+
} : {}) & (MethodMap<TOAS, TPath>[TMethod] extends Checks$1['Parameters'] ? ParamMap<MethodMap<TOAS, TPath>[TMethod]['parameters']> : {}) & // If there is any parameters defined in path but not in the parameters array, we should add them to the params
|
|
349
|
+
(TPath extends Checks$1['PathBrackets'] ? {
|
|
350
|
+
/**
|
|
351
|
+
* Parameters defined in the path are required for this request.
|
|
352
|
+
*
|
|
353
|
+
* The value of `params` will be used to replace the path parameters.
|
|
354
|
+
*
|
|
355
|
+
* For example if path is `/todos/{id}` and `params` is `{ id: '1' }`, the path will be `/todos/1`
|
|
356
|
+
*/
|
|
357
|
+
params: Record<ExtractPathParamsWithBrackets<TPath>, string | number | bigint | boolean>;
|
|
358
|
+
} : {}) & (TPath extends Checks$1['PathPattern'] ? {
|
|
359
|
+
/**
|
|
360
|
+
* Parameters defined in the path are required for this request.
|
|
361
|
+
*
|
|
362
|
+
* The value of `params` will be used to replace the path parameters.
|
|
363
|
+
*
|
|
364
|
+
* For example if path is `/todos/:id` and `params` is `{ id: '1' }`, the path will be `/todos/1`.
|
|
365
|
+
*/
|
|
366
|
+
params: Record<ExtractPathParamsWithPattern<TPath>, string | number | bigint | boolean>;
|
|
367
|
+
} : {}) & // Respect security definitions in path object
|
|
368
|
+
SecurityParamsBySecurityRef<TOAS, MethodMap<TOAS, TPath>[TMethod]> & // Respect global security definitions
|
|
369
|
+
SecurityParamsBySecurityRef<TOAS, TOAS>;
|
|
370
|
+
|
|
371
|
+
type Checks = {
|
|
372
|
+
Content: {
|
|
373
|
+
content: any;
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
type ResponseSchemas<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>, TStatus extends keyof StatusMap<TOAS, TPath, TMethod>> = StatusMap<TOAS, TPath, TMethod>[TStatus]['content'];
|
|
377
|
+
type JSONResponseSchema<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>, TStatus extends keyof StatusMap<TOAS, TPath, TMethod>> = StatusMap<TOAS, TPath, TMethod>[TStatus] extends Checks['Content'] ? ResponseSchemas<TOAS, TPath, TMethod, TStatus>[keyof ResponseSchemas<TOAS, TPath, TMethod, TStatus>]['schema'] : StatusMap<TOAS, TPath, TMethod>[TStatus]['schema'];
|
|
378
|
+
type Response<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>, TStatusCode extends keyof StatusMap<TOAS, TPath, TMethod> = 200> = FromSchema<JSONResponseSchema<TOAS, TPath, TMethod, TStatusCode>>;
|
|
379
|
+
|
|
380
|
+
export type { Infer, MethodMap, Model, PathMap, RequestParams, Response, StatusMap };
|
package/dist/infer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"infer.js"}
|
package/dist/parser.cjs
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkJAZKMYLT_cjs = require('./chunk-JAZKMYLT.cjs');
|
|
4
|
+
var openapiCore = require('@redocly/openapi-core');
|
|
5
|
+
var OASNormalize = require('oas-normalize');
|
|
6
|
+
var swagger2openapi = require('swagger2openapi');
|
|
3
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
4
9
|
|
|
5
|
-
var
|
|
10
|
+
var OASNormalize__default = /*#__PURE__*/_interopDefault(OASNormalize);
|
|
11
|
+
var swagger2openapi__default = /*#__PURE__*/_interopDefault(swagger2openapi);
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
9
|
-
var _swagger2openapi = require('swagger2openapi'); var _swagger2openapi2 = _interopRequireDefault(_swagger2openapi);
|
|
10
|
-
var _openapicore = require('@redocly/openapi-core');
|
|
11
|
-
async function parse(pathOrApi, options = {}, oasClass = _chunkUIWP4KHBcjs.Oas) {
|
|
13
|
+
async function parse(pathOrApi, oasClass = chunkJAZKMYLT_cjs.Oas) {
|
|
12
14
|
if (typeof pathOrApi === "string") {
|
|
13
|
-
const config = await
|
|
14
|
-
const bundleResults = await
|
|
15
|
-
return parse(bundleResults.bundle.parsed
|
|
15
|
+
const config = await openapiCore.loadConfig();
|
|
16
|
+
const bundleResults = await openapiCore.bundle({ ref: pathOrApi, config, base: pathOrApi });
|
|
17
|
+
return parse(bundleResults.bundle.parsed);
|
|
16
18
|
}
|
|
17
|
-
const oasNormalize = new
|
|
19
|
+
const oasNormalize = new OASNormalize__default.default(pathOrApi, {
|
|
18
20
|
enablePaths: true,
|
|
19
21
|
colorizeErrors: true
|
|
20
22
|
});
|
|
21
23
|
const document = await oasNormalize.load();
|
|
22
|
-
if (
|
|
23
|
-
const { openapi } = await
|
|
24
|
+
if (chunkJAZKMYLT_cjs.isOpenApiV2Document(document)) {
|
|
25
|
+
const { openapi } = await swagger2openapi__default.default.convertObj(document, {
|
|
24
26
|
anchors: true
|
|
25
27
|
});
|
|
26
|
-
|
|
27
|
-
return new oasClass({ oas: oas2 });
|
|
28
|
+
return new oasClass({ oas: openapi });
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
return new oasClass({ oas });
|
|
30
|
+
return new oasClass({ oas: document });
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
33
|
exports.parse = parse;
|
|
34
|
+
//# sourceMappingURL=parser.cjs.map
|
|
35
35
|
//# sourceMappingURL=parser.cjs.map
|
package/dist/parser.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/parser/index.ts"],"names":["Oas","loadConfig","bundle","OASNormalize","isOpenApiV2Document","swagger2openapi"],"mappings":";;;;;;;;;;;;AAUA,eAAsB,KAAA,CAAM,SAAiC,EAAA,QAAA,GAAuBA,qBAAmB,EAAA;AACrG,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAMC,sBAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAMC,kBAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAO,OAAA,KAAA,CAAM,aAAc,CAAA,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,GAC1C;AAEA,EAAM,MAAA,YAAA,GAAe,IAAIC,6BAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAAC,qCAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAMC,gCAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,SAAwB,CAAA,CAAA;AAAA,GACrD;AAEA,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,UAAU,CAAA,CAAA;AACvC","file":"parser.cjs","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document })\n}\n"]}
|
package/dist/parser.d.cts
CHANGED
|
@@ -1,49 +1,8 @@
|
|
|
1
|
-
import { O as Oas } from './Oas-
|
|
1
|
+
import { O as Oas } from './Oas-Br0yKhGF.cjs';
|
|
2
2
|
import { OASDocument } from 'oas/types';
|
|
3
3
|
import 'oas';
|
|
4
4
|
import 'oas/operation';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
verbose?: boolean;
|
|
8
|
-
'no-sort'?: boolean;
|
|
9
|
-
sort?: boolean;
|
|
10
|
-
output?: string;
|
|
11
|
-
sortSet?: {
|
|
12
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>;
|
|
13
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
14
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
15
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
16
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
17
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
18
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>;
|
|
19
|
-
requestBody?: Array<'description' | 'required' | 'content'>;
|
|
20
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>;
|
|
21
|
-
content?: Array<string>;
|
|
22
|
-
components?: Array<'parameters' | 'schemas'>;
|
|
23
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
24
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
25
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
|
|
26
|
-
};
|
|
27
|
-
filterSet?: {
|
|
28
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
29
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
30
|
-
tags?: Array<string>;
|
|
31
|
-
inverseTags?: Array<string>;
|
|
32
|
-
operationIds?: Array<string>;
|
|
33
|
-
inverseOperationIds?: Array<string>;
|
|
34
|
-
operations?: Array<string>;
|
|
35
|
-
flags?: Array<string>;
|
|
36
|
-
inverseFlags?: Array<string>;
|
|
37
|
-
flagValues?: Array<string>;
|
|
38
|
-
inverseFlagValues?: Array<string>;
|
|
39
|
-
stripFlags?: Array<string>;
|
|
40
|
-
responseContent?: Array<string>;
|
|
41
|
-
inverseResponseContent?: Array<string>;
|
|
42
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>;
|
|
43
|
-
};
|
|
44
|
-
sortComponentsSet?: {};
|
|
45
|
-
casingSet?: {};
|
|
46
|
-
};
|
|
47
|
-
declare function parse(pathOrApi: string | OASDocument, options?: FormatOptions, oasClass?: typeof Oas): Promise<Oas>;
|
|
6
|
+
declare function parse(pathOrApi: string | OASDocument, oasClass?: typeof Oas): Promise<Oas>;
|
|
48
7
|
|
|
49
|
-
export {
|
|
8
|
+
export { parse };
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,49 +1,8 @@
|
|
|
1
|
-
import { O as Oas } from './Oas-
|
|
1
|
+
import { O as Oas } from './Oas-Br0yKhGF.js';
|
|
2
2
|
import { OASDocument } from 'oas/types';
|
|
3
3
|
import 'oas';
|
|
4
4
|
import 'oas/operation';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
verbose?: boolean;
|
|
8
|
-
'no-sort'?: boolean;
|
|
9
|
-
sort?: boolean;
|
|
10
|
-
output?: string;
|
|
11
|
-
sortSet?: {
|
|
12
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>;
|
|
13
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
14
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
15
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
16
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
17
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
18
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>;
|
|
19
|
-
requestBody?: Array<'description' | 'required' | 'content'>;
|
|
20
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>;
|
|
21
|
-
content?: Array<string>;
|
|
22
|
-
components?: Array<'parameters' | 'schemas'>;
|
|
23
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
24
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
25
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
|
|
26
|
-
};
|
|
27
|
-
filterSet?: {
|
|
28
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
29
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
30
|
-
tags?: Array<string>;
|
|
31
|
-
inverseTags?: Array<string>;
|
|
32
|
-
operationIds?: Array<string>;
|
|
33
|
-
inverseOperationIds?: Array<string>;
|
|
34
|
-
operations?: Array<string>;
|
|
35
|
-
flags?: Array<string>;
|
|
36
|
-
inverseFlags?: Array<string>;
|
|
37
|
-
flagValues?: Array<string>;
|
|
38
|
-
inverseFlagValues?: Array<string>;
|
|
39
|
-
stripFlags?: Array<string>;
|
|
40
|
-
responseContent?: Array<string>;
|
|
41
|
-
inverseResponseContent?: Array<string>;
|
|
42
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>;
|
|
43
|
-
};
|
|
44
|
-
sortComponentsSet?: {};
|
|
45
|
-
casingSet?: {};
|
|
46
|
-
};
|
|
47
|
-
declare function parse(pathOrApi: string | OASDocument, options?: FormatOptions, oasClass?: typeof Oas): Promise<Oas>;
|
|
6
|
+
declare function parse(pathOrApi: string | OASDocument, oasClass?: typeof Oas): Promise<Oas>;
|
|
48
7
|
|
|
49
|
-
export {
|
|
8
|
+
export { parse };
|
package/dist/parser.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./chunk-7D7ASOLY.js";
|
|
1
|
+
import { isOpenApiV2Document, Oas } from './chunk-PHE7X6W6.js';
|
|
2
|
+
import { loadConfig, bundle } from '@redocly/openapi-core';
|
|
3
|
+
import OASNormalize from 'oas-normalize';
|
|
4
|
+
import swagger2openapi from 'swagger2openapi';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
import OASNormalize from "oas-normalize";
|
|
9
|
-
import swagger2openapi from "swagger2openapi";
|
|
10
|
-
import { bundle, loadConfig } from "@redocly/openapi-core";
|
|
11
|
-
async function parse(pathOrApi, options = {}, oasClass = Oas) {
|
|
6
|
+
async function parse(pathOrApi, oasClass = Oas) {
|
|
12
7
|
if (typeof pathOrApi === "string") {
|
|
13
8
|
const config = await loadConfig();
|
|
14
9
|
const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi });
|
|
15
|
-
return parse(bundleResults.bundle.parsed
|
|
10
|
+
return parse(bundleResults.bundle.parsed);
|
|
16
11
|
}
|
|
17
12
|
const oasNormalize = new OASNormalize(pathOrApi, {
|
|
18
13
|
enablePaths: true,
|
|
@@ -23,13 +18,11 @@ async function parse(pathOrApi, options = {}, oasClass = Oas) {
|
|
|
23
18
|
const { openapi } = await swagger2openapi.convertObj(document, {
|
|
24
19
|
anchors: true
|
|
25
20
|
});
|
|
26
|
-
|
|
27
|
-
return new oasClass({ oas: oas2 });
|
|
21
|
+
return new oasClass({ oas: openapi });
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
return new oasClass({ oas });
|
|
23
|
+
return new oasClass({ oas: document });
|
|
31
24
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
|
|
26
|
+
export { parse };
|
|
27
|
+
//# sourceMappingURL=parser.js.map
|
|
35
28
|
//# sourceMappingURL=parser.js.map
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parser/index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/parser/index.ts"],"names":[],"mappings":";;;;;AAUA,eAAsB,KAAA,CAAM,SAAiC,EAAA,QAAA,GAAuB,GAAmB,EAAA;AACrG,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAM,UAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAM,MAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAO,OAAA,KAAA,CAAM,aAAc,CAAA,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,GAC1C;AAEA,EAAM,MAAA,YAAA,GAAe,IAAI,YAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAA,mBAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAM,eAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,SAAwB,CAAA,CAAA;AAAA,GACrD;AAEA,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,UAAU,CAAA,CAAA;AACvC","file":"parser.js","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document })\n}\n"]}
|