@kubb/plugin-oas 2.18.4 → 2.18.6

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 (68) hide show
  1. package/dist/{OperationGenerator-X6CTMfhG.d.cts → OperationGenerator-B6_KXF47.d.cts} +12 -11
  2. package/dist/{OperationGenerator-DvnXUUp4.d.ts → OperationGenerator-BL3W1CH2.d.ts} +12 -11
  3. package/dist/{Schema-DFZBfjF2.d.ts → Schema-ByMOp8RL.d.ts} +6 -12
  4. package/dist/{Schema-BWPWyiQO.d.cts → Schema-C9Wxng-Q.d.cts} +6 -12
  5. package/dist/{SchemaGenerator-hK5SHxTI.d.ts → SchemaMapper-DRlWYDvv.d.cts} +2 -74
  6. package/dist/{SchemaGenerator-z_7YrAAB.d.cts → SchemaMapper-DRlWYDvv.d.ts} +2 -74
  7. package/dist/{chunk-UMYKVV7G.js → chunk-37DRAF2Z.js} +49 -2
  8. package/dist/chunk-37DRAF2Z.js.map +1 -0
  9. package/dist/chunk-CTFUZW3D.cjs +682 -0
  10. package/dist/chunk-CTFUZW3D.cjs.map +1 -0
  11. package/dist/{chunk-XML4KQ5H.js → chunk-FL37EDQ2.js} +12 -30
  12. package/dist/{chunk-XML4KQ5H.js.map → chunk-FL37EDQ2.js.map} +1 -1
  13. package/dist/chunk-JWIFGIVZ.js +34 -0
  14. package/dist/chunk-JWIFGIVZ.js.map +1 -0
  15. package/dist/{chunk-YI3FIAD4.cjs → chunk-OUN5NRHC.cjs} +30 -48
  16. package/dist/chunk-OUN5NRHC.cjs.map +1 -0
  17. package/dist/chunk-QLNCBDLM.js +682 -0
  18. package/dist/chunk-QLNCBDLM.js.map +1 -0
  19. package/dist/chunk-R4EI2NRQ.cjs +34 -0
  20. package/dist/chunk-R4EI2NRQ.cjs.map +1 -0
  21. package/dist/{chunk-BDNSPC5Z.cjs → chunk-SSSTH6CP.cjs} +50 -3
  22. package/dist/chunk-SSSTH6CP.cjs.map +1 -0
  23. package/dist/components.cjs +5 -5
  24. package/dist/components.d.cts +5 -4
  25. package/dist/components.d.ts +5 -4
  26. package/dist/components.js +3 -3
  27. package/dist/hooks.cjs +13 -13
  28. package/dist/hooks.cjs.map +1 -1
  29. package/dist/hooks.d.cts +7 -8
  30. package/dist/hooks.d.ts +7 -8
  31. package/dist/hooks.js +3 -3
  32. package/dist/hooks.js.map +1 -1
  33. package/dist/index.cjs +69 -642
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +72 -6
  36. package/dist/index.d.ts +72 -6
  37. package/dist/index.js +50 -623
  38. package/dist/index.js.map +1 -1
  39. package/dist/{types-n5zV4Q3s.d.cts → types-BMBTfHxe.d.cts} +3 -2
  40. package/dist/{types-n5zV4Q3s.d.ts → types-BMBTfHxe.d.ts} +3 -2
  41. package/dist/utils.cjs +9 -9
  42. package/dist/utils.cjs.map +1 -1
  43. package/dist/utils.d.cts +5 -4
  44. package/dist/utils.d.ts +5 -4
  45. package/dist/utils.js +5 -5
  46. package/dist/utils.js.map +1 -1
  47. package/package.json +10 -9
  48. package/src/OperationGenerator.ts +27 -11
  49. package/src/SchemaGenerator.ts +30 -35
  50. package/src/SchemaMapper.ts +1 -1
  51. package/src/components/Schema.tsx +12 -42
  52. package/src/hooks/useOperationManager.ts +3 -2
  53. package/src/hooks/useSchema.ts +1 -8
  54. package/src/index.ts +1 -0
  55. package/src/plugin.ts +3 -3
  56. package/src/types.ts +3 -1
  57. package/src/utils/getGroupedByTagFiles.ts +4 -3
  58. package/dist/chunk-4OLWDMEK.cjs +0 -61
  59. package/dist/chunk-4OLWDMEK.cjs.map +0 -1
  60. package/dist/chunk-BDNSPC5Z.cjs.map +0 -1
  61. package/dist/chunk-BIJSTJCQ.js +0 -61
  62. package/dist/chunk-BIJSTJCQ.js.map +0 -1
  63. package/dist/chunk-I2JOGJIB.cjs +0 -81
  64. package/dist/chunk-I2JOGJIB.cjs.map +0 -1
  65. package/dist/chunk-UMYKVV7G.js.map +0 -1
  66. package/dist/chunk-XRPYJNPR.js +0 -81
  67. package/dist/chunk-XRPYJNPR.js.map +0 -1
  68. package/dist/chunk-YI3FIAD4.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { Generator } from '@kubb/core'
1
+ import { type FileMetaBase, Generator } from '@kubb/core'
2
2
  import transformers, { pascalCase } from '@kubb/core/transformers'
3
3
  import { getUniqueName } from '@kubb/core/utils'
4
4
 
@@ -8,12 +8,16 @@ import { isKeyword, schemaKeywords } from './SchemaMapper.ts'
8
8
  import { getSchemaFactory } from './utils/getSchemaFactory.ts'
9
9
  import { getSchemas } from './utils/getSchemas.ts'
10
10
 
11
- import type { KubbFile, Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from '@kubb/core'
11
+ import type { Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from '@kubb/core'
12
+ import type * as KubbFile from '@kubb/fs/types'
13
+
12
14
  import type { Oas, OpenAPIV3, SchemaObject, contentType } from '@kubb/oas'
13
15
  import type { Schema, SchemaKeywordMapper } from './SchemaMapper.ts'
14
16
  import type { OperationSchema, Override, Refs } from './types.ts'
15
17
 
16
- export type SchemaMethodResult<TFileMeta extends KubbFile.FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
18
+ export type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never
19
+
20
+ export type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
17
21
 
18
22
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
19
23
  oas: Oas
@@ -62,7 +66,7 @@ type SchemaProps = {
62
66
  export abstract class SchemaGenerator<
63
67
  TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions,
64
68
  TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
65
- TFileMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase,
69
+ TFileMeta extends FileMetaBase = FileMetaBase,
66
70
  > extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
67
71
  // Collect the types of all referenced schemas, so we can export them later
68
72
  refs: Refs = {}
@@ -75,7 +79,7 @@ export abstract class SchemaGenerator<
75
79
  * Delegates to getBaseTypeFromSchema internally and
76
80
  * optionally adds a union with null.
77
81
  */
78
- buildSchemas(props: SchemaProps): Schema[] {
82
+ parse(props: SchemaProps): Schema[] {
79
83
  const options = this.#getOptions(props)
80
84
 
81
85
  const defaultSchemas = this.#parseSchemaObject(props)
@@ -84,18 +88,18 @@ export abstract class SchemaGenerator<
84
88
  return uniqueWith<Schema>(schemas, isDeepEqual)
85
89
  }
86
90
 
87
- deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][] {
88
- return SchemaGenerator.deepSearch<T>(schemas, keyword)
91
+ deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][] {
92
+ return SchemaGenerator.deepSearch<T>(tree, keyword)
89
93
  }
90
94
 
91
- find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
92
- return SchemaGenerator.find<T>(schemas, keyword)
95
+ find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
96
+ return SchemaGenerator.find<T>(tree, keyword)
93
97
  }
94
98
 
95
- static deepSearch<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][] {
99
+ static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T][] {
96
100
  const foundItems: SchemaKeywordMapper[T][] = []
97
101
 
98
- schemas?.forEach((schema) => {
102
+ tree?.forEach((schema) => {
99
103
  if (schema.keyword === keyword) {
100
104
  foundItems.push(schema as SchemaKeywordMapper[T])
101
105
  }
@@ -148,10 +152,10 @@ export abstract class SchemaGenerator<
148
152
  return foundItems
149
153
  }
150
154
 
151
- static findInObject<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
155
+ static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
152
156
  let foundItem: SchemaKeywordMapper[T] | undefined = undefined
153
157
 
154
- schemas?.forEach((schema) => {
158
+ tree?.forEach((schema) => {
155
159
  if (!foundItem && schema.keyword === keyword) {
156
160
  foundItem = schema as SchemaKeywordMapper[T]
157
161
  }
@@ -176,10 +180,10 @@ export abstract class SchemaGenerator<
176
180
  return foundItem
177
181
  }
178
182
 
179
- static find<T extends keyof SchemaKeywordMapper>(schemas: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
183
+ static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined {
180
184
  let foundItem: SchemaKeywordMapper[T] | undefined = undefined
181
185
 
182
- schemas?.forEach((schema) => {
186
+ tree?.forEach((schema) => {
183
187
  if (!foundItem && schema.keyword === keyword) {
184
188
  foundItem = schema as SchemaKeywordMapper[T]
185
189
  }
@@ -275,7 +279,7 @@ export abstract class SchemaGenerator<
275
279
  const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required
276
280
  const nullable = propertySchema.nullable ?? propertySchema['x-nullable'] ?? false
277
281
 
278
- validationFunctions.push(...this.buildSchemas({ schema: propertySchema, name: propertyName, parentName: name }))
282
+ validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }))
279
283
 
280
284
  validationFunctions.push({
281
285
  keyword: schemaKeywords.name,
@@ -299,7 +303,7 @@ export abstract class SchemaGenerator<
299
303
  additionalPropertiesSchemas =
300
304
  additionalProperties === true
301
305
  ? [{ keyword: this.#getUnknownReturn({ schema, name }) }]
302
- : this.buildSchemas({ schema: additionalProperties as SchemaObject, parentName: name })
306
+ : this.parse({ schema: additionalProperties as SchemaObject, parentName: name })
303
307
  }
304
308
 
305
309
  return [
@@ -462,7 +466,7 @@ export abstract class SchemaGenerator<
462
466
  keyword: schemaKeywords.union,
463
467
  args: schema.oneOf
464
468
  .map((item) => {
465
- return item && this.buildSchemas({ schema: item as SchemaObject, name, parentName })[0]
469
+ return item && this.parse({ schema: item as SchemaObject, name, parentName })[0]
466
470
  })
467
471
  .filter(Boolean)
468
472
  .filter((item) => {
@@ -470,7 +474,7 @@ export abstract class SchemaGenerator<
470
474
  }),
471
475
  }
472
476
  if (schemaWithoutOneOf.properties) {
473
- return [...this.buildSchemas({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems]
477
+ return [...this.parse({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems]
474
478
  }
475
479
 
476
480
  return [union, ...baseItems]
@@ -484,7 +488,7 @@ export abstract class SchemaGenerator<
484
488
  keyword: schemaKeywords.union,
485
489
  args: schema.anyOf
486
490
  .map((item) => {
487
- return item && this.buildSchemas({ schema: item as SchemaObject, name, parentName })[0]
491
+ return item && this.parse({ schema: item as SchemaObject, name, parentName })[0]
488
492
  })
489
493
  .filter(Boolean)
490
494
  .filter((item) => {
@@ -504,7 +508,7 @@ export abstract class SchemaGenerator<
504
508
  }),
505
509
  }
506
510
  if (schemaWithoutAnyOf.properties) {
507
- return [...this.buildSchemas({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems]
511
+ return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems]
508
512
  }
509
513
 
510
514
  return [union, ...baseItems]
@@ -517,7 +521,7 @@ export abstract class SchemaGenerator<
517
521
  keyword: schemaKeywords.and,
518
522
  args: schema.allOf
519
523
  .map((item) => {
520
- return item && this.buildSchemas({ schema: item as SchemaObject, name, parentName })[0]
524
+ return item && this.parse({ schema: item as SchemaObject, name, parentName })[0]
521
525
  })
522
526
  .filter(Boolean)
523
527
  .filter((item) => {
@@ -529,7 +533,7 @@ export abstract class SchemaGenerator<
529
533
  return [
530
534
  {
531
535
  ...and,
532
- args: [...(and.args || []), ...this.buildSchemas({ schema: schemaWithoutAllOf, name, parentName })],
536
+ args: [...(and.args || []), ...this.parse({ schema: schemaWithoutAllOf, name, parentName })],
533
537
  },
534
538
  ...baseItems,
535
539
  ]
@@ -629,7 +633,7 @@ export abstract class SchemaGenerator<
629
633
  keyword: schemaKeywords.tuple,
630
634
  args: prefixItems
631
635
  .map((item) => {
632
- return this.buildSchemas({ schema: item, name, parentName })[0]
636
+ return this.parse({ schema: item, name, parentName })[0]
633
637
  })
634
638
  .filter(Boolean),
635
639
  },
@@ -746,7 +750,7 @@ export abstract class SchemaGenerator<
746
750
  if ('items' in schema || schema.type === ('array' as 'string')) {
747
751
  const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? undefined
748
752
  const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? undefined
749
- const items = this.buildSchemas({ schema: 'items' in schema ? (schema.items as SchemaObject) : [], name, parentName })
753
+ const items = this.parse({ schema: 'items' in schema ? (schema.items as SchemaObject) : [], name, parentName })
750
754
 
751
755
  return [
752
756
  {
@@ -771,7 +775,7 @@ export abstract class SchemaGenerator<
771
775
  const [type] = schema.type as Array<OpenAPIV3.NonArraySchemaObjectType>
772
776
 
773
777
  return [
774
- ...this.buildSchemas({
778
+ ...this.parse({
775
779
  schema: {
776
780
  ...schema,
777
781
  type,
@@ -815,13 +819,4 @@ export abstract class SchemaGenerator<
815
819
  * Schema
816
820
  */
817
821
  abstract schema(name: string, object: SchemaObject): SchemaMethodResult<TFileMeta>
818
- /**
819
- * Returns the source, in the future it will return a React component
820
- */
821
- abstract getSource<TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions>(name: string, schemas: Schema[], options?: TOptions): string[]
822
-
823
- /**
824
- * @deprecated only used for testing
825
- */
826
- abstract buildSource(name: string, object: SchemaObject | undefined, options?: SchemaGeneratorBuildOptions): string[]
827
822
  }
@@ -1,4 +1,4 @@
1
- import type { KubbFile } from '@kubb/core'
1
+ import type * as KubbFile from '@kubb/fs/types'
2
2
 
3
3
  export type SchemaKeywordMapper = {
4
4
  object: {
@@ -1,39 +1,36 @@
1
- import { Parser, File, createContext, useApp, useFile } from '@kubb/react'
1
+ import { File, Parser, createContext, useApp, useFile } from '@kubb/react'
2
2
 
3
3
  import { schemaKeywords } from '../SchemaMapper.ts'
4
4
  import { useSchema } from '../hooks/useSchema.ts'
5
5
 
6
- import type { KubbFile } from '@kubb/core'
6
+ import type * as KubbFile from '@kubb/fs/types'
7
7
  import type { SchemaObject } from '@kubb/oas'
8
8
  import type { KubbNode } from '@kubb/react'
9
9
  import type { ReactNode } from 'react'
10
- import type { SchemaGenerator, SchemaGeneratorBuildOptions } from '../SchemaGenerator.ts'
10
+ import { SchemaGenerator } from '../SchemaGenerator.ts'
11
11
  import type { Schema as SchemaType } from '../SchemaMapper.ts'
12
12
  import type { PluginOas } from '../types.ts'
13
13
 
14
14
  export type SchemaContextProps = {
15
15
  name: string
16
- object?: SchemaObject
17
- generator?: SchemaGenerator
18
- schemas: SchemaType[]
16
+ schema?: SchemaObject
17
+ tree: Array<SchemaType>
19
18
  }
20
19
 
21
20
  type Props = {
22
21
  name: string
23
- object?: SchemaObject
24
- generator: SchemaGenerator<any, any, any>
22
+ value?: SchemaObject
23
+ tree?: Array<SchemaType>
25
24
  children?: KubbNode
26
25
  }
27
26
 
28
27
  const SchemaContext = createContext<SchemaContextProps>({
29
28
  name: 'unknown',
30
- schemas: [],
29
+ tree: [],
31
30
  })
32
31
 
33
- export function Schema({ name, object, generator, children }: Props): KubbNode {
34
- const schemas = generator.buildSchemas({ schema: object, name })
35
-
36
- return <SchemaContext.Provider value={{ name, schemas, object, generator }}>{children}</SchemaContext.Provider>
32
+ export function Schema({ name, value, tree = [], children }: Props): KubbNode {
33
+ return <SchemaContext.Provider value={{ name, schema: value, tree }}>{children}</SchemaContext.Provider>
37
34
  }
38
35
 
39
36
  type FileProps = {
@@ -66,9 +63,6 @@ Schema.File = function ({ output, isTypeOnly, children }: FileProps): ReactNode
66
63
  pluginKey: plugin.key,
67
64
  }}
68
65
  >
69
- <File.Source>
70
- <Schema.Source />
71
- </File.Source>
72
66
  {children}
73
67
  </File>
74
68
  </Parser>
@@ -99,9 +93,6 @@ Schema.File = function ({ output, isTypeOnly, children }: FileProps): ReactNode
99
93
  }}
100
94
  >
101
95
  <Schema.Imports isTypeOnly={isTypeOnly} />
102
- <File.Source>
103
- <Schema.Source />
104
- </File.Source>
105
96
  {children}
106
97
  </File>
107
98
  </Parser>
@@ -113,10 +104,10 @@ type SchemaImportsProps = {
113
104
  }
114
105
 
115
106
  Schema.Imports = ({ isTypeOnly }: SchemaImportsProps): ReactNode => {
116
- const { generator, schemas } = useSchema()
107
+ const { tree } = useSchema()
117
108
  const { path: root } = useFile()
118
109
 
119
- const refs = generator.deepSearch(schemas, schemaKeywords.ref)
110
+ const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)
120
111
 
121
112
  return (
122
113
  <>
@@ -132,25 +123,4 @@ Schema.Imports = ({ isTypeOnly }: SchemaImportsProps): ReactNode => {
132
123
  </>
133
124
  )
134
125
  }
135
-
136
- type SchemaSourceProps<TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions> = {
137
- extraSchemas?: SchemaType[]
138
- options?: TOptions
139
- }
140
-
141
- Schema.Source = <TOptions extends SchemaGeneratorBuildOptions = SchemaGeneratorBuildOptions>({
142
- options,
143
- extraSchemas = [],
144
- }: SchemaSourceProps<TOptions>): ReactNode => {
145
- const { name, generator, schemas } = useSchema()
146
-
147
- const source = generator.getSource(name, [...schemas, ...extraSchemas], options as SchemaGeneratorBuildOptions)
148
-
149
- return (
150
- <>
151
- {source}
152
- <br />
153
- </>
154
- )
155
- }
156
126
  Schema.Context = SchemaContext
@@ -2,11 +2,12 @@ import { useApp, useContext } from '@kubb/react'
2
2
 
3
3
  import { Oas } from '../components/Oas.tsx'
4
4
 
5
- import type { KubbFile, Plugin, ResolveNameParams } from '@kubb/core'
5
+ import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'
6
+ import type * as KubbFile from '@kubb/fs/types'
6
7
  import type { Operation, Operation as OperationType } from '@kubb/oas'
7
8
  import type { OperationSchemas } from '../types.ts'
8
9
 
9
- type FileMeta = KubbFile.FileMetaBase & {
10
+ type FileMeta = FileMetaBase & {
10
11
  pluginKey: Plugin['key']
11
12
  name: string
12
13
  tag?: string
@@ -3,11 +3,8 @@ import { useContext } from '@kubb/react'
3
3
  import { Schema } from '../components/Schema.tsx'
4
4
 
5
5
  import type { SchemaContextProps } from '../components/Schema.tsx'
6
- import type { SchemaGenerator } from '../SchemaGenerator.ts'
7
6
 
8
- type UseSchemaResult = Omit<SchemaContextProps, 'generator'> & {
9
- generator: SchemaGenerator
10
- }
7
+ type UseSchemaResult = SchemaContextProps
11
8
 
12
9
  /**
13
10
  * `useSchema` will return the current `schema properties`
@@ -15,9 +12,5 @@ type UseSchemaResult = Omit<SchemaContextProps, 'generator'> & {
15
12
  export function useSchema(): UseSchemaResult {
16
13
  const props = useContext(Schema.Context)
17
14
 
18
- if (!props.generator) {
19
- throw new Error('Generator is not defined')
20
- }
21
-
22
15
  return props as UseSchemaResult
23
16
  }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export type {
7
7
  export { OperationGenerator } from './OperationGenerator.ts'
8
8
  export { pluginOas, pluginOasName } from './plugin.ts'
9
9
  export type {
10
+ GetSchemaGeneratorOptions,
10
11
  SchemaGeneratorBuildOptions,
11
12
  SchemaGeneratorOptions,
12
13
  } from './SchemaGenerator.ts'
package/src/plugin.ts CHANGED
@@ -77,12 +77,12 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
77
77
  resolveName(name, type) {
78
78
  return camelCase(name, { isFile: type === 'file' })
79
79
  },
80
- async writeFile(source, writePath) {
81
- if (!writePath.endsWith('.json') || !source) {
80
+ async writeFile(path, source) {
81
+ if (!path.endsWith('.json') || !source) {
82
82
  return
83
83
  }
84
84
 
85
- return this.fileManager.write(source, writePath, { sanity: false })
85
+ return this.fileManager.write(path, source, { sanity: false })
86
86
  },
87
87
  async buildStart() {
88
88
  if (!output) {
package/src/types.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { Plugin } from '@kubb/core'
2
- import type { KubbFile, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
+ import type { PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
3
+ import type * as KubbFile from '@kubb/fs/types'
4
+
3
5
  import type { HttpMethod, Oas, Operation, SchemaObject, contentType } from '@kubb/oas'
4
6
  import type { FormatOptions } from '@kubb/oas/parser'
5
7
  import type { GetSchemasProps } from './utils/getSchemas.ts'
@@ -1,16 +1,17 @@
1
1
  import { resolve } from 'node:path'
2
2
 
3
3
  import { FileManager } from '@kubb/core'
4
- import { getRelativePath } from '@kubb/core/fs'
5
4
  import transformers from '@kubb/core/transformers'
6
5
  import { renderTemplate } from '@kubb/core/utils'
6
+ import { getRelativePath } from '@kubb/fs'
7
7
 
8
- import type { KubbFile, Plugin } from '@kubb/core'
8
+ import type { Plugin } from '@kubb/core'
9
9
  import type { Logger } from '@kubb/core/logger'
10
+ import type * as KubbFile from '@kubb/fs/types'
10
11
 
11
12
  type Options = {
12
13
  logger: Logger
13
- files: KubbFile.File[]
14
+ files: Array<KubbFile.File<FileMeta>>
14
15
  plugin: Plugin
15
16
  template: string
16
17
  exportAs: string
@@ -1,61 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkBDNSPC5Zcjs = require('./chunk-BDNSPC5Z.cjs');
4
-
5
- // src/SchemaMapper.ts
6
- _chunkBDNSPC5Zcjs.init_cjs_shims.call(void 0, );
7
- var schemaKeywords = {
8
- any: "any",
9
- strict: "strict",
10
- unknown: "unknown",
11
- number: "number",
12
- integer: "integer",
13
- string: "string",
14
- boolean: "boolean",
15
- undefined: "undefined",
16
- nullable: "nullable",
17
- null: "null",
18
- nullish: "nullish",
19
- array: "array",
20
- tuple: "tuple",
21
- enum: "enum",
22
- union: "union",
23
- datetime: "datetime",
24
- date: "date",
25
- email: "email",
26
- uuid: "uuid",
27
- url: "url",
28
- /* intersection */
29
- default: "default",
30
- const: "const",
31
- and: "and",
32
- describe: "describe",
33
- min: "min",
34
- max: "max",
35
- optional: "optional",
36
- readOnly: "readOnly",
37
- // custom ones
38
- object: "object",
39
- ref: "ref",
40
- matches: "matches",
41
- firstName: "firstName",
42
- lastName: "lastName",
43
- password: "password",
44
- phone: "phone",
45
- blob: "blob",
46
- deprecated: "deprecated",
47
- example: "example",
48
- schema: "schema",
49
- catchall: "catchall",
50
- time: "time",
51
- name: "name"
52
- };
53
- function isKeyword(meta, keyword) {
54
- return meta.keyword === keyword;
55
- }
56
-
57
-
58
-
59
-
60
- exports.schemaKeywords = schemaKeywords; exports.isKeyword = isKeyword;
61
- //# sourceMappingURL=chunk-4OLWDMEK.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/SchemaMapper.ts"],"names":[],"mappings":";;;;;AAAA;AA+EO,IAAM,iBAAiB;AAAA,EAC5B,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA;AAAA,EAEL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AAAA,EACV,KAAK;AAAA,EACL,KAAK;AAAA,EACL,UAAU;AAAA,EACV,UAAU;AAAA;AAAA,EAGV,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,MAAM;AACR;AAiBO,SAAS,UAAiE,MAAS,SAAwD;AAChJ,SAAO,KAAK,YAAY;AAC1B","sourcesContent":["import type { KubbFile } from '@kubb/core'\n\nexport type SchemaKeywordMapper = {\n object: {\n keyword: 'object'\n args: {\n properties: { [x: string]: Schema[] }\n additionalProperties: Schema[]\n strict?: boolean\n }\n }\n strict: { keyword: 'strict' }\n url: { keyword: 'url' }\n readOnly: { keyword: 'readOnly' }\n uuid: { keyword: 'uuid' }\n email: { keyword: 'email' }\n firstName: { keyword: 'firstName' }\n lastName: { keyword: 'lastName' }\n phone: { keyword: 'phone' }\n password: { keyword: 'password' }\n date: { keyword: 'date'; args: { type?: 'date' | 'string' } }\n time: { keyword: 'time'; args: { type?: 'date' | 'string' } }\n datetime: { keyword: 'datetime'; args: { offset?: boolean; local?: boolean } }\n tuple: { keyword: 'tuple'; args: Schema[] }\n array: {\n keyword: 'array'\n args: { items: Schema[]; min?: number; max?: number }\n }\n enum: {\n keyword: 'enum'\n args: {\n name: string\n typeName: string\n asConst: boolean\n items: Array<{\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }>\n }\n }\n and: { keyword: 'and'; args: Schema[] }\n const: {\n keyword: 'const'\n args: {\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }\n }\n union: { keyword: 'union'; args: Schema[] }\n ref: {\n keyword: 'ref'\n args: { name: string; path: KubbFile.OptionalPath; isTypeOnly?: boolean }\n }\n matches: { keyword: 'matches'; args?: string }\n boolean: { keyword: 'boolean' }\n default: { keyword: 'default'; args: string | number | boolean }\n string: { keyword: 'string' }\n integer: { keyword: 'integer' }\n number: { keyword: 'number' }\n max: { keyword: 'max'; args: number }\n min: { keyword: 'min'; args: number }\n describe: { keyword: 'describe'; args: string }\n example: { keyword: 'example'; args: string }\n deprecated: { keyword: 'deprecated' }\n optional: { keyword: 'optional' }\n undefined: { keyword: 'undefined' }\n nullish: { keyword: 'nullish' }\n nullable: { keyword: 'nullable' }\n null: { keyword: 'null' }\n any: { keyword: 'any' }\n unknown: { keyword: 'unknown' }\n blob: { keyword: 'blob' }\n schema: { keyword: 'schema'; args: { type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'; format?: string } }\n name: { keyword: 'name'; args: string }\n catchall: { keyword: 'catchall' }\n}\n\nexport const schemaKeywords = {\n any: 'any',\n strict: 'strict',\n unknown: 'unknown',\n number: 'number',\n integer: 'integer',\n string: 'string',\n boolean: 'boolean',\n undefined: 'undefined',\n nullable: 'nullable',\n null: 'null',\n nullish: 'nullish',\n array: 'array',\n tuple: 'tuple',\n enum: 'enum',\n union: 'union',\n datetime: 'datetime',\n date: 'date',\n email: 'email',\n uuid: 'uuid',\n url: 'url',\n /* intersection */\n default: 'default',\n const: 'const',\n and: 'and',\n describe: 'describe',\n min: 'min',\n max: 'max',\n optional: 'optional',\n readOnly: 'readOnly',\n\n // custom ones\n object: 'object',\n ref: 'ref',\n matches: 'matches',\n firstName: 'firstName',\n lastName: 'lastName',\n password: 'password',\n phone: 'phone',\n blob: 'blob',\n deprecated: 'deprecated',\n example: 'example',\n schema: 'schema',\n catchall: 'catchall',\n time: 'time',\n name: 'name',\n} satisfies {\n [K in keyof SchemaKeywordMapper]: SchemaKeywordMapper[K]['keyword']\n}\n\nexport type SchemaKeyword = keyof SchemaKeywordMapper\n\nexport type SchemaMapper<T = string | null | undefined> = {\n [K in keyof SchemaKeywordMapper]: (() => T | undefined) | undefined\n}\n\nexport type SchemaKeywordBase<T> = {\n keyword: SchemaKeyword\n args: T\n}\n\nexport type Schema = { keyword: string } | SchemaKeywordMapper[keyof SchemaKeywordMapper]\n\nexport function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]> {\n return meta.keyword === keyword\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.0.2_@microsoft+api-extractor@7.43.4_@types+node@20.12.11__postcss@8.4.38_ts-node@10.9._vnyhfq7fulozpuwbvh64t7gkvm/node_modules/tsup/assets/cjs_shims.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL('file:' + __filename).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"]}
@@ -1,61 +0,0 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-UMYKVV7G.js";
4
-
5
- // src/SchemaMapper.ts
6
- init_esm_shims();
7
- var schemaKeywords = {
8
- any: "any",
9
- strict: "strict",
10
- unknown: "unknown",
11
- number: "number",
12
- integer: "integer",
13
- string: "string",
14
- boolean: "boolean",
15
- undefined: "undefined",
16
- nullable: "nullable",
17
- null: "null",
18
- nullish: "nullish",
19
- array: "array",
20
- tuple: "tuple",
21
- enum: "enum",
22
- union: "union",
23
- datetime: "datetime",
24
- date: "date",
25
- email: "email",
26
- uuid: "uuid",
27
- url: "url",
28
- /* intersection */
29
- default: "default",
30
- const: "const",
31
- and: "and",
32
- describe: "describe",
33
- min: "min",
34
- max: "max",
35
- optional: "optional",
36
- readOnly: "readOnly",
37
- // custom ones
38
- object: "object",
39
- ref: "ref",
40
- matches: "matches",
41
- firstName: "firstName",
42
- lastName: "lastName",
43
- password: "password",
44
- phone: "phone",
45
- blob: "blob",
46
- deprecated: "deprecated",
47
- example: "example",
48
- schema: "schema",
49
- catchall: "catchall",
50
- time: "time",
51
- name: "name"
52
- };
53
- function isKeyword(meta, keyword) {
54
- return meta.keyword === keyword;
55
- }
56
-
57
- export {
58
- schemaKeywords,
59
- isKeyword
60
- };
61
- //# sourceMappingURL=chunk-BIJSTJCQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/SchemaMapper.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/core'\n\nexport type SchemaKeywordMapper = {\n object: {\n keyword: 'object'\n args: {\n properties: { [x: string]: Schema[] }\n additionalProperties: Schema[]\n strict?: boolean\n }\n }\n strict: { keyword: 'strict' }\n url: { keyword: 'url' }\n readOnly: { keyword: 'readOnly' }\n uuid: { keyword: 'uuid' }\n email: { keyword: 'email' }\n firstName: { keyword: 'firstName' }\n lastName: { keyword: 'lastName' }\n phone: { keyword: 'phone' }\n password: { keyword: 'password' }\n date: { keyword: 'date'; args: { type?: 'date' | 'string' } }\n time: { keyword: 'time'; args: { type?: 'date' | 'string' } }\n datetime: { keyword: 'datetime'; args: { offset?: boolean; local?: boolean } }\n tuple: { keyword: 'tuple'; args: Schema[] }\n array: {\n keyword: 'array'\n args: { items: Schema[]; min?: number; max?: number }\n }\n enum: {\n keyword: 'enum'\n args: {\n name: string\n typeName: string\n asConst: boolean\n items: Array<{\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }>\n }\n }\n and: { keyword: 'and'; args: Schema[] }\n const: {\n keyword: 'const'\n args: {\n name: string | number\n format: 'string' | 'number'\n value?: string | number\n }\n }\n union: { keyword: 'union'; args: Schema[] }\n ref: {\n keyword: 'ref'\n args: { name: string; path: KubbFile.OptionalPath; isTypeOnly?: boolean }\n }\n matches: { keyword: 'matches'; args?: string }\n boolean: { keyword: 'boolean' }\n default: { keyword: 'default'; args: string | number | boolean }\n string: { keyword: 'string' }\n integer: { keyword: 'integer' }\n number: { keyword: 'number' }\n max: { keyword: 'max'; args: number }\n min: { keyword: 'min'; args: number }\n describe: { keyword: 'describe'; args: string }\n example: { keyword: 'example'; args: string }\n deprecated: { keyword: 'deprecated' }\n optional: { keyword: 'optional' }\n undefined: { keyword: 'undefined' }\n nullish: { keyword: 'nullish' }\n nullable: { keyword: 'nullable' }\n null: { keyword: 'null' }\n any: { keyword: 'any' }\n unknown: { keyword: 'unknown' }\n blob: { keyword: 'blob' }\n schema: { keyword: 'schema'; args: { type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'; format?: string } }\n name: { keyword: 'name'; args: string }\n catchall: { keyword: 'catchall' }\n}\n\nexport const schemaKeywords = {\n any: 'any',\n strict: 'strict',\n unknown: 'unknown',\n number: 'number',\n integer: 'integer',\n string: 'string',\n boolean: 'boolean',\n undefined: 'undefined',\n nullable: 'nullable',\n null: 'null',\n nullish: 'nullish',\n array: 'array',\n tuple: 'tuple',\n enum: 'enum',\n union: 'union',\n datetime: 'datetime',\n date: 'date',\n email: 'email',\n uuid: 'uuid',\n url: 'url',\n /* intersection */\n default: 'default',\n const: 'const',\n and: 'and',\n describe: 'describe',\n min: 'min',\n max: 'max',\n optional: 'optional',\n readOnly: 'readOnly',\n\n // custom ones\n object: 'object',\n ref: 'ref',\n matches: 'matches',\n firstName: 'firstName',\n lastName: 'lastName',\n password: 'password',\n phone: 'phone',\n blob: 'blob',\n deprecated: 'deprecated',\n example: 'example',\n schema: 'schema',\n catchall: 'catchall',\n time: 'time',\n name: 'name',\n} satisfies {\n [K in keyof SchemaKeywordMapper]: SchemaKeywordMapper[K]['keyword']\n}\n\nexport type SchemaKeyword = keyof SchemaKeywordMapper\n\nexport type SchemaMapper<T = string | null | undefined> = {\n [K in keyof SchemaKeywordMapper]: (() => T | undefined) | undefined\n}\n\nexport type SchemaKeywordBase<T> = {\n keyword: SchemaKeyword\n args: T\n}\n\nexport type Schema = { keyword: string } | SchemaKeywordMapper[keyof SchemaKeywordMapper]\n\nexport function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]> {\n return meta.keyword === keyword\n}\n"],"mappings":";;;;;AAAA;AA+EO,IAAM,iBAAiB;AAAA,EAC5B,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA;AAAA,EAEL,SAAS;AAAA,EACT,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AAAA,EACV,KAAK;AAAA,EACL,KAAK;AAAA,EACL,UAAU;AAAA,EACV,UAAU;AAAA;AAAA,EAGV,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,MAAM;AACR;AAiBO,SAAS,UAAiE,MAAS,SAAwD;AAChJ,SAAO,KAAK,YAAY;AAC1B;","names":[]}
@@ -1,81 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunkBDNSPC5Zcjs = require('./chunk-BDNSPC5Z.cjs');
4
-
5
- // src/utils/getSchemas.ts
6
- _chunkBDNSPC5Zcjs.init_cjs_shims.call(void 0, );
7
- function getSchemas({ oas, contentType, includes = ["schemas", "requestBodies", "responses"] }) {
8
- const components = oas.getDefinition().components;
9
- let schemas = {};
10
- if (includes.includes("schemas")) {
11
- schemas = {
12
- ...schemas,
13
- ..._optionalChain([components, 'optionalAccess', _ => _.schemas]) || {}
14
- };
15
- }
16
- const requestBodies = _optionalChain([components, 'optionalAccess', _2 => _2.requestBodies]) || {};
17
- if (includes.includes("responses")) {
18
- const responses = _optionalChain([components, 'optionalAccess', _3 => _3.responses]) || {};
19
- Object.entries(responses).forEach(([name, response]) => {
20
- if (response.content && !schemas[name]) {
21
- const firstContentType = Object.keys(response.content)[0] || "application/json";
22
- schemas[name] = _optionalChain([response, 'access', _4 => _4.content, 'optionalAccess', _5 => _5[contentType || firstContentType], 'optionalAccess', _6 => _6.schema]);
23
- }
24
- });
25
- }
26
- if (includes.includes("requestBodies")) {
27
- Object.entries(requestBodies).forEach(([name, request]) => {
28
- if (request.content && !schemas[name]) {
29
- const firstContentType = Object.keys(request.content)[0] || "application/json";
30
- schemas[name] = _optionalChain([request, 'access', _7 => _7.content, 'optionalAccess', _8 => _8[contentType || firstContentType], 'optionalAccess', _9 => _9.schema]);
31
- }
32
- });
33
- }
34
- return schemas;
35
- }
36
-
37
- // src/utils/parseFromConfig.ts
38
- _chunkBDNSPC5Zcjs.init_cjs_shims.call(void 0, );
39
- var _path = require('path');
40
- var _utils = require('@kubb/core/utils');
41
- var _parser = require('@kubb/oas/parser');
42
- var _yaml = require('@stoplight/yaml'); var _yaml2 = _interopRequireDefault(_yaml);
43
- function parseFromConfig(config, options = {}) {
44
- if ("data" in config.input) {
45
- if (typeof config.input.data === "object") {
46
- const api2 = JSON.parse(JSON.stringify(config.input.data));
47
- return _parser.parse.call(void 0, api2, options);
48
- }
49
- try {
50
- const api2 = _yaml2.default.parse(config.input.data);
51
- return _parser.parse.call(void 0, api2, options);
52
- } catch (e) {
53
- }
54
- const api = JSON.parse(JSON.stringify(config.input.data));
55
- return _parser.parse.call(void 0, api, options);
56
- }
57
- if (new (0, _utils.URLPath)(config.input.path).isURL) {
58
- return _parser.parse.call(void 0, config.input.path, options);
59
- }
60
- return _parser.parse.call(void 0, _path.resolve.call(void 0, config.root, config.input.path), options);
61
- }
62
-
63
- // src/utils/getSchemaFactory.ts
64
- _chunkBDNSPC5Zcjs.init_cjs_shims.call(void 0, );
65
- var _oas = require('@kubb/oas');
66
- function getSchemaFactory(oas) {
67
- return (schema) => {
68
- const version = _oas.isOpenApiV3_1Document.call(void 0, oas.api) ? "3.1" : "3.0";
69
- return {
70
- schema,
71
- version
72
- };
73
- };
74
- }
75
-
76
-
77
-
78
-
79
-
80
- exports.getSchemas = getSchemas; exports.parseFromConfig = parseFromConfig; exports.getSchemaFactory = getSchemaFactory;
81
- //# sourceMappingURL=chunk-I2JOGJIB.cjs.map