@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/swagger-ts",
3
- "version": "2.4.0",
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.4.0",
53
- "@kubb/parser": "2.4.0",
54
- "@kubb/swagger": "2.4.0",
55
- "@kubb/types": "2.4.0",
56
- "@kubb/react": "2.4.0"
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/tsup-config": "1.1.8",
66
- "@kubb/ts-config": "0.1.0"
65
+ "@kubb/ts-config": "0.1.0",
66
+ "@kubb/tsup-config": "1.1.8"
67
67
  },
68
68
  "peerDependencies": {
69
- "@kubb/react": "2.4.0"
69
+ "@kubb/react": "2.5.0"
70
70
  },
71
71
  "packageManager": "pnpm@8.3.0",
72
72
  "engines": {
@@ -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 ? factory.keywordTypeNodes.any : this.getTypeFromSchema(additionalProperties as OasTypes.SchemaObject)
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 path = this.context.pluginManager.resolvePath({ baseName: propertyName, pluginKey })
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 factory.keywordTypeNodes.any
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 !== factory.keywordTypeNodes.any
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 !== factory.keywordTypeNodes.any
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 !== factory.keywordTypeNodes.any
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 factory.keywordTypeNodes.any
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
  }
@@ -64,19 +64,24 @@ function printCombinedSchema(name: string, operation: Operation, schemas: Operat
64
64
  })!
65
65
  }
66
66
 
67
- const namespaceNode = factory.createNamespaceDeclaration({
67
+ const namespaceNode = factory.createTypeAliasDeclaration({
68
68
  name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,
69
- statements: Object.keys(properties).map(key => {
70
- const type = properties[key]
71
- if (!type) {
72
- return undefined
73
- }
74
- return factory.createTypeAliasDeclaration({
75
- modifiers: [factory.modifiers.export],
76
- name: transformers.pascalCase(key),
77
- type,
78
- })
79
- }).filter(Boolean),
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
@@ -1,6 +1,3 @@
1
- import { definePlugin } from './plugin.ts'
2
-
3
1
  export { definePlugin, pluginKey, pluginName } from './plugin.ts'
2
+ export { definePlugin as default } from './plugin.ts'
4
3
  export type * from './types.ts'
5
-
6
- export default definePlugin
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
- namespace Checks {
6
- export type AllOFf = { allOf: any[] }
7
- export type Object = {
4
+ type Checks = {
5
+ AllOFf: { allOf: any[] }
6
+ Object: {
8
7
  type: 'object'
9
8
  properties: any
10
9
  }
11
- export type Properties = { properties: any }
12
- export type PropertiesRequired = {
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.AllOFf ? Omit<T, 'allOf'> & {
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.Object ? Omit<T, 'additionalProperties'> & { additionalProperties: false }
22
+ type FixMissingAdditionalProperties<T> = T extends Checks['Object'] ? Omit<T, 'additionalProperties'> & { additionalProperties: false }
24
23
  : T
25
- type FixMissingTypeObject<T> = T extends Checks.Properties ? T & { type: 'object' } : T
24
+ type FixMissingTypeObject<T> = T extends Checks['Properties'] ? T & { type: 'object' } : T
26
25
 
27
- type FixExtraRequiredFields<T> = T extends Checks.PropertiesRequired ? Omit<T, 'required'> & {
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
@@ -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
- namespace Checks {
11
- export type Required = { required: true }
9
+ type Checks<TParamType = never> = {
10
+ Required: { required: true }
12
11
 
13
- export type Schemas = {
12
+ Schemas: {
14
13
  schema: JSONSchema
15
14
  }
16
- export type Enum = { type: JSONSchemaTypeName; enum?: any[] }
17
- export type Parameters = { in: string; required?: boolean }[]
18
- export type SingleParameter<TParamType> = [{ in: TParamType; required?: true }]
19
- export type Responses = { responses: any }
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.Required ? {
44
- [TName in TParameter['name']]: TParameter extends Checks.Schemas ? FromSchema<TParameter['schema']>
45
- : TParameter extends Checks.Enum ? FromSchema<{
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.Schemas ? FromSchema<TParameter['schema']>
53
- : TParameter extends Checks.Enum ? FromSchema<{
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.Parameters> extends Fn {
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.SingleParameter<TParamType> ? {
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.Parameters> = Pipe<
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.Responses ? MethodMap<TOAS, TPath>[TMethod]['responses']
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
- namespace Checks {
9
- export type ModelWithSchemas = {
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
- export type ModelWithSchemasNamed<TName extends string | number | symbol> = {
13
+ ModelWithSchemasNamed: {
15
14
  components: {
16
15
  schemas: {
17
16
  [TModelName in TName]: JSONSchema
18
17
  }
19
18
  }
20
19
  }
21
- export type ModelWithDefinitions = {
20
+ ModelWithDefinitions: {
22
21
  definitions: Record<string, JSONSchema>
23
22
  }
24
- export type ModelWithDefinitionsNamed<TName extends string | number | symbol = never> = {
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.ModelWithSchemas ? keyof TOAS['components']['schemas']
34
- : TOAS extends Checks.ModelWithDefinitions ? keyof TOAS['definitions']
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.ModelWithSchemasNamed<TName> ? FromSchema<TOAS['components']['schemas'][TName]>
37
- : TOAS extends Checks.ModelWithDefinitionsNamed<TName> ? FromSchema<TOAS['definitions'][TName]>
35
+ > = TOAS extends Checks<TName>['ModelWithSchemasNamed'] ? FromSchema<TOAS['components']['schemas'][TName]>
36
+ : TOAS extends Checks<TName>['ModelWithDefinitionsNamed'] ? FromSchema<TOAS['definitions'][TName]>
38
37
  : never
@@ -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
- namespace Checks {
15
- export type RequestBodyJson = {
12
+ type Checks = {
13
+ RequestBodyJson: {
16
14
  requestBody: { content: { 'application/json': { schema: JSONSchema } } }
17
15
  }
18
- export type RequestBodyFormData = {
16
+ RequestBodyFormData: {
19
17
  requestBody: {
20
18
  content: { 'multipart/form-data': { schema: JSONSchema } }
21
19
  }
22
20
  }
23
- export type RequestBodyFormEncoded = {
21
+ RequestBodyFormEncoded: {
24
22
  requestBody: {
25
23
  content: {
26
24
  'application/x-www-form-urlencoded': { schema: JSONSchema }
27
25
  }
28
26
  }
29
27
  }
30
- export type Parameters = {
28
+ Parameters: {
31
29
  parameters: { name: string; in: string }[]
32
30
  }
33
- export type PathBrackets = `${string}{${string}}${string}`
34
- export type PathPattern = `${string}:${string}${string}`
35
- export type Required = { required: true }
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.RequestBodyJson ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks.Required ? {
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.RequestBodyFormData ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks.Required ? {
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.RequestBodyFormEncoded ? MethodMap<TOAS, TPath>[TMethod]['requestBody'] extends Checks.Required ? {
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.Parameters ? ParamMap<MethodMap<TOAS, TPath>[TMethod]['parameters']>
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.PathBrackets ? {
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.PathPattern ? {
154
+ & (TPath extends Checks['PathPattern'] ? {
157
155
  /**
158
156
  * Parameters defined in the path are required for this request.
159
157
  *
@@ -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
- namespace Checks {
9
- export type Content = { content: any }
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.Content ? ResponseSchemas<TOAS, TPath, TMethod, TStatus>[
23
+ > = StatusMap<TOAS, TPath, TMethod>[TStatus] extends Checks['Content'] ? ResponseSchemas<TOAS, TPath, TMethod, TStatus>[
25
24
  keyof ResponseSchemas<
26
25
  TOAS,
27
26
  TPath,
@@ -3,46 +3,46 @@
3
3
 
4
4
  import type { Call, Objects, Tuples } from 'hotscript'
5
5
 
6
- namespace Checks {
7
- export type Security = { security: { [key: string]: any }[] }
6
+ type Checks = {
7
+ Security: { security: { [key: string]: any }[] }
8
8
 
9
- export namespace AuthParams {
10
- export type Basic =
9
+ AuthParams: {
10
+ Basic:
11
11
  | {
12
12
  type: 'http'
13
13
  scheme: 'basic'
14
14
  }
15
15
  | { type: 'basic' }
16
- export type Bearer =
16
+ Bearer:
17
17
  | {
18
18
  type: 'http'
19
19
  scheme: 'bearer'
20
20
  }
21
21
  | { type: 'bearer' }
22
22
 
23
- export type OAuth2 = {
23
+ OAuth2: {
24
24
  type: 'oauth2'
25
25
  }
26
- export type ApiKey = {
26
+ ApiKey: {
27
27
  type: 'apiKey'
28
28
  in: 'header'
29
29
  }
30
30
  }
31
31
 
32
- export namespace AuthName {
33
- export type Basic = `basic${string}`
34
- export type Bearer = `bearer${string}`
35
- export type OAuth2 = `oauth${string}`
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.Security> = Call<
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.AuthParams.Basic ? {
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.AuthParams.Bearer ? {
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.AuthParams.ApiKey & { name: infer TApiKeyHeaderName } ? {
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.AuthParams.OAuth2 ? {
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.Security ? TOAS extends
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.AuthName.Basic ? AuthParams.Basic<{
146
+ : SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['Basic'] ? AuthParams.Basic<{
147
147
  type: 'http'
148
148
  scheme: 'basic'
149
149
  }>
150
- : SecuritySchemeName<TSecurityObj> extends Checks.AuthName.Bearer ? AuthParams.Bearer<{
150
+ : SecuritySchemeName<TSecurityObj> extends Checks['AuthName']['Bearer'] ? AuthParams.Bearer<{
151
151
  type: 'http'
152
152
  scheme: 'bearer'
153
153
  }>
154
- : SecuritySchemeName<TSecurityObj> extends Checks.AuthName.OAuth2 ? AuthParams.OAuth2<{
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, KubbPlugin } from '@kubb/core'
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]: [KubbPlugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [swaggerPluginName])
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, KubbPlugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
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?: KubbPlugin['key']
101
+ pluginKey?: Plugin['key']
96
102
  name?: string
97
103
  tag?: string
98
104
  }