@kubb/swagger-ts 2.11.0 → 2.12.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/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
2
  import { KubbFile, ResolveNameParams, Plugin, PluginFactoryOptions } from '@kubb/core';
3
3
  import { Exclude, Include, Override, ResolvePathOptions } from '@kubb/swagger';
4
- export { i as Oas } from './index-BKDH3fXc.cjs';
4
+ export { i as Oas } from './index-_MgWTBjd.cjs';
5
5
  import 'hotscript';
6
6
  import 'ts-toolbelt';
7
7
  import '@kubb/swagger/oas';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
2
  import { KubbFile, ResolveNameParams, Plugin, PluginFactoryOptions } from '@kubb/core';
3
3
  import { Exclude, Include, Override, ResolvePathOptions } from '@kubb/swagger';
4
- export { i as Oas } from './index-BKDH3fXc.js';
4
+ export { i as Oas } from './index-_MgWTBjd.js';
5
5
  import 'hotscript';
6
6
  import 'ts-toolbelt';
7
7
  import '@kubb/swagger/oas';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  pluginKey,
4
4
  pluginName,
5
5
  src_default
6
- } from "./chunk-QIZFD754.js";
6
+ } from "./chunk-ZNLTJZHN.js";
7
7
  export {
8
8
  src_default as default,
9
9
  definePlugin,
package/dist/oas.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as Infer, M as MethodMap, a as Model, P as PathMap, R as RequestParams, b as Response, S as StatusMap } from './index-BKDH3fXc.cjs';
1
+ export { I as Infer, M as MethodMap, a as Model, P as PathMap, R as RequestParams, b as Response, S as StatusMap } from './index-_MgWTBjd.cjs';
2
2
  import 'hotscript';
3
3
  import 'ts-toolbelt';
4
4
  import '@kubb/swagger/oas';
package/dist/oas.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as Infer, M as MethodMap, a as Model, P as PathMap, R as RequestParams, b as Response, S as StatusMap } from './index-BKDH3fXc.js';
1
+ export { I as Infer, M as MethodMap, a as Model, P as PathMap, R as RequestParams, b as Response, S as StatusMap } from './index-_MgWTBjd.js';
2
2
  import 'hotscript';
3
3
  import 'ts-toolbelt';
4
4
  import '@kubb/swagger/oas';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/swagger-ts",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "description": "Generator swagger-ts",
5
5
  "keywords": [
6
6
  "typescript",
@@ -59,16 +59,17 @@
59
59
  "hotscript": "^1.0.13",
60
60
  "json-schema-to-ts": "^3.0.1",
61
61
  "ts-toolbelt": "^9.6.0",
62
- "@kubb/core": "2.11.0",
63
- "@kubb/parser": "2.11.0",
64
- "@kubb/react": "2.11.0",
65
- "@kubb/swagger": "2.11.0",
66
- "@kubb/types": "2.11.0"
62
+ "@kubb/core": "2.12.0",
63
+ "@kubb/parser": "2.12.0",
64
+ "@kubb/react": "2.12.0",
65
+ "@kubb/swagger": "2.12.0",
66
+ "@kubb/types": "2.12.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@types/react": "^18.2.69",
69
+ "@types/react": "^18.2.73",
70
70
  "eslint": "^8.57.0",
71
- "expect-type": "^0.17.3",
71
+ "expect-type": "^0.19.0",
72
+ "prettier": "^3.2.5",
72
73
  "react": "^18.2.0",
73
74
  "tsup": "^8.0.2",
74
75
  "@kubb/eslint-config": "1.1.8",
@@ -76,7 +77,7 @@
76
77
  "@kubb/tsup-config": "1.1.8"
77
78
  },
78
79
  "peerDependencies": {
79
- "@kubb/react": "2.11.0"
80
+ "@kubb/react": "2.12.0"
80
81
  },
81
82
  "packageManager": "pnpm@8.3.0",
82
83
  "engines": {
@@ -14,7 +14,9 @@ export class OperationGenerator extends Generator<PluginOptions['resolvedOptions
14
14
  async all(operations: Operation[]): OperationMethodResult<FileMeta> {
15
15
  const { oas, pluginManager, plugin } = this.context
16
16
 
17
- const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
17
+ const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({
18
+ logger: pluginManager.logger,
19
+ })
18
20
 
19
21
  root.render(
20
22
  <Oas oas={oas} operations={operations} getOperationSchemas={(...props) => this.getSchemas(...props)}>
@@ -26,13 +28,12 @@ export class OperationGenerator extends Generator<PluginOptions['resolvedOptions
26
28
  return root.files
27
29
  }
28
30
 
29
- async operation(
30
- operation: Operation,
31
- options: PluginOptions['resolvedOptions'],
32
- ): OperationMethodResult<FileMeta> {
31
+ async operation(operation: Operation, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
33
32
  const { oas, pluginManager, plugin, mode } = this.context
34
33
 
35
- const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
34
+ const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({
35
+ logger: pluginManager.logger,
36
+ })
36
37
  root.render(
37
38
  <Oas oas={oas} operations={[operation]} getOperationSchemas={(...props) => this.getSchemas(...props)}>
38
39
  <Oas.Operation operation={operation}>
@@ -15,7 +15,9 @@ export class SchemaGenerator extends Generator<PluginOptions['resolvedOptions'],
15
15
  async schema(name: string, object: SchemaObject): SchemaMethodResult<FileMeta> {
16
16
  const { oas, pluginManager, mode, plugin, output } = this.context
17
17
 
18
- const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
18
+ const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({
19
+ logger: pluginManager.logger,
20
+ })
19
21
 
20
22
  root.render(
21
23
  <Oas oas={oas}>
@@ -29,14 +31,19 @@ export class SchemaGenerator extends Generator<PluginOptions['resolvedOptions'],
29
31
  return root.files
30
32
  }
31
33
  // TODO convert to a react component called `Schema.Parser` with props parser as part of the SchemaContext
32
- getSource(name: string, schemas: SchemaType[], {
33
- keysToOmit,
34
- description,
35
- }: SchemaGeneratorBuildOptions = {}): string[] {
34
+ getSource(name: string, schemas: SchemaType[], { keysToOmit, description }: SchemaGeneratorBuildOptions = {}): string[] {
36
35
  const texts: string[] = []
37
36
 
38
- const resolvedName = this.context.pluginManager.resolveName({ name, pluginKey, type: 'function' })
39
- const resvoledTypeName = this.context.pluginManager.resolveName({ name, pluginKey: swaggerTypeScriptPluginKey, type: 'type' })
37
+ const resolvedName = this.context.pluginManager.resolveName({
38
+ name,
39
+ pluginKey,
40
+ type: 'function',
41
+ })
42
+ const resvoledTypeName = this.context.pluginManager.resolveName({
43
+ name,
44
+ pluginKey: swaggerTypeScriptPluginKey,
45
+ type: 'type',
46
+ })
40
47
 
41
48
  const typeOutput = typeParser(schemas, {
42
49
  name: resolvedName,
@@ -1,5 +1,4 @@
1
- import { Editor, File, Type, usePlugin } from '@kubb/react'
2
- import { useGetFile } from '@kubb/react'
1
+ import { Editor, File, Type, usePlugin, usePluginManager } from '@kubb/react'
3
2
  import { useOas } from '@kubb/swagger/hooks'
4
3
 
5
4
  import type { OasTypes } from '@kubb/swagger/oas'
@@ -15,11 +14,7 @@ type TemplateProps = {
15
14
  api: OasTypes.OASDocument
16
15
  }
17
16
 
18
- function Template({
19
- name,
20
- typeName,
21
- api,
22
- }: TemplateProps): ReactNode {
17
+ function Template({ name, typeName, api }: TemplateProps): ReactNode {
23
18
  return (
24
19
  <>
25
20
  {`export const ${name} = ${JSON.stringify(api, undefined, 2)} as const`}
@@ -42,11 +37,7 @@ type Props = {
42
37
  Template?: React.ComponentType<React.ComponentProps<typeof Template>>
43
38
  }
44
39
 
45
- export function OasType({
46
- name,
47
- typeName,
48
- Template = defaultTemplates.default,
49
- }: Props): ReactNode {
40
+ export function OasType({ name, typeName, Template = defaultTemplates.default }: Props): ReactNode {
50
41
  const oas = useOas()
51
42
 
52
43
  return <Template name={name} typeName={typeName} api={oas.api} />
@@ -61,19 +52,16 @@ type FileProps = {
61
52
  templates?: typeof defaultTemplates
62
53
  }
63
54
 
64
- OasType.File = function({ name, typeName, templates = defaultTemplates }: FileProps): ReactNode {
55
+ OasType.File = function ({ name, typeName, templates = defaultTemplates }: FileProps): ReactNode {
65
56
  const { key: pluginKey } = usePlugin<PluginOptions>()
66
- const file = useGetFile({ name, extName: '.ts', pluginKey })
57
+ const pluginManager = usePluginManager()
58
+ const file = pluginManager.getFile({ name, extName: '.ts', pluginKey })
67
59
 
68
60
  const Template = templates.default
69
61
 
70
62
  return (
71
63
  <Editor language="typescript">
72
- <File<FileMeta>
73
- baseName={file.baseName}
74
- path={file.path}
75
- meta={file.meta}
76
- >
64
+ <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
77
65
  <File.Import name={['Infer']} path="@kubb/swagger-ts/oas" isTypeOnly />
78
66
  <File.Source>
79
67
  <OasType Template={Template} name={name} typeName={typeName} />
@@ -5,7 +5,7 @@ import { print } from '@kubb/parser'
5
5
  import * as factory from '@kubb/parser/factory'
6
6
  import { Editor, File, usePlugin, usePluginManager } from '@kubb/react'
7
7
  import { Oas, Schema } from '@kubb/swagger/components'
8
- import { useGetOperationFile, useOas, useOperation, useOperationName, useOperationSchemas } from '@kubb/swagger/hooks'
8
+ import { useOas, useOperation, useOperationManager } from '@kubb/swagger/hooks'
9
9
 
10
10
  import { SchemaGenerator } from '../SchemaGenerator.tsx'
11
11
 
@@ -21,47 +21,29 @@ type Props = {}
21
21
 
22
22
  function printCombinedSchema(name: string, operation: Operation, schemas: OperationSchemas): string {
23
23
  const properties: Record<string, ts.TypeNode> = {
24
- 'response': factory.createTypeReferenceNode(
25
- factory.createIdentifier(schemas.response.name),
26
- undefined,
27
- ),
24
+ response: factory.createTypeReferenceNode(factory.createIdentifier(schemas.response.name), undefined),
28
25
  }
29
26
 
30
27
  if (schemas.request) {
31
- properties['request'] = factory.createTypeReferenceNode(
32
- factory.createIdentifier(schemas.request.name),
33
- undefined,
34
- )
28
+ properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.request.name), undefined)
35
29
  }
36
30
 
37
31
  if (schemas.pathParams) {
38
- properties['pathParams'] = factory.createTypeReferenceNode(
39
- factory.createIdentifier(schemas.pathParams.name),
40
- undefined,
41
- )
32
+ properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.pathParams.name), undefined)
42
33
  }
43
34
 
44
35
  if (schemas.queryParams) {
45
- properties['queryParams'] = factory.createTypeReferenceNode(
46
- factory.createIdentifier(schemas.queryParams.name),
47
- undefined,
48
- )
36
+ properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.queryParams.name), undefined)
49
37
  }
50
38
 
51
39
  if (schemas.headerParams) {
52
- properties['headerParams'] = factory.createTypeReferenceNode(
53
- factory.createIdentifier(schemas.headerParams.name),
54
- undefined,
55
- )
40
+ properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(schemas.headerParams.name), undefined)
56
41
  }
57
42
 
58
43
  if (schemas.errors) {
59
44
  properties['errors'] = factory.createUnionDeclaration({
60
- nodes: schemas.errors.map(error => {
61
- return factory.createTypeReferenceNode(
62
- factory.createIdentifier(error.name),
63
- undefined,
64
- )
45
+ nodes: schemas.errors.map((error) => {
46
+ return factory.createTypeReferenceNode(factory.createIdentifier(error.name), undefined)
65
47
  }),
66
48
  })!
67
49
  }
@@ -69,19 +51,19 @@ function printCombinedSchema(name: string, operation: Operation, schemas: Operat
69
51
  const namespaceNode = factory.createTypeAliasDeclaration({
70
52
  name: operation.method === 'get' ? `${name}Query` : `${name}Mutation`,
71
53
  type: factory.createTypeLiteralNode(
72
- Object.keys(properties).map(key => {
73
- const type = properties[key]
74
- if (!type) {
75
- return undefined
76
- }
77
-
78
- return factory.createPropertySignature(
79
- {
54
+ Object.keys(properties)
55
+ .map((key) => {
56
+ const type = properties[key]
57
+ if (!type) {
58
+ return undefined
59
+ }
60
+
61
+ return factory.createPropertySignature({
80
62
  name: transformers.pascalCase(key),
81
63
  type,
82
- },
83
- )
84
- }).filter(Boolean),
64
+ })
65
+ })
66
+ .filter(Boolean),
85
67
  ),
86
68
  modifiers: [factory.modifiers.export],
87
69
  })
@@ -90,42 +72,36 @@ function printCombinedSchema(name: string, operation: Operation, schemas: Operat
90
72
  }
91
73
 
92
74
  export function OperationSchema({}: Props): ReactNode {
93
- return (
94
- <>
95
- </>
96
- )
75
+ return <></>
97
76
  }
98
77
 
99
78
  type FileProps = {
100
79
  mode: KubbFile.Mode | undefined
101
80
  }
102
81
 
103
- OperationSchema.File = function({ mode = 'directory' }: FileProps): ReactNode {
82
+ OperationSchema.File = function ({ mode = 'directory' }: FileProps): ReactNode {
104
83
  const plugin = usePlugin<PluginOptions>()
105
84
 
106
85
  const pluginManager = usePluginManager()
107
86
  const oas = useOas()
108
- const schemas = useOperationSchemas()
109
- const file = useGetOperationFile()
110
- const factoryName = useOperationName({ type: 'type' })
87
+ const { getSchemas, getFile, getName } = useOperationManager()
111
88
  const operation = useOperation()
112
89
 
113
- const generator = new SchemaGenerator(plugin.options, { oas, plugin, pluginManager })
90
+ const file = getFile(operation)
91
+ const schemas = getSchemas(operation)
92
+ const factoryName = getName(operation, { type: 'type' })
93
+ const generator = new SchemaGenerator(plugin.options, {
94
+ oas,
95
+ plugin,
96
+ pluginManager,
97
+ })
114
98
 
115
- const items = [
116
- schemas.pathParams,
117
- schemas.queryParams,
118
- schemas.headerParams,
119
- schemas.statusCodes,
120
- schemas.request,
121
- schemas.response,
122
- ].flat().filter(Boolean)
99
+ const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean)
123
100
 
124
101
  const mapItem = ({ name, schema: object, ...options }: OperationSchemaType, i: number) => {
125
102
  return (
126
103
  <Oas.Schema key={i} generator={generator} name={name} object={object}>
127
- {mode === 'directory'
128
- && <Schema.Imports isTypeOnly />}
104
+ {mode === 'directory' && <Schema.Imports isTypeOnly />}
129
105
  <File.Source>
130
106
  <Schema.Source options={options} />
131
107
  </File.Source>
@@ -135,16 +111,10 @@ OperationSchema.File = function({ mode = 'directory' }: FileProps): ReactNode {
135
111
 
136
112
  return (
137
113
  <Editor language="typescript">
138
- <File<FileMeta>
139
- baseName={file.baseName}
140
- path={file.path}
141
- meta={file.meta}
142
- >
114
+ <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
143
115
  {items.map(mapItem)}
144
116
 
145
- <File.Source>
146
- {printCombinedSchema(factoryName, operation, schemas)}
147
- </File.Source>
117
+ <File.Source>{printCombinedSchema(factoryName, operation, schemas)}</File.Source>
148
118
  </File>
149
119
  </Editor>
150
120
  )
package/src/oas/infer.ts CHANGED
@@ -14,41 +14,35 @@ type Checks = {
14
14
  }
15
15
  }
16
16
 
17
- type FixAdditionalPropertiesForAllOf<T> = T extends Checks['AllOFf'] ? Omit<T, 'allOf'> & {
18
- allOf: Call<Tuples.Map<Objects.Omit<'additionalProperties'>>, T['allOf']>
19
- }
17
+ type FixAdditionalPropertiesForAllOf<T> = T extends Checks['AllOFf']
18
+ ? Omit<T, 'allOf'> & {
19
+ allOf: Call<Tuples.Map<Objects.Omit<'additionalProperties'>>, T['allOf']>
20
+ }
20
21
  : T
21
22
 
22
- type FixMissingAdditionalProperties<T> = T extends Checks['Object'] ? Omit<T, 'additionalProperties'> & { additionalProperties: false }
23
- : T
23
+ type FixMissingAdditionalProperties<T> = T extends Checks['Object'] ? Omit<T, 'additionalProperties'> & { additionalProperties: false } : T
24
24
  type FixMissingTypeObject<T> = T extends Checks['Properties'] ? T & { type: 'object' } : T
25
25
 
26
- type FixExtraRequiredFields<T> = T extends Checks['PropertiesRequired'] ? Omit<T, 'required'> & {
27
- required: Call<Tuples.Filter<Booleans.Extends<keyof T['properties']>>, T['required']>
28
- }
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
+ }
29
30
  : T
30
31
 
31
32
  // Later suggest using json-machete
32
- type FixJSONSchema<T> = FixAdditionalPropertiesForAllOf<
33
- FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>
34
- >
33
+ type FixJSONSchema<T> = FixAdditionalPropertiesForAllOf<FixMissingAdditionalProperties<FixMissingTypeObject<FixExtraRequiredFields<T>>>>
35
34
 
36
- type Mutable<Type> = FixJSONSchema<
37
- {
38
- -readonly [Key in keyof Type]: Mutable<Type[Key]>
39
- }
40
- >
35
+ type Mutable<Type> = FixJSONSchema<{
36
+ -readonly [Key in keyof Type]: Mutable<Type[Key]>
37
+ }>
41
38
 
42
- type RefToPath<T extends string> = T extends `#/${infer Ref}` ? Call<Strings.Split<'/'>, Ref>
43
- : never
39
+ type RefToPath<T extends string> = T extends `#/${infer Ref}` ? Call<Strings.Split<'/'>, Ref> : never
44
40
 
45
41
  type ResolveRef<TObj, TRef extends string> = {
46
42
  $id: TRef
47
43
  } & Object.Path<TObj, RefToPath<TRef>>
48
44
 
49
- type ResolveRefInObj<T, TBase> = T extends { $ref: infer Ref } ? Ref extends string ? ResolveRef<TBase, Ref>
50
- : T
51
- : T
45
+ type ResolveRefInObj<T, TBase> = T extends { $ref: infer Ref } ? (Ref extends string ? ResolveRef<TBase, Ref> : T) : T
52
46
 
53
47
  type ResolveRefsInObj<T, TBase = T> = {
54
48
  [K in keyof T]: ResolveRefsInObj<ResolveRefInObj<T[K], TBase>, TBase>
@@ -1,10 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
2
  import type { OasTypes } from '@kubb/swagger/oas'
3
3
  import type { Fn, Pipe, Tuples } from 'hotscript'
4
- import type {
5
- FromSchema,
6
- JSONSchema,
7
- } from 'json-schema-to-ts'
4
+ import type { FromSchema, JSONSchema } from 'json-schema-to-ts'
8
5
 
9
6
  type Checks<TParamType = never> = {
10
7
  Required: { required: true }
@@ -26,67 +23,54 @@ interface ParamPropMap {
26
23
  header: 'headers'
27
24
  }
28
25
 
29
- type JSONSchemaTypeName =
30
- | 'string'
31
- | 'number'
32
- | 'integer'
33
- | 'boolean'
34
- | 'object'
35
- | 'array'
36
- | 'null'
26
+ type JSONSchemaTypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null'
37
27
 
38
28
  type ParamObj<
39
29
  TParameter extends {
40
30
  name: string
41
31
  },
42
- > = TParameter extends Checks['Required'] ? {
43
- [TName in TParameter['name']]: TParameter extends Checks['Schemas'] ? FromSchema<TParameter['schema']>
44
- : TParameter extends Checks['Enum'] ? FromSchema<{
45
- type: TParameter['type']
46
- enum: TParameter['enum']
47
- }>
48
- : unknown
49
- }
32
+ > = TParameter extends Checks['Required']
33
+ ? {
34
+ [TName in TParameter['name']]: TParameter extends Checks['Schemas']
35
+ ? FromSchema<TParameter['schema']>
36
+ : TParameter extends Checks['Enum']
37
+ ? FromSchema<{
38
+ type: TParameter['type']
39
+ enum: TParameter['enum']
40
+ }>
41
+ : unknown
42
+ }
50
43
  : {
51
- [TName in TParameter['name']]?: TParameter extends Checks['Schemas'] ? FromSchema<TParameter['schema']>
52
- : TParameter extends Checks['Enum'] ? FromSchema<{
53
- type: TParameter['type']
54
- enum: TParameter['enum']
55
- }>
56
- : unknown
57
- }
44
+ [TName in TParameter['name']]?: TParameter extends Checks['Schemas']
45
+ ? FromSchema<TParameter['schema']>
46
+ : TParameter extends Checks['Enum']
47
+ ? FromSchema<{
48
+ type: TParameter['type']
49
+ enum: TParameter['enum']
50
+ }>
51
+ : unknown
52
+ }
58
53
 
59
54
  interface ParamToRequestParam<TParameters extends Checks['Parameters']> extends Fn {
60
55
  return: this['arg0'] extends { name: string; in: infer TParamType }
61
- // If there is any required parameter for this parameter type, make that parameter type required
62
- ? TParameters extends Checks<TParamType>['SingleParameter'] ? {
63
- [
64
- TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType]
65
- : never
66
- ]: ParamObj<this['arg0']>
67
- }
68
- : {
69
- [
70
- TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType]
71
- : never
72
- ]?: ParamObj<this['arg0']>
73
- }
56
+ ? // If there is any required parameter for this parameter type, make that parameter type required
57
+ TParameters extends Checks<TParamType>['SingleParameter']
58
+ ? {
59
+ [TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]: ParamObj<this['arg0']>
60
+ }
61
+ : {
62
+ [TKey in TParamType extends keyof ParamPropMap ? ParamPropMap[TParamType] : never]?: ParamObj<this['arg0']>
63
+ }
74
64
  : {}
75
65
  }
76
66
 
77
- export type ParamMap<TParameters extends Checks['Parameters']> = Pipe<
78
- TParameters,
79
- [Tuples.Map<ParamToRequestParam<TParameters>>, Tuples.ToIntersection]
80
- >
67
+ export type ParamMap<TParameters extends Checks['Parameters']> = Pipe<TParameters, [Tuples.Map<ParamToRequestParam<TParameters>>, Tuples.ToIntersection]>
81
68
 
82
- export type MethodMap<
83
- TOAS extends OasTypes.OASDocument,
84
- TPath extends keyof PathMap<TOAS>,
85
- > = PathMap<TOAS>[TPath]
69
+ export type MethodMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>> = PathMap<TOAS>[TPath]
86
70
 
87
- export type StatusMap<
88
- TOAS extends OasTypes.OASDocument,
89
- TPath extends keyof PathMap<TOAS>,
90
- TMethod extends keyof MethodMap<TOAS, TPath>,
91
- > = MethodMap<TOAS, TPath>[TMethod] extends Checks['Responses'] ? MethodMap<TOAS, TPath>[TMethod]['responses']
71
+ export type StatusMap<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>> = MethodMap<
72
+ TOAS,
73
+ TPath
74
+ >[TMethod] extends Checks['Responses']
75
+ ? MethodMap<TOAS, TPath>[TMethod]['responses']
92
76
  : never
package/src/oas/model.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  import type { OasTypes } from '@kubb/swagger/oas'
2
- import type {
3
- FromSchema,
4
- JSONSchema,
5
- } from 'json-schema-to-ts'
2
+ import type { FromSchema, JSONSchema } from 'json-schema-to-ts'
6
3
 
7
4
  type Checks<TName extends string | number | symbol = never> = {
8
5
  ModelWithSchemas: {
@@ -29,9 +26,13 @@ type Checks<TName extends string | number | symbol = never> = {
29
26
 
30
27
  export type Model<
31
28
  TOAS extends OasTypes.OASDocument,
32
- TName extends TOAS extends Checks['ModelWithSchemas'] ? keyof TOAS['components']['schemas']
33
- : TOAS extends Checks['ModelWithDefinitions'] ? keyof TOAS['definitions']
34
- : never,
35
- > = TOAS extends Checks<TName>['ModelWithSchemasNamed'] ? FromSchema<TOAS['components']['schemas'][TName]>
36
- : TOAS extends Checks<TName>['ModelWithDefinitionsNamed'] ? FromSchema<TOAS['definitions'][TName]>
37
- : never
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