@kubb/swagger-ts 2.13.0 → 2.13.2

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.
@@ -1,389 +0,0 @@
1
- import { Call, Tuples, Objects, Booleans, Strings, Pipe, Fn } from 'hotscript';
2
- import { Object as Object$1 } from 'ts-toolbelt';
3
- import { OasTypes } from '@kubb/swagger/oas';
4
- import { JSONSchema, FromSchema } from 'json-schema-to-ts';
5
- import { TupleToUnion, SplitByDelimiter } from '@kubb/types';
6
-
7
- type Checks$5 = {
8
- AllOFf: {
9
- allOf: any[];
10
- };
11
- Object: {
12
- type: 'object';
13
- properties: any;
14
- };
15
- Properties: {
16
- properties: any;
17
- };
18
- PropertiesRequired: {
19
- properties: Record<string, any>;
20
- required: string[];
21
- };
22
- };
23
- type FixAdditionalPropertiesForAllOf<T> = T extends Checks$5['AllOFf'] ? Omit<T, 'allOf'> & {
24
- allOf: Call<Tuples.Map<Objects.Omit<'additionalProperties'>>, T['allOf']>;
25
- } : T;
26
- type FixMissingAdditionalProperties<T> = T extends Checks$5['Object'] ? Omit<T, 'additionalProperties'> & {
27
- additionalProperties: false;
28
- } : T;
29
- type FixMissingTypeObject<T> = T extends Checks$5['Properties'] ? T & {
30
- type: 'object';
31
- } : T;
32
- type FixExtraRequiredFields<T> = T extends Checks$5['PropertiesRequired'] ? Omit<T, 'required'> & {
33
- required: Call<Tuples.Filter<Booleans.Extends<keyof T['properties']>>, T['required']>;
34
- } : T;
35
- type FixJSONSchema<T> = FixAdditionalPropertiesForAllOf<FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>>;
36
- type Mutable<Type> = FixJSONSchema<{
37
- -readonly [Key in keyof Type]: Mutable<Type[Key]>;
38
- }>;
39
- type RefToPath<T extends string> = T extends `#/${infer Ref}` ? Call<Strings.Split<'/'>, Ref> : never;
40
- type ResolveRef<TObj, TRef extends string> = {
41
- $id: TRef;
42
- } & Object$1.Path<TObj, RefToPath<TRef>>;
43
- type ResolveRefInObj<T, TBase> = T extends {
44
- $ref: infer Ref;
45
- } ? (Ref extends string ? ResolveRef<TBase, Ref> : T) : T;
46
- type ResolveRefsInObj<T, TBase = T> = {
47
- [K in keyof T]: ResolveRefsInObj<ResolveRefInObj<T[K], TBase>, TBase>;
48
- };
49
- type Infer<TOAS> = Mutable<ResolveRefsInObj<TOAS>>;
50
-
51
- type Checks$4<TParamType = never> = {
52
- Required: {
53
- required: true;
54
- };
55
- Schemas: {
56
- schema: JSONSchema;
57
- };
58
- Enum: {
59
- type: JSONSchemaTypeName;
60
- enum?: any[];
61
- };
62
- Parameters: {
63
- in: string;
64
- required?: boolean;
65
- }[];
66
- SingleParameter: [{
67
- in: TParamType;
68
- required?: true;
69
- }];
70
- Responses: {
71
- responses: any;
72
- };
73
- };
74
- type PathMap<TOAS extends OasTypes.OASDocument> = TOAS['paths'];
75
- interface ParamPropMap {
76
- query: 'query';
77
- path: 'params';
78
- header: 'headers';
79
- }
80
- type JSONSchemaTypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
81
- type ParamObj<TParameter extends {
82
- name: string;
83
- }> = TParameter extends Checks$4['Required'] ? {
84
- [TName in TParameter['name']]: TParameter extends Checks$4['Schemas'] ? FromSchema<TParameter['schema']> : TParameter extends Checks$4['Enum'] ? FromSchema<{
85
- type: TParameter['type'];
86
- enum: TParameter['enum'];
87
- }> : unknown;
88
- } : {
89
- [TName in TParameter['name']]?: TParameter extends Checks$4['Schemas'] ? FromSchema<TParameter['schema']> : TParameter extends Checks$4['Enum'] ? FromSchema<{
90
- type: TParameter['type'];
91
- enum: TParameter['enum'];
92
- }> : unknown;
93
- };
94
- interface ParamToRequestParam<TParameters extends Checks$4['Parameters']> extends Fn {
95
- return: this['arg0'] extends {
96
- name: string;
97
- in: infer TParamType;
98
- } ? TParameters extends Checks$4<TParamType>['SingleParameter'] ? {
99
- [TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]: ParamObj<this['arg0']>;
100
- } : {
101
- [TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]?: ParamObj<this['arg0']>;
102
- } : {};
103
- }
104
- type ParamMap<TParameters extends Checks$4['Parameters']> = Pipe<TParameters, [Tuples.Map<ParamToRequestParam<TParameters>>, Tuples.ToIntersection]>;
105
- type MethodMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>> = PathMap<TOAS>[TPath];
106
- 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;
107
-
108
- type Checks$3<TName extends string | number | symbol = never> = {
109
- ModelWithSchemas: {
110
- components: {
111
- schemas: Record<string, JSONSchema>;
112
- };
113
- };
114
- ModelWithSchemasNamed: {
115
- components: {
116
- schemas: {
117
- [TModelName in TName]: JSONSchema;
118
- };
119
- };
120
- };
121
- ModelWithDefinitions: {
122
- definitions: Record<string, JSONSchema>;
123
- };
124
- ModelWithDefinitionsNamed: {
125
- definitions: {
126
- [TModelName in TName]: JSONSchema;
127
- };
128
- };
129
- };
130
- 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;
131
-
132
- type Checks$2 = {
133
- Security: {
134
- security: {
135
- [key: string]: any;
136
- }[];
137
- };
138
- AuthParams: {
139
- Basic: {
140
- type: 'http';
141
- scheme: 'basic';
142
- } | {
143
- type: 'basic';
144
- };
145
- Bearer: {
146
- type: 'http';
147
- scheme: 'bearer';
148
- } | {
149
- type: 'bearer';
150
- };
151
- OAuth2: {
152
- type: 'oauth2';
153
- };
154
- ApiKey: {
155
- type: 'apiKey';
156
- in: 'header';
157
- };
158
- };
159
- AuthName: {
160
- Basic: `basic${string}`;
161
- Bearer: `bearer${string}`;
162
- OAuth2: `oauth${string}`;
163
- };
164
- };
165
- type SecuritySchemeName<T extends Checks$2['Security']> = Call<Tuples.Map<Objects.Keys>, T['security']>[number];
166
- declare namespace AuthParams {
167
- type Basic<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['Basic'] ? {
168
- headers: {
169
- /**
170
- * `Authorization` header is required for basic authentication
171
- * @see https://en.wikipedia.org/wiki/Basic_access_authentication
172
- *
173
- * It contains the word `Basic` followed by a space and a base64-encoded string `username:password`
174
- *
175
- * @example
176
- * ```
177
- * Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
178
- * ```
179
- */
180
- Authorization: `Basic ${string}`;
181
- };
182
- } : {};
183
- type Bearer<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['Bearer'] ? {
184
- /**
185
- * `Authorization` header is required for bearer authentication
186
- * @see https://swagger.io/docs/specification/authentication/bearer-authentication/
187
- */
188
- headers: {
189
- /**
190
- * It contains the word `Bearer` followed by a space and the token
191
- *
192
- * @example
193
- * ```
194
- * Authorization: Bearer {token}
195
- * ```
196
- */
197
- Authorization: `Bearer ${string}`;
198
- };
199
- } : {};
200
- type ApiKey<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['ApiKey'] & {
201
- name: infer TApiKeyHeaderName;
202
- } ? {
203
- headers: {
204
- [THeaderName in TApiKeyHeaderName extends string ? TApiKeyHeaderName : never]: string;
205
- };
206
- } : TSecurityScheme extends {
207
- type: 'apiKey';
208
- in: 'query';
209
- name: infer TApiKeyQueryName;
210
- } ? {
211
- query: {
212
- [TQueryName in TApiKeyQueryName extends string ? TApiKeyQueryName : never]: string;
213
- };
214
- } : {};
215
- type OAuth2<TSecurityScheme> = TSecurityScheme extends Checks$2['AuthParams']['OAuth2'] ? {
216
- /**
217
- * `Authorization` header is required for OAuth2.
218
- */
219
- headers: {
220
- /**
221
- * The access token string as issued by the authorization server.
222
- * @example `Authorization: Bearer <access_token>`
223
- */
224
- Authorization: `Bearer ${string}`;
225
- };
226
- } : {};
227
- }
228
- type OASSecurityParams<TSecurityScheme> = AuthParams.Basic<TSecurityScheme> & AuthParams.Bearer<TSecurityScheme> & AuthParams.ApiKey<TSecurityScheme> & AuthParams.OAuth2<TSecurityScheme>;
229
- type SecurityParamsBySecurityRef<TOAS, TSecurityObj> = TSecurityObj extends Checks$2['Security'] ? TOAS extends {
230
- components: {
231
- securitySchemes: {
232
- [TSecuritySchemeNameKey in SecuritySchemeName<TSecurityObj> extends string ? SecuritySchemeName<TSecurityObj> : never]: infer TSecurityScheme;
233
- };
234
- };
235
- } | {
236
- securityDefinitions: {
237
- [TSecuritySchemeNameKey in SecuritySchemeName<TSecurityObj> extends string ? SecuritySchemeName<TSecurityObj> : never]: infer TSecurityScheme;
238
- };
239
- } ? OASSecurityParams<TSecurityScheme> : SecuritySchemeName<TSecurityObj> extends Checks$2['AuthName']['Basic'] ? AuthParams.Basic<{
240
- type: 'http';
241
- scheme: 'basic';
242
- }> : SecuritySchemeName<TSecurityObj> extends Checks$2['AuthName']['Bearer'] ? AuthParams.Bearer<{
243
- type: 'http';
244
- scheme: 'bearer';
245
- }> : SecuritySchemeName<TSecurityObj> extends Checks$2['AuthName']['OAuth2'] ? AuthParams.OAuth2<{
246
- type: 'oauth2';
247
- }> : {} : {};
248
-
249
- type Checks$1 = {
250
- RequestBodyJson: {
251
- requestBody: {
252
- content: {
253
- 'application/json': {
254
- schema: JSONSchema;
255
- };
256
- };
257
- };
258
- };
259
- RequestBodyFormData: {
260
- requestBody: {
261
- content: {
262
- 'multipart/form-data': {
263
- schema: JSONSchema;
264
- };
265
- };
266
- };
267
- };
268
- RequestBodyFormEncoded: {
269
- requestBody: {
270
- content: {
271
- 'application/x-www-form-urlencoded': {
272
- schema: JSONSchema;
273
- };
274
- };
275
- };
276
- };
277
- Parameters: {
278
- parameters: {
279
- name: string;
280
- in: string;
281
- }[];
282
- };
283
- PathBrackets: `${string}{${string}}${string}`;
284
- PathPattern: `${string}:${string}${string}`;
285
- Required: {
286
- required: true;
287
- };
288
- };
289
- type ExtractPathParamsWithPattern<TPath extends string> = Pipe<TPath, [
290
- Strings.Split<'/'>,
291
- Tuples.Filter<Strings.StartsWith<':'>>,
292
- Tuples.Map<Strings.Trim<':'>>,
293
- Tuples.ToUnion
294
- ]>;
295
- type IsPathParameter<T extends string> = T extends `{${infer U}}` ? U : never;
296
- type ExtractPathParameters<T extends any[]> = {
297
- [K in keyof T]: IsPathParameter<T[K]>;
298
- };
299
- type ExtractSegments<TPath extends string> = SplitByDelimiter<TPath, '/'>;
300
- type ExtractSubSegments<T extends any[]> = {
301
- [K in keyof T]: SplitByDelimiter<T[K], ';'>;
302
- };
303
- type ExtractPathParamsWithBrackets<TPath extends string> = TupleToUnion<ExtractPathParameters<ExtractSubSegments<ExtractSegments<TPath>>[number]>>;
304
- 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'] ? {
305
- /**
306
- * The request body in JSON is required for this request.
307
- *
308
- * The value of `json` will be stringified and sent as the request body with `Content-Type: application/json`.
309
- */
310
- json: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']>;
311
- } : {
312
- /**
313
- * The request body in JSON is optional for this request.
314
- *
315
- * The value of `json` will be stringified and sent as the request body with `Content-Type: application/json`.
316
- */
317
- json?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']>;
318
- } : MethodMap<TOAS, TPath>[TMethod] extends Checks$1['RequestBodyFormData'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks$1['Required'] ? {
319
- /**
320
- * The request body in multipart/form-data is required for this request.
321
- *
322
- * The value of `formData` will be sent as the request body with `Content-Type: multipart/form-data`.
323
- */
324
- formData: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['multipart/form-data']['schema']>;
325
- } : {
326
- /**
327
- * The request body in multipart/form-data is optional for this request.
328
- *
329
- * The value of `formData` will be sent as the request body with `Content-Type: multipart/form-data`.
330
- */
331
- formData?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['multipart/form-data']['schema']>;
332
- } : MethodMap<TOAS, TPath>[TMethod] extends Checks$1['RequestBodyFormEncoded'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks$1['Required'] ? {
333
- /**
334
- * The request body in application/x-www-form-urlencoded is required for this request.
335
- *
336
- * The value of `formUrlEncoded` will be sent as the request body with `Content-Type: application/x-www-form-urlencoded`.
337
- */
338
- formUrlEncoded: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']>;
339
- } : {
340
- /**
341
- * The request body in application/x-www-form-urlencoded is optional for this request.
342
- *
343
- * The value of `formUrlEncoded` will be sent as the request body with `Content-Type: application/x-www-form-urlencoded`.
344
- */
345
- formUrlEncoded?: FromSchema<MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/x-www-form-urlencoded']['schema']>;
346
- } : {}) & (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
347
- (TPath extends Checks$1['PathBrackets'] ? {
348
- /**
349
- * Parameters defined in the path are required for this request.
350
- *
351
- * The value of `params` will be used to replace the path parameters.
352
- *
353
- * For example if path is `/todos/{id}` and `params` is `{ id: '1' }`, the path will be `/todos/1`
354
- */
355
- params: Record<ExtractPathParamsWithBrackets<TPath>, string | number | bigint | boolean>;
356
- } : {}) & (TPath extends Checks$1['PathPattern'] ? {
357
- /**
358
- * Parameters defined in the path are required for this request.
359
- *
360
- * The value of `params` will be used to replace the path parameters.
361
- *
362
- * For example if path is `/todos/:id` and `params` is `{ id: '1' }`, the path will be `/todos/1`.
363
- */
364
- params: Record<ExtractPathParamsWithPattern<TPath>, string | number | bigint | boolean>;
365
- } : {}) & // Respect security definitions in path object
366
- SecurityParamsBySecurityRef<TOAS, MethodMap<TOAS, TPath>[TMethod]> & // Respect global security definitions
367
- SecurityParamsBySecurityRef<TOAS, TOAS>;
368
-
369
- type Checks = {
370
- Content: {
371
- content: any;
372
- };
373
- };
374
- 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'];
375
- 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'];
376
- 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>>;
377
-
378
- type index_Infer<TOAS> = Infer<TOAS>;
379
- type index_MethodMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>> = MethodMap<TOAS, TPath>;
380
- type index_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> = Model<TOAS, TName>;
381
- type index_PathMap<TOAS extends OasTypes.OASDocument> = PathMap<TOAS>;
382
- type index_RequestParams<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = RequestParams<TOAS, TPath, TMethod>;
383
- type index_Response<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>, TStatusCode extends keyof StatusMap<TOAS, TPath, TMethod> = 200> = Response<TOAS, TPath, TMethod, TStatusCode>;
384
- type index_StatusMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = StatusMap<TOAS, TPath, TMethod>;
385
- declare namespace index {
386
- export type { index_Infer as Infer, index_MethodMap as MethodMap, index_Model as Model, index_PathMap as PathMap, index_RequestParams as RequestParams, index_Response as Response, index_StatusMap as StatusMap };
387
- }
388
-
389
- export { type Infer as I, type MethodMap as M, type PathMap as P, type RequestParams as R, type StatusMap as S, type Model as a, type Response as b, index as i };
package/src/oas/infer.ts DELETED
@@ -1,51 +0,0 @@
1
- import type { Booleans, Call, Objects, Strings, Tuples } from 'hotscript'
2
- import type { Object } from 'ts-toolbelt'
3
-
4
- type Checks = {
5
- AllOFf: { allOf: any[] }
6
- Object: {
7
- type: 'object'
8
- properties: any
9
- }
10
- Properties: { properties: any }
11
- PropertiesRequired: {
12
- properties: Record<string, any>
13
- required: string[]
14
- }
15
- }
16
-
17
- type FixAdditionalPropertiesForAllOf<T> = T extends Checks['AllOFf']
18
- ? Omit<T, 'allOf'> & {
19
- allOf: Call<Tuples.Map<Objects.Omit<'additionalProperties'>>, T['allOf']>
20
- }
21
- : T
22
-
23
- type FixMissingAdditionalProperties<T> = T extends Checks['Object'] ? Omit<T, 'additionalProperties'> & { additionalProperties: false } : T
24
- type FixMissingTypeObject<T> = T extends Checks['Properties'] ? T & { type: 'object' } : T
25
-
26
- type FixExtraRequiredFields<T> = T extends Checks['PropertiesRequired']
27
- ? Omit<T, 'required'> & {
28
- required: Call<Tuples.Filter<Booleans.Extends<keyof T['properties']>>, T['required']>
29
- }
30
- : T
31
-
32
- // Later suggest using json-machete
33
- type FixJSONSchema<T> = FixAdditionalPropertiesForAllOf<FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>>
34
-
35
- type Mutable<Type> = FixJSONSchema<{
36
- -readonly [Key in keyof Type]: Mutable<Type[Key]>
37
- }>
38
-
39
- type RefToPath<T extends string> = T extends `#/${infer Ref}` ? Call<Strings.Split<'/'>, Ref> : never
40
-
41
- type ResolveRef<TObj, TRef extends string> = {
42
- $id: TRef
43
- } & Object.Path<TObj, RefToPath<TRef>>
44
-
45
- type ResolveRefInObj<T, TBase> = T extends { $ref: infer Ref } ? (Ref extends string ? ResolveRef<TBase, Ref> : T) : T
46
-
47
- type ResolveRefsInObj<T, TBase = T> = {
48
- [K in keyof T]: ResolveRefsInObj<ResolveRefInObj<T[K], TBase>, TBase>
49
- }
50
-
51
- export type Infer<TOAS> = Mutable<ResolveRefsInObj<TOAS>>
@@ -1,75 +0,0 @@
1
- import type { OasTypes } from '@kubb/swagger/oas'
2
- import type { Fn, Pipe, Tuples } from 'hotscript'
3
- import type { FromSchema, JSONSchema } from 'json-schema-to-ts'
4
-
5
- type Checks<TParamType = never> = {
6
- Required: { required: true }
7
-
8
- Schemas: {
9
- schema: JSONSchema
10
- }
11
- Enum: { type: JSONSchemaTypeName; enum?: any[] }
12
- Parameters: { in: string; required?: boolean }[]
13
- SingleParameter: [{ in: TParamType; required?: true }]
14
- Responses: { responses: any }
15
- }
16
-
17
- export type PathMap<TOAS extends OasTypes.OASDocument> = TOAS['paths']
18
-
19
- interface ParamPropMap {
20
- query: 'query'
21
- path: 'params'
22
- header: 'headers'
23
- }
24
-
25
- type JSONSchemaTypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null'
26
-
27
- type ParamObj<
28
- TParameter extends {
29
- name: string
30
- },
31
- > = TParameter extends Checks['Required']
32
- ? {
33
- [TName in TParameter['name']]: TParameter extends Checks['Schemas']
34
- ? FromSchema<TParameter['schema']>
35
- : TParameter extends Checks['Enum']
36
- ? FromSchema<{
37
- type: TParameter['type']
38
- enum: TParameter['enum']
39
- }>
40
- : unknown
41
- }
42
- : {
43
- [TName in TParameter['name']]?: TParameter extends Checks['Schemas']
44
- ? FromSchema<TParameter['schema']>
45
- : TParameter extends Checks['Enum']
46
- ? FromSchema<{
47
- type: TParameter['type']
48
- enum: TParameter['enum']
49
- }>
50
- : unknown
51
- }
52
-
53
- interface ParamToRequestParam<TParameters extends Checks['Parameters']> extends Fn {
54
- return: this['arg0'] extends { name: string; in: infer TParamType }
55
- ? // If there is any required parameter for this parameter type, make that parameter type required
56
- TParameters extends Checks<TParamType>['SingleParameter']
57
- ? {
58
- [TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]: ParamObj<this['arg0']>
59
- }
60
- : {
61
- [TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]?: ParamObj<this['arg0']>
62
- }
63
- : {}
64
- }
65
-
66
- export type ParamMap<TParameters extends Checks['Parameters']> = Pipe<TParameters, [Tuples.Map<ParamToRequestParam<TParameters>>, Tuples.ToIntersection]>
67
-
68
- export type MethodMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>> = PathMap<TOAS>[TPath]
69
-
70
- export type StatusMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = MethodMap<
71
- TOAS,
72
- TPath
73
- >[TMethod] extends Checks['Responses']
74
- ? MethodMap<TOAS, TPath>[TMethod]['responses']
75
- : never
package/src/oas/model.ts DELETED
@@ -1,38 +0,0 @@
1
- import type { OasTypes } from '@kubb/swagger/oas'
2
- import type { FromSchema, JSONSchema } from 'json-schema-to-ts'
3
-
4
- type Checks<TName extends string | number | symbol = never> = {
5
- ModelWithSchemas: {
6
- components: {
7
- schemas: Record<string, JSONSchema>
8
- }
9
- }
10
- ModelWithSchemasNamed: {
11
- components: {
12
- schemas: {
13
- [TModelName in TName]: JSONSchema
14
- }
15
- }
16
- }
17
- ModelWithDefinitions: {
18
- definitions: Record<string, JSONSchema>
19
- }
20
- ModelWithDefinitionsNamed: {
21
- definitions: {
22
- [TModelName in TName]: JSONSchema
23
- }
24
- }
25
- }
26
-
27
- export type Model<
28
- TOAS extends OasTypes.OASDocument,
29
- TName extends TOAS extends Checks['ModelWithSchemas']
30
- ? keyof TOAS['components']['schemas']
31
- : TOAS extends Checks['ModelWithDefinitions']
32
- ? keyof TOAS['definitions']
33
- : never,
34
- > = TOAS extends Checks<TName>['ModelWithSchemasNamed']
35
- ? FromSchema<TOAS['components']['schemas'][TName]>
36
- : TOAS extends Checks<TName>['ModelWithDefinitionsNamed']
37
- ? FromSchema<TOAS['definitions'][TName]>
38
- : never