@kubb/swagger-ts 2.0.0-beta.1 → 2.0.0-beta.11

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