@kubb/swagger-ts 2.0.0-beta.8 → 2.0.0-beta.9
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/components.cjs +2 -2
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +1 -3
- package/dist/components.d.ts +1 -3
- package/dist/components.js +2 -2
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -62
- package/dist/index.d.ts +60 -62
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/{infer.d.ts → oas.d.ts} +56 -56
- package/dist/{infer.js → oas.js} +1 -1
- package/package.json +11 -11
- package/src/components/Oas.tsx +2 -2
- package/src/{infer → oas}/index.ts +1 -1
- package/src/{infer/parse.ts → oas/infer.ts} +1 -1
- package/src/types.ts +2 -4
- /package/dist/{infer.js.map → oas.js.map} +0 -0
- /package/src/{infer → oas}/mappers.ts +0 -0
- /package/src/{infer → oas}/model.ts +0 -0
- /package/src/{infer → oas}/requestParams.ts +0 -0
- /package/src/{infer → oas}/response.ts +0 -0
- /package/src/{infer → oas}/security.ts +0 -0
@@ -1,10 +1,54 @@
|
|
1
|
+
import { Call, Tuples, Objects, Booleans, Strings, Pipe, Fn } from 'hotscript';
|
2
|
+
import { Object as Object$1 } from 'ts-toolbelt';
|
1
3
|
import { OasTypes } from '@kubb/swagger';
|
2
|
-
import { Pipe, Tuples, Fn, Call, Objects, Booleans, Strings } from 'hotscript';
|
3
4
|
import { JSONSchema, FromSchema } from 'json-schema-to-ts';
|
4
|
-
import { Object as Object$1 } from 'ts-toolbelt';
|
5
5
|
import { TupleToUnion, SplitByDelimiter } from '@kubb/types';
|
6
6
|
|
7
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 {
|
8
52
|
type Required = {
|
9
53
|
required: true;
|
10
54
|
};
|
@@ -36,35 +80,35 @@ interface ParamPropMap {
|
|
36
80
|
type JSONSchemaTypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
37
81
|
type ParamObj<TParameter extends {
|
38
82
|
name: string;
|
39
|
-
}> = TParameter extends Checks$
|
40
|
-
[TName in TParameter['name']]: TParameter extends Checks$
|
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<{
|
41
85
|
type: TParameter['type'];
|
42
86
|
enum: TParameter['enum'];
|
43
87
|
}> : unknown;
|
44
88
|
} : {
|
45
|
-
[TName in TParameter['name']]?: TParameter extends Checks$
|
89
|
+
[TName in TParameter['name']]?: TParameter extends Checks$4.Schemas ? FromSchema<TParameter['schema']> : TParameter extends Checks$4.Enum ? FromSchema<{
|
46
90
|
type: TParameter['type'];
|
47
91
|
enum: TParameter['enum'];
|
48
92
|
}> : unknown;
|
49
93
|
};
|
50
|
-
interface ParamToRequestParam<TParameters extends Checks$
|
94
|
+
interface ParamToRequestParam<TParameters extends Checks$4.Parameters> extends Fn {
|
51
95
|
return: this['arg0'] extends {
|
52
96
|
name: string;
|
53
97
|
in: infer TParamType;
|
54
|
-
} ? TParameters extends Checks$
|
98
|
+
} ? TParameters extends Checks$4.SingleParameter<TParamType> ? {
|
55
99
|
[TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]: ParamObj<this['arg0']>;
|
56
100
|
} : {
|
57
101
|
[TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]?: ParamObj<this['arg0']>;
|
58
102
|
} : {};
|
59
103
|
}
|
60
|
-
type ParamMap<TParameters extends Checks$
|
104
|
+
type ParamMap<TParameters extends Checks$4.Parameters> = Pipe<TParameters, [
|
61
105
|
Tuples.Map<ParamToRequestParam<TParameters>>,
|
62
106
|
Tuples.ToIntersection
|
63
107
|
]>;
|
64
108
|
type MethodMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>> = PathMap<TOAS>[TPath];
|
65
|
-
type StatusMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = MethodMap<TOAS, TPath>[TMethod] extends Checks$
|
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;
|
66
110
|
|
67
|
-
declare namespace Checks$
|
111
|
+
declare namespace Checks$3 {
|
68
112
|
type ModelWithSchemas = {
|
69
113
|
components: {
|
70
114
|
schemas: Record<string, JSONSchema>;
|
@@ -86,51 +130,7 @@ declare namespace Checks$4 {
|
|
86
130
|
};
|
87
131
|
};
|
88
132
|
}
|
89
|
-
type Model<TOAS extends OasTypes.OASDocument, TName extends TOAS extends Checks$
|
90
|
-
|
91
|
-
declare namespace Checks$3 {
|
92
|
-
type AllOFf = {
|
93
|
-
allOf: any[];
|
94
|
-
};
|
95
|
-
type Object = {
|
96
|
-
type: 'object';
|
97
|
-
properties: any;
|
98
|
-
};
|
99
|
-
type Properties = {
|
100
|
-
properties: any;
|
101
|
-
};
|
102
|
-
type PropertiesRequired = {
|
103
|
-
properties: Record<string, any>;
|
104
|
-
required: string[];
|
105
|
-
};
|
106
|
-
}
|
107
|
-
type FixAdditionalPropertiesForAllOf<T> = T extends Checks$3.AllOFf ? Omit<T, 'allOf'> & {
|
108
|
-
allOf: Call<Tuples.Map<Objects.Omit<'additionalProperties'>>, T['allOf']>;
|
109
|
-
} : T;
|
110
|
-
type FixMissingAdditionalProperties<T> = T extends Checks$3.Object ? Omit<T, 'additionalProperties'> & {
|
111
|
-
additionalProperties: false;
|
112
|
-
} : T;
|
113
|
-
type FixMissingTypeObject<T> = T extends Checks$3.Properties ? T & {
|
114
|
-
type: 'object';
|
115
|
-
} : T;
|
116
|
-
type FixExtraRequiredFields<T> = T extends Checks$3.PropertiesRequired ? Omit<T, 'required'> & {
|
117
|
-
required: Call<Tuples.Filter<Booleans.Extends<keyof T['properties']>>, T['required']>;
|
118
|
-
} : T;
|
119
|
-
type FixJSONSchema<T> = FixAdditionalPropertiesForAllOf<FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>>;
|
120
|
-
type Mutable<Type> = FixJSONSchema<{
|
121
|
-
-readonly [Key in keyof Type]: Mutable<Type[Key]>;
|
122
|
-
}>;
|
123
|
-
type RefToPath<T extends string> = T extends `#/${infer Ref}` ? Call<Strings.Split<'/'>, Ref> : never;
|
124
|
-
type ResolveRef<TObj, TRef extends string> = {
|
125
|
-
$id: TRef;
|
126
|
-
} & Object$1.Path<TObj, RefToPath<TRef>>;
|
127
|
-
type ResolveRefInObj<T, TBase> = T extends {
|
128
|
-
$ref: infer Ref;
|
129
|
-
} ? Ref extends string ? ResolveRef<TBase, Ref> : T : T;
|
130
|
-
type ResolveRefsInObj<T, TBase = T> = {
|
131
|
-
[K in keyof T]: ResolveRefsInObj<ResolveRefInObj<T[K], TBase>, TBase>;
|
132
|
-
};
|
133
|
-
type Parse<TOAS> = Mutable<ResolveRefsInObj<TOAS>>;
|
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
134
|
|
135
135
|
declare namespace Checks$2 {
|
136
136
|
type Security = {
|
@@ -378,4 +378,4 @@ type ResponseSchemas<TOAS extends OasTypes.OASDocument, TPath extends keyof Path
|
|
378
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
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
380
|
|
381
|
-
export type { MethodMap, Model,
|
381
|
+
export type { Infer, MethodMap, Model, PathMap, RequestParams, Response, StatusMap };
|
package/dist/{infer.js → oas.js}
RENAMED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kubb/swagger-ts",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.9",
|
4
4
|
"description": "Generator swagger-ts",
|
5
5
|
"keywords": [
|
6
6
|
"typescript",
|
@@ -30,8 +30,8 @@
|
|
30
30
|
"require": "./dist/components.cjs",
|
31
31
|
"default": "./dist/components.cjs"
|
32
32
|
},
|
33
|
-
"./
|
34
|
-
"types": "./dist/
|
33
|
+
"./oas": {
|
34
|
+
"types": "./dist/oas.d.ts"
|
35
35
|
},
|
36
36
|
"./package.json": "./package.json",
|
37
37
|
"./*": "./*"
|
@@ -46,17 +46,17 @@
|
|
46
46
|
"!/**/__tests__/**"
|
47
47
|
],
|
48
48
|
"dependencies": {
|
49
|
-
"json-schema-to-ts": "^2.9.2",
|
50
49
|
"hotscript": "^1.0.13",
|
50
|
+
"json-schema-to-ts": "^2.9.2",
|
51
51
|
"ts-toolbelt": "^9.6.0",
|
52
|
-
"@kubb/core": "2.0.0-beta.
|
53
|
-
"@kubb/parser": "2.0.0-beta.
|
54
|
-
"@kubb/react": "2.0.0-beta.
|
55
|
-
"@kubb/
|
56
|
-
"@kubb/
|
52
|
+
"@kubb/core": "2.0.0-beta.9",
|
53
|
+
"@kubb/parser": "2.0.0-beta.9",
|
54
|
+
"@kubb/react": "2.0.0-beta.9",
|
55
|
+
"@kubb/swagger": "2.0.0-beta.9",
|
56
|
+
"@kubb/types": "2.0.0-beta.9"
|
57
57
|
},
|
58
58
|
"devDependencies": {
|
59
|
-
"@types/react": "^18.2.
|
59
|
+
"@types/react": "^18.2.39",
|
60
60
|
"eslint": "^8.54.0",
|
61
61
|
"expect-type": "^0.17.3",
|
62
62
|
"react": "^18.2.0",
|
@@ -66,7 +66,7 @@
|
|
66
66
|
"@kubb/tsup-config": "1.1.8"
|
67
67
|
},
|
68
68
|
"peerDependencies": {
|
69
|
-
"@kubb/react": "2.0.0-beta.
|
69
|
+
"@kubb/react": "2.0.0-beta.9"
|
70
70
|
},
|
71
71
|
"packageManager": "pnpm@8.3.0",
|
72
72
|
"engines": {
|
package/src/components/Oas.tsx
CHANGED
@@ -25,7 +25,7 @@ function Template({
|
|
25
25
|
{`export const ${name} = ${JSON.stringify(api, undefined, 2)} as const`}
|
26
26
|
<br />
|
27
27
|
<Type name={typeName} export>
|
28
|
-
{`
|
28
|
+
{`Infer<typeof ${name}>`}
|
29
29
|
</Type>
|
30
30
|
</>
|
31
31
|
)
|
@@ -73,7 +73,7 @@ Oas.File = function({ name, typeName, templates = defaultTemplates }: FileProps)
|
|
73
73
|
path={file.path}
|
74
74
|
meta={file.meta}
|
75
75
|
>
|
76
|
-
<File.Import name={['
|
76
|
+
<File.Import name={['Infer']} path="@kubb/swagger-ts/oas" isTypeOnly />
|
77
77
|
<File.Source>
|
78
78
|
<Oas Template={Template} name={name} typeName={typeName} />
|
79
79
|
</File.Source>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// based on https://github.com/ardatan/feTS/tree/master
|
2
2
|
|
3
|
+
export type { Infer } from './infer.ts'
|
3
4
|
export type { MethodMap, PathMap, StatusMap } from './mappers.ts'
|
4
5
|
export type { Model } from './model.ts'
|
5
|
-
export type { Parse } from './parse.ts'
|
6
6
|
export type { RequestParams } from './requestParams.ts'
|
7
7
|
export type { Response } from './response.ts'
|
package/src/types.ts
CHANGED
@@ -72,9 +72,7 @@ export type Options = {
|
|
72
72
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
73
73
|
}
|
74
74
|
/**
|
75
|
-
* Export Oas object as Oas type with import type { Infer } from
|
76
|
-
* TODO add docs
|
77
|
-
* @beta
|
75
|
+
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/swagger-ts/oas'`
|
78
76
|
*/
|
79
77
|
oasType?: boolean
|
80
78
|
}
|
@@ -104,4 +102,4 @@ declare module '@kubb/core' {
|
|
104
102
|
}
|
105
103
|
}
|
106
104
|
// external packages
|
107
|
-
export * as
|
105
|
+
export * as Oas from './oas/index.ts'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|