@kubb/swagger-ts 2.4.0 → 2.5.0
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/{chunk-FUVECZEQ.cjs → chunk-FLSA5Y4E.cjs} +38 -23
- package/dist/chunk-FLSA5Y4E.cjs.map +1 -0
- package/dist/{chunk-FCNKYMOH.js → chunk-P4BOGC6U.js} +38 -23
- package/dist/chunk-P4BOGC6U.js.map +1 -0
- package/dist/components.cjs +4 -4
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{index-sycg8owy.d.cts → index-x0xIwSiH.d.cts} +75 -75
- package/dist/{index-sycg8owy.d.ts → index-x0xIwSiH.d.ts} +75 -75
- package/dist/index.cjs +9 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +574 -7
- package/dist/index.d.ts +574 -7
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/dist/oas.d.cts +1 -1
- package/dist/oas.d.ts +1 -1
- package/dist/{types-ZlpJhb2p.d.cts → types-Y_otwxvd.d.cts} +8 -2
- package/dist/{types-ZlpJhb2p.d.ts → types-Y_otwxvd.d.ts} +8 -2
- package/package.json +9 -9
- package/src/TypeGenerator.ts +16 -9
- package/src/components/Query.tsx +17 -12
- package/src/index.ts +1 -4
- package/src/oas/infer.ts +9 -10
- package/src/oas/mappers.ts +16 -17
- package/src/oas/model.ts +9 -10
- package/src/oas/requestParams.ts +14 -16
- package/src/oas/response.ts +3 -4
- package/src/oas/security.ts +20 -20
- package/src/plugin.ts +5 -3
- package/src/types.ts +8 -2
- package/dist/chunk-FCNKYMOH.js.map +0 -1
- package/dist/chunk-FUVECZEQ.cjs.map +0 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kubb/swagger-ts",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.5.0",
|
4
4
|
"description": "Generator swagger-ts",
|
5
5
|
"keywords": [
|
6
6
|
"typescript",
|
@@ -49,11 +49,11 @@
|
|
49
49
|
"hotscript": "^1.0.13",
|
50
50
|
"json-schema-to-ts": "^3.0.0",
|
51
51
|
"ts-toolbelt": "^9.6.0",
|
52
|
-
"@kubb/core": "2.
|
53
|
-
"@kubb/parser": "2.
|
54
|
-
"@kubb/
|
55
|
-
"@kubb/types": "2.
|
56
|
-
"@kubb/
|
52
|
+
"@kubb/core": "2.5.0",
|
53
|
+
"@kubb/parser": "2.5.0",
|
54
|
+
"@kubb/react": "2.5.0",
|
55
|
+
"@kubb/types": "2.5.0",
|
56
|
+
"@kubb/swagger": "2.5.0"
|
57
57
|
},
|
58
58
|
"devDependencies": {
|
59
59
|
"@types/react": "^18.2.48",
|
@@ -62,11 +62,11 @@
|
|
62
62
|
"react": "^18.2.0",
|
63
63
|
"tsup": "^8.0.1",
|
64
64
|
"@kubb/eslint-config": "1.1.8",
|
65
|
-
"@kubb/
|
66
|
-
"@kubb/
|
65
|
+
"@kubb/ts-config": "0.1.0",
|
66
|
+
"@kubb/tsup-config": "1.1.8"
|
67
67
|
},
|
68
68
|
"peerDependencies": {
|
69
|
-
"@kubb/react": "2.
|
69
|
+
"@kubb/react": "2.5.0"
|
70
70
|
},
|
71
71
|
"packageManager": "pnpm@8.3.0",
|
72
72
|
"engines": {
|
package/src/TypeGenerator.ts
CHANGED
@@ -142,11 +142,9 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
142
142
|
schema.default !== undefined && typeof schema.default !== 'string' ? `@default ${schema.default as string}` : undefined,
|
143
143
|
].filter(Boolean),
|
144
144
|
})
|
145
|
-
|
146
|
-
return propertySignature
|
147
145
|
})
|
148
146
|
if (additionalProperties) {
|
149
|
-
const type = additionalProperties === true ?
|
147
|
+
const type = additionalProperties === true ? this.#unknownReturn : this.getTypeFromSchema(additionalProperties as OasTypes.SchemaObject)
|
150
148
|
|
151
149
|
if (type) {
|
152
150
|
members.push(factory.createIndexSignature(type))
|
@@ -174,7 +172,8 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
174
172
|
originalName,
|
175
173
|
}
|
176
174
|
|
177
|
-
const
|
175
|
+
const fileName = this.context.pluginManager.resolveName({ name: originalName, pluginKey, type: 'file' })
|
176
|
+
const path = this.context.pluginManager.resolvePath({ baseName: fileName, pluginKey })
|
178
177
|
|
179
178
|
this.imports.push({
|
180
179
|
ref,
|
@@ -201,7 +200,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
201
200
|
const { schema, version } = this.#getParsedSchema(_schema)
|
202
201
|
|
203
202
|
if (!schema) {
|
204
|
-
return
|
203
|
+
return this.#unknownReturn
|
205
204
|
}
|
206
205
|
|
207
206
|
if (isReference(schema)) {
|
@@ -219,7 +218,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
219
218
|
return item && this.getTypeFromSchema(item as OasTypes.SchemaObject)
|
220
219
|
})
|
221
220
|
.filter((item) => {
|
222
|
-
return item && item !==
|
221
|
+
return item && item !== this.#unknownReturn
|
223
222
|
}) as Array<ts.TypeNode>,
|
224
223
|
})
|
225
224
|
|
@@ -242,7 +241,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
242
241
|
return item && this.getTypeFromSchema(item as OasTypes.SchemaObject)
|
243
242
|
})
|
244
243
|
.filter((item) => {
|
245
|
-
return item && item !==
|
244
|
+
return item && item !== this.#unknownReturn
|
246
245
|
}) as Array<ts.TypeNode>,
|
247
246
|
})
|
248
247
|
|
@@ -265,7 +264,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
265
264
|
return item && this.getTypeFromSchema(item as OasTypes.SchemaObject)
|
266
265
|
})
|
267
266
|
.filter((item) => {
|
268
|
-
return item && item !==
|
267
|
+
return item && item !== this.#unknownReturn
|
269
268
|
}) as Array<ts.TypeNode>,
|
270
269
|
})
|
271
270
|
|
@@ -401,6 +400,14 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
401
400
|
return factory.createTypeReferenceNode('Blob', [])
|
402
401
|
}
|
403
402
|
|
404
|
-
return
|
403
|
+
return this.#unknownReturn
|
404
|
+
}
|
405
|
+
|
406
|
+
get #unknownReturn() {
|
407
|
+
if (this.options.unknownType === 'any') {
|
408
|
+
return factory.keywordTypeNodes.any
|
409
|
+
}
|
410
|
+
|
411
|
+
return factory.keywordTypeNodes.unknown
|
405
412
|
}
|
406
413
|
}
|
package/src/components/Query.tsx
CHANGED
@@ -64,19 +64,24 @@ function printCombinedSchema(name: string, operation: Operation, schemas: Operat
|
|
64
64
|
})!
|
65
65
|
}
|
66
66
|
|
67
|
-
const namespaceNode = factory.
|
67
|
+
const namespaceNode = factory.createTypeAliasDeclaration({
|
68
68
|
name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
69
|
+
type: factory.createTypeLiteralNode(
|
70
|
+
Object.keys(properties).map(key => {
|
71
|
+
const type = properties[key]
|
72
|
+
if (!type) {
|
73
|
+
return undefined
|
74
|
+
}
|
75
|
+
|
76
|
+
return factory.createPropertySignature(
|
77
|
+
{
|
78
|
+
name: transformers.pascalCase(key),
|
79
|
+
type,
|
80
|
+
},
|
81
|
+
)
|
82
|
+
}).filter(Boolean),
|
83
|
+
),
|
84
|
+
modifiers: [factory.modifiers.export],
|
80
85
|
})
|
81
86
|
|
82
87
|
return print(namespaceNode)
|
package/src/index.ts
CHANGED
package/src/oas/infer.ts
CHANGED
@@ -1,30 +1,29 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
2
1
|
import type { Booleans, Call, Objects, Strings, Tuples } from 'hotscript'
|
3
2
|
import type { Object } from 'ts-toolbelt'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
type Checks = {
|
5
|
+
AllOFf: { allOf: any[] }
|
6
|
+
Object: {
|
8
7
|
type: 'object'
|
9
8
|
properties: any
|
10
9
|
}
|
11
|
-
|
12
|
-
|
10
|
+
Properties: { properties: any }
|
11
|
+
PropertiesRequired: {
|
13
12
|
properties: Record<string, any>
|
14
13
|
required: string[]
|
15
14
|
}
|
16
15
|
}
|
17
16
|
|
18
|
-
type FixAdditionalPropertiesForAllOf<T> = T extends Checks
|
17
|
+
type FixAdditionalPropertiesForAllOf<T> = T extends Checks['AllOFf'] ? Omit<T, 'allOf'> & {
|
19
18
|
allOf: Call<Tuples.Map<Objects.Omit<'additionalProperties'>>, T['allOf']>
|
20
19
|
}
|
21
20
|
: T
|
22
21
|
|
23
|
-
type FixMissingAdditionalProperties<T> = T extends Checks
|
22
|
+
type FixMissingAdditionalProperties<T> = T extends Checks['Object'] ? Omit<T, 'additionalProperties'> & { additionalProperties: false }
|
24
23
|
: T
|
25
|
-
type FixMissingTypeObject<T> = T extends Checks
|
24
|
+
type FixMissingTypeObject<T> = T extends Checks['Properties'] ? T & { type: 'object' } : T
|
26
25
|
|
27
|
-
type FixExtraRequiredFields<T> = T extends Checks
|
26
|
+
type FixExtraRequiredFields<T> = T extends Checks['PropertiesRequired'] ? Omit<T, 'required'> & {
|
28
27
|
required: Call<Tuples.Filter<Booleans.Extends<keyof T['properties']>>, T['required']>
|
29
28
|
}
|
30
29
|
: T
|
package/src/oas/mappers.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
2
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
3
2
|
import type { OasTypes } from '@kubb/swagger/oas'
|
4
3
|
import type { Fn, Pipe, Tuples } from 'hotscript'
|
5
4
|
import type {
|
@@ -7,16 +6,16 @@ import type {
|
|
7
6
|
JSONSchema,
|
8
7
|
} from 'json-schema-to-ts'
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
type Checks<TParamType = never> = {
|
10
|
+
Required: { required: true }
|
12
11
|
|
13
|
-
|
12
|
+
Schemas: {
|
14
13
|
schema: JSONSchema
|
15
14
|
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
Enum: { type: JSONSchemaTypeName; enum?: any[] }
|
16
|
+
Parameters: { in: string; required?: boolean }[]
|
17
|
+
SingleParameter: [{ in: TParamType; required?: true }]
|
18
|
+
Responses: { responses: any }
|
20
19
|
}
|
21
20
|
|
22
21
|
export type PathMap<TOAS extends OasTypes.OASDocument> = TOAS['paths']
|
@@ -40,27 +39,27 @@ type ParamObj<
|
|
40
39
|
TParameter extends {
|
41
40
|
name: string
|
42
41
|
},
|
43
|
-
> = TParameter extends Checks
|
44
|
-
[TName in TParameter['name']]: TParameter extends Checks
|
45
|
-
: TParameter extends Checks
|
42
|
+
> = TParameter extends Checks['Required'] ? {
|
43
|
+
[TName in TParameter['name']]: TParameter extends Checks['Schemas'] ? FromSchema<TParameter['schema']>
|
44
|
+
: TParameter extends Checks['Enum'] ? FromSchema<{
|
46
45
|
type: TParameter['type']
|
47
46
|
enum: TParameter['enum']
|
48
47
|
}>
|
49
48
|
: unknown
|
50
49
|
}
|
51
50
|
: {
|
52
|
-
[TName in TParameter['name']]?: TParameter extends Checks
|
53
|
-
: TParameter extends Checks
|
51
|
+
[TName in TParameter['name']]?: TParameter extends Checks['Schemas'] ? FromSchema<TParameter['schema']>
|
52
|
+
: TParameter extends Checks['Enum'] ? FromSchema<{
|
54
53
|
type: TParameter['type']
|
55
54
|
enum: TParameter['enum']
|
56
55
|
}>
|
57
56
|
: unknown
|
58
57
|
}
|
59
58
|
|
60
|
-
interface ParamToRequestParam<TParameters extends Checks
|
59
|
+
interface ParamToRequestParam<TParameters extends Checks['Parameters']> extends Fn {
|
61
60
|
return: this['arg0'] extends { name: string; in: infer TParamType }
|
62
61
|
// If there is any required parameter for this parameter type, make that parameter type required
|
63
|
-
? TParameters extends Checks
|
62
|
+
? TParameters extends Checks<TParamType>['SingleParameter'] ? {
|
64
63
|
[
|
65
64
|
TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType]
|
66
65
|
: never
|
@@ -75,7 +74,7 @@ interface ParamToRequestParam<TParameters extends Checks.Parameters> extends Fn
|
|
75
74
|
: {}
|
76
75
|
}
|
77
76
|
|
78
|
-
export type ParamMap<TParameters extends Checks
|
77
|
+
export type ParamMap<TParameters extends Checks['Parameters']> = Pipe<
|
79
78
|
TParameters,
|
80
79
|
[Tuples.Map<ParamToRequestParam<TParameters>>, Tuples.ToIntersection]
|
81
80
|
>
|
@@ -89,5 +88,5 @@ export type StatusMap<
|
|
89
88
|
TOAS extends OasTypes.OASDocument,
|
90
89
|
TPath extends keyof PathMap<TOAS>,
|
91
90
|
TMethod extends keyof MethodMap<TOAS, TPath>,
|
92
|
-
> = MethodMap<TOAS, TPath>[TMethod] extends Checks
|
91
|
+
> = MethodMap<TOAS, TPath>[TMethod] extends Checks['Responses'] ? MethodMap<TOAS, TPath>[TMethod]['responses']
|
93
92
|
: never
|
package/src/oas/model.ts
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
2
1
|
import type { OasTypes } from '@kubb/swagger/oas'
|
3
2
|
import type {
|
4
3
|
FromSchema,
|
5
4
|
JSONSchema,
|
6
5
|
} from 'json-schema-to-ts'
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
type Checks<TName extends string | number | symbol = never> = {
|
8
|
+
ModelWithSchemas: {
|
10
9
|
components: {
|
11
10
|
schemas: Record<string, JSONSchema>
|
12
11
|
}
|
13
12
|
}
|
14
|
-
|
13
|
+
ModelWithSchemasNamed: {
|
15
14
|
components: {
|
16
15
|
schemas: {
|
17
16
|
[TModelName in TName]: JSONSchema
|
18
17
|
}
|
19
18
|
}
|
20
19
|
}
|
21
|
-
|
20
|
+
ModelWithDefinitions: {
|
22
21
|
definitions: Record<string, JSONSchema>
|
23
22
|
}
|
24
|
-
|
23
|
+
ModelWithDefinitionsNamed: {
|
25
24
|
definitions: {
|
26
25
|
[TModelName in TName]: JSONSchema
|
27
26
|
}
|
@@ -30,9 +29,9 @@ namespace Checks {
|
|
30
29
|
|
31
30
|
export type Model<
|
32
31
|
TOAS extends OasTypes.OASDocument,
|
33
|
-
TName extends TOAS extends Checks
|
34
|
-
: TOAS extends Checks
|
32
|
+
TName extends TOAS extends Checks['ModelWithSchemas'] ? keyof TOAS['components']['schemas']
|
33
|
+
: TOAS extends Checks['ModelWithDefinitions'] ? keyof TOAS['definitions']
|
35
34
|
: never,
|
36
|
-
> = TOAS extends Checks
|
37
|
-
: TOAS extends Checks
|
35
|
+
> = TOAS extends Checks<TName>['ModelWithSchemasNamed'] ? FromSchema<TOAS['components']['schemas'][TName]>
|
36
|
+
: TOAS extends Checks<TName>['ModelWithDefinitionsNamed'] ? FromSchema<TOAS['definitions'][TName]>
|
38
37
|
: never
|
package/src/oas/requestParams.ts
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
2
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
3
|
-
|
4
2
|
import type { OasTypes } from '@kubb/swagger/oas'
|
5
3
|
import type { SplitByDelimiter, TupleToUnion } from '@kubb/types'
|
6
4
|
import type { Pipe, Strings, Tuples } from 'hotscript'
|
@@ -11,28 +9,28 @@ import type {
|
|
11
9
|
import type { MethodMap, ParamMap, PathMap } from './mappers.ts'
|
12
10
|
import type { SecurityParamsBySecurityRef } from './security.ts'
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
type Checks = {
|
13
|
+
RequestBodyJson: {
|
16
14
|
requestBody: { content: { 'application/json': { schema: JSONSchema } } }
|
17
15
|
}
|
18
|
-
|
16
|
+
RequestBodyFormData: {
|
19
17
|
requestBody: {
|
20
18
|
content: { 'multipart/form-data': { schema: JSONSchema } }
|
21
19
|
}
|
22
20
|
}
|
23
|
-
|
21
|
+
RequestBodyFormEncoded: {
|
24
22
|
requestBody: {
|
25
23
|
content: {
|
26
24
|
'application/x-www-form-urlencoded': { schema: JSONSchema }
|
27
25
|
}
|
28
26
|
}
|
29
27
|
}
|
30
|
-
|
28
|
+
Parameters: {
|
31
29
|
parameters: { name: string; in: string }[]
|
32
30
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
PathBrackets: `${string}{${string}}${string}`
|
32
|
+
PathPattern: `${string}:${string}${string}`
|
33
|
+
Required: { required: true }
|
36
34
|
}
|
37
35
|
|
38
36
|
type ExtractPathParamsWithPattern<TPath extends string> = Pipe<
|
@@ -66,7 +64,7 @@ export type RequestParams<
|
|
66
64
|
TPath extends keyof PathMap<TOAS>,
|
67
65
|
TMethod extends keyof MethodMap<TOAS, TPath>,
|
68
66
|
> =
|
69
|
-
& (MethodMap<TOAS, TPath>[TMethod] extends Checks
|
67
|
+
& (MethodMap<TOAS, TPath>[TMethod] extends Checks['RequestBodyJson'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks['Required'] ? {
|
70
68
|
/**
|
71
69
|
* The request body in JSON is required for this request.
|
72
70
|
*
|
@@ -86,7 +84,7 @@ export type RequestParams<
|
|
86
84
|
MethodMap<TOAS, TPath>[TMethod]['requestBody']['content']['application/json']['schema']
|
87
85
|
>
|
88
86
|
}
|
89
|
-
: MethodMap<TOAS, TPath>[TMethod] extends Checks
|
87
|
+
: MethodMap<TOAS, TPath>[TMethod] extends Checks['RequestBodyFormData'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks['Required'] ? {
|
90
88
|
/**
|
91
89
|
* The request body in multipart/form-data is required for this request.
|
92
90
|
*
|
@@ -112,7 +110,7 @@ export type RequestParams<
|
|
112
110
|
>[TMethod]['requestBody']['content']['multipart/form-data']['schema']
|
113
111
|
>
|
114
112
|
}
|
115
|
-
: MethodMap<TOAS, TPath>[TMethod] extends Checks
|
113
|
+
: MethodMap<TOAS, TPath>[TMethod] extends Checks['RequestBodyFormEncoded'] ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks['Required'] ? {
|
116
114
|
/**
|
117
115
|
* The request body in application/x-www-form-urlencoded is required for this request.
|
118
116
|
*
|
@@ -139,10 +137,10 @@ export type RequestParams<
|
|
139
137
|
>
|
140
138
|
}
|
141
139
|
: {})
|
142
|
-
& (MethodMap<TOAS, TPath>[TMethod] extends Checks
|
140
|
+
& (MethodMap<TOAS, TPath>[TMethod] extends Checks['Parameters'] ? ParamMap<MethodMap<TOAS, TPath>[TMethod]['parameters']>
|
143
141
|
: {})
|
144
142
|
& // If there is any parameters defined in path but not in the parameters array, we should add them to the params
|
145
|
-
(TPath extends Checks
|
143
|
+
(TPath extends Checks['PathBrackets'] ? {
|
146
144
|
/**
|
147
145
|
* Parameters defined in the path are required for this request.
|
148
146
|
*
|
@@ -153,7 +151,7 @@ export type RequestParams<
|
|
153
151
|
params: Record<ExtractPathParamsWithBrackets<TPath>, string | number | bigint | boolean>
|
154
152
|
}
|
155
153
|
: {})
|
156
|
-
& (TPath extends Checks
|
154
|
+
& (TPath extends Checks['PathPattern'] ? {
|
157
155
|
/**
|
158
156
|
* Parameters defined in the path are required for this request.
|
159
157
|
*
|
package/src/oas/response.ts
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
2
1
|
import type { OasTypes } from '@kubb/swagger/oas'
|
3
2
|
import type {
|
4
3
|
FromSchema,
|
5
4
|
} from 'json-schema-to-ts'
|
6
5
|
import type { MethodMap, PathMap, StatusMap } from './mappers.ts'
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
type Checks = {
|
8
|
+
Content: { content: any }
|
10
9
|
}
|
11
10
|
|
12
11
|
type ResponseSchemas<
|
@@ -21,7 +20,7 @@ type JSONResponseSchema<
|
|
21
20
|
TPath extends keyof PathMap<TOAS>,
|
22
21
|
TMethod extends keyof MethodMap<TOAS, TPath>,
|
23
22
|
TStatus extends keyof StatusMap<TOAS, TPath, TMethod>,
|
24
|
-
> = StatusMap<TOAS, TPath, TMethod>[TStatus] extends Checks
|
23
|
+
> = StatusMap<TOAS, TPath, TMethod>[TStatus] extends Checks['Content'] ? ResponseSchemas<TOAS, TPath, TMethod, TStatus>[
|
25
24
|
keyof ResponseSchemas<
|
26
25
|
TOAS,
|
27
26
|
TPath,
|
package/src/oas/security.ts
CHANGED
@@ -3,46 +3,46 @@
|
|
3
3
|
|
4
4
|
import type { Call, Objects, Tuples } from 'hotscript'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
type Checks = {
|
7
|
+
Security: { security: { [key: string]: any }[] }
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
AuthParams: {
|
10
|
+
Basic:
|
11
11
|
| {
|
12
12
|
type: 'http'
|
13
13
|
scheme: 'basic'
|
14
14
|
}
|
15
15
|
| { type: 'basic' }
|
16
|
-
|
16
|
+
Bearer:
|
17
17
|
| {
|
18
18
|
type: 'http'
|
19
19
|
scheme: 'bearer'
|
20
20
|
}
|
21
21
|
| { type: 'bearer' }
|
22
22
|
|
23
|
-
|
23
|
+
OAuth2: {
|
24
24
|
type: 'oauth2'
|
25
25
|
}
|
26
|
-
|
26
|
+
ApiKey: {
|
27
27
|
type: 'apiKey'
|
28
28
|
in: 'header'
|
29
29
|
}
|
30
30
|
}
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
AuthName: {
|
33
|
+
Basic: `basic${string}`
|
34
|
+
Bearer: `bearer${string}`
|
35
|
+
OAuth2: `oauth${string}`
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
type SecuritySchemeName<T extends Checks
|
39
|
+
type SecuritySchemeName<T extends Checks['Security']> = Call<
|
40
40
|
Tuples.Map<Objects.Keys>,
|
41
41
|
T['security']
|
42
42
|
>[number]
|
43
43
|
|
44
44
|
namespace AuthParams {
|
45
|
-
export type Basic<TSecurityScheme> = TSecurityScheme extends Checks
|
45
|
+
export type Basic<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['Basic'] ? {
|
46
46
|
headers: {
|
47
47
|
/**
|
48
48
|
* `Authorization` header is required for basic authentication
|
@@ -60,7 +60,7 @@ namespace AuthParams {
|
|
60
60
|
}
|
61
61
|
: {}
|
62
62
|
|
63
|
-
export type Bearer<TSecurityScheme> = TSecurityScheme extends Checks
|
63
|
+
export type Bearer<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['Bearer'] ? {
|
64
64
|
/**
|
65
65
|
* `Authorization` header is required for bearer authentication
|
66
66
|
* @see https://swagger.io/docs/specification/authentication/bearer-authentication/
|
@@ -79,7 +79,7 @@ namespace AuthParams {
|
|
79
79
|
}
|
80
80
|
: {}
|
81
81
|
|
82
|
-
export type ApiKey<TSecurityScheme> = TSecurityScheme extends Checks
|
82
|
+
export type ApiKey<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['ApiKey'] & { name: infer TApiKeyHeaderName } ? {
|
83
83
|
headers: {
|
84
84
|
/**
|
85
85
|
* Header required for API key authentication
|
@@ -101,7 +101,7 @@ namespace AuthParams {
|
|
101
101
|
}
|
102
102
|
: {}
|
103
103
|
|
104
|
-
export type OAuth2<TSecurityScheme> = TSecurityScheme extends Checks
|
104
|
+
export type OAuth2<TSecurityScheme> = TSecurityScheme extends Checks['AuthParams']['OAuth2'] ? {
|
105
105
|
/**
|
106
106
|
* `Authorization` header is required for OAuth2.
|
107
107
|
*/
|
@@ -122,7 +122,7 @@ type OASSecurityParams<TSecurityScheme> =
|
|
122
122
|
& AuthParams.ApiKey<TSecurityScheme>
|
123
123
|
& AuthParams.OAuth2<TSecurityScheme>
|
124
124
|
|
125
|
-
export type SecurityParamsBySecurityRef<TOAS, TSecurityObj> = TSecurityObj extends Checks
|
125
|
+
export type SecurityParamsBySecurityRef<TOAS, TSecurityObj> = TSecurityObj extends Checks['Security'] ? TOAS extends
|
126
126
|
| {
|
127
127
|
components: {
|
128
128
|
securitySchemes: {
|
@@ -143,15 +143,15 @@ export type SecurityParamsBySecurityRef<TOAS, TSecurityObj> = TSecurityObj exten
|
|
143
143
|
} ? OASSecurityParams<TSecurityScheme>
|
144
144
|
// OAS may have a bad reference to a security scheme
|
145
145
|
// So we can assume it
|
146
|
-
: SecuritySchemeName<TSecurityObj> extends Checks
|
146
|
+
: SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['Basic'] ? AuthParams.Basic<{
|
147
147
|
type: 'http'
|
148
148
|
scheme: 'basic'
|
149
149
|
}>
|
150
|
-
: SecuritySchemeName<TSecurityObj> extends Checks
|
150
|
+
: SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['Bearer'] ? AuthParams.Bearer<{
|
151
151
|
type: 'http'
|
152
152
|
scheme: 'bearer'
|
153
153
|
}>
|
154
|
-
: SecuritySchemeName<TSecurityObj> extends Checks
|
154
|
+
: SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['OAuth2'] ? AuthParams.OAuth2<{
|
155
155
|
type: 'oauth2'
|
156
156
|
}>
|
157
157
|
: {}
|
package/src/plugin.ts
CHANGED
@@ -8,7 +8,7 @@ import { pluginName as swaggerPluginName } from '@kubb/swagger'
|
|
8
8
|
import { OperationGenerator } from './OperationGenerator.tsx'
|
9
9
|
import { TypeBuilder } from './TypeBuilder.ts'
|
10
10
|
|
11
|
-
import type { KubbFile,
|
11
|
+
import type { KubbFile, Plugin } from '@kubb/core'
|
12
12
|
import type { PluginOptions as SwaggerPluginOptions } from '@kubb/swagger'
|
13
13
|
import type { OasTypes } from '@kubb/swagger/oas'
|
14
14
|
import type { PluginOptions } from './types.ts'
|
@@ -24,6 +24,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
24
24
|
override = [],
|
25
25
|
enumType = 'asConst',
|
26
26
|
dateType = 'string',
|
27
|
+
unknownType = 'any',
|
27
28
|
optionalType = 'questionToken',
|
28
29
|
transformers = {},
|
29
30
|
oasType = false,
|
@@ -40,6 +41,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
40
41
|
oasType,
|
41
42
|
// keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)
|
42
43
|
usedEnumNames: {},
|
44
|
+
unknownType,
|
43
45
|
},
|
44
46
|
pre: [swaggerPluginName],
|
45
47
|
resolvePath(baseName, directory, options) {
|
@@ -63,7 +65,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
63
65
|
return path.resolve(root, output.path, baseName)
|
64
66
|
},
|
65
67
|
resolveName(name, type) {
|
66
|
-
const resolvedName = pascalCase(name)
|
68
|
+
const resolvedName = pascalCase(name, { isFile: type === 'file' })
|
67
69
|
|
68
70
|
if (type) {
|
69
71
|
return transformers?.name?.(resolvedName, type) || resolvedName
|
@@ -79,7 +81,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
79
81
|
return this.fileManager.write(source, writePath, { sanity: false })
|
80
82
|
},
|
81
83
|
async buildStart() {
|
82
|
-
const [swaggerPlugin]: [
|
84
|
+
const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [swaggerPluginName])
|
83
85
|
|
84
86
|
const oas = await swaggerPlugin.api.getOas()
|
85
87
|
|
package/src/types.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { KubbFile,
|
1
|
+
import type { KubbFile, Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
2
2
|
import type { AppMeta as SwaggerAppMeta, Exclude, Include, Override, ResolvePathOptions } from '@kubb/swagger'
|
3
3
|
|
4
4
|
export type Options = {
|
@@ -62,6 +62,11 @@ export type Options = {
|
|
62
62
|
* @default 'string'
|
63
63
|
*/
|
64
64
|
dateType?: 'string' | 'date'
|
65
|
+
/**
|
66
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
67
|
+
* @default 'any'
|
68
|
+
*/
|
69
|
+
unknownType?: 'any' | 'unknown'
|
65
70
|
/**
|
66
71
|
* Choose what to use as mode for an optional value.
|
67
72
|
* @examples 'questionToken': type?: string
|
@@ -85,6 +90,7 @@ export type Options = {
|
|
85
90
|
type ResolvedOptions = {
|
86
91
|
enumType: NonNullable<Options['enumType']>
|
87
92
|
dateType: NonNullable<Options['dateType']>
|
93
|
+
unknownType: NonNullable<Options['unknownType']>
|
88
94
|
optionalType: NonNullable<Options['optionalType']>
|
89
95
|
transformers: NonNullable<Options['transformers']>
|
90
96
|
oasType: NonNullable<Options['oasType']>
|
@@ -92,7 +98,7 @@ type ResolvedOptions = {
|
|
92
98
|
}
|
93
99
|
|
94
100
|
export type FileMeta = {
|
95
|
-
pluginKey?:
|
101
|
+
pluginKey?: Plugin['key']
|
96
102
|
name?: string
|
97
103
|
tag?: string
|
98
104
|
}
|