@kubb/plugin-oas 0.0.0-canary-20240509211223

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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/OperationGenerator-DvnXUUp4.d.ts +56 -0
  4. package/dist/OperationGenerator-X6CTMfhG.d.cts +56 -0
  5. package/dist/Schema-BWPWyiQO.d.cts +39 -0
  6. package/dist/Schema-DFZBfjF2.d.ts +39 -0
  7. package/dist/SchemaGenerator-hK5SHxTI.d.ts +316 -0
  8. package/dist/SchemaGenerator-z_7YrAAB.d.cts +316 -0
  9. package/dist/chunk-2MJ2CQMI.js +61 -0
  10. package/dist/chunk-2MJ2CQMI.js.map +1 -0
  11. package/dist/chunk-3RCQ2LNT.js +81 -0
  12. package/dist/chunk-3RCQ2LNT.js.map +1 -0
  13. package/dist/chunk-55NUFNT6.cjs +68 -0
  14. package/dist/chunk-55NUFNT6.cjs.map +1 -0
  15. package/dist/chunk-ECXSQTMV.cjs +81 -0
  16. package/dist/chunk-ECXSQTMV.cjs.map +1 -0
  17. package/dist/chunk-EPTOYYAP.js +3312 -0
  18. package/dist/chunk-EPTOYYAP.js.map +1 -0
  19. package/dist/chunk-H52M2RUX.cjs +3312 -0
  20. package/dist/chunk-H52M2RUX.cjs.map +1 -0
  21. package/dist/chunk-LQ6IAWRX.js +68 -0
  22. package/dist/chunk-LQ6IAWRX.js.map +1 -0
  23. package/dist/chunk-VNFSHGSN.cjs +61 -0
  24. package/dist/chunk-VNFSHGSN.cjs.map +1 -0
  25. package/dist/components.cjs +18 -0
  26. package/dist/components.cjs.map +1 -0
  27. package/dist/components.d.cts +41 -0
  28. package/dist/components.d.ts +41 -0
  29. package/dist/components.js +18 -0
  30. package/dist/components.js.map +1 -0
  31. package/dist/hooks.cjs +152 -0
  32. package/dist/hooks.cjs.map +1 -0
  33. package/dist/hooks.d.cts +76 -0
  34. package/dist/hooks.d.ts +76 -0
  35. package/dist/hooks.js +152 -0
  36. package/dist/hooks.js.map +1 -0
  37. package/dist/index.cjs +985 -0
  38. package/dist/index.cjs.map +1 -0
  39. package/dist/index.d.cts +17 -0
  40. package/dist/index.d.ts +17 -0
  41. package/dist/index.js +985 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/types-n5zV4Q3s.d.cts +146 -0
  44. package/dist/types-n5zV4Q3s.d.ts +146 -0
  45. package/dist/utils.cjs +126 -0
  46. package/dist/utils.cjs.map +1 -0
  47. package/dist/utils.d.cts +80 -0
  48. package/dist/utils.d.ts +80 -0
  49. package/dist/utils.js +126 -0
  50. package/dist/utils.js.map +1 -0
  51. package/package.json +107 -0
  52. package/src/OperationGenerator.ts +328 -0
  53. package/src/SchemaGenerator.ts +827 -0
  54. package/src/SchemaMapper.ts +145 -0
  55. package/src/components/Oas.tsx +31 -0
  56. package/src/components/Operation.tsx +21 -0
  57. package/src/components/Schema.tsx +156 -0
  58. package/src/components/index.ts +3 -0
  59. package/src/hooks/index.ts +5 -0
  60. package/src/hooks/useOas.ts +15 -0
  61. package/src/hooks/useOperation.ts +18 -0
  62. package/src/hooks/useOperationManager.ts +142 -0
  63. package/src/hooks/useOperations.ts +40 -0
  64. package/src/hooks/useSchema.ts +23 -0
  65. package/src/index.ts +30 -0
  66. package/src/plugin.ts +133 -0
  67. package/src/types.ts +147 -0
  68. package/src/utils/getComments.ts +15 -0
  69. package/src/utils/getGroupedByTagFiles.ts +81 -0
  70. package/src/utils/getParams.ts +57 -0
  71. package/src/utils/getSchemaFactory.ts +33 -0
  72. package/src/utils/getSchemas.ts +45 -0
  73. package/src/utils/index.ts +8 -0
  74. package/src/utils/parseFromConfig.ts +36 -0
  75. package/src/utils/refSorter.ts +13 -0
@@ -0,0 +1,145 @@
1
+ import type { KubbFile } from '@kubb/core'
2
+
3
+ export type SchemaKeywordMapper = {
4
+ object: {
5
+ keyword: 'object'
6
+ args: {
7
+ properties: { [x: string]: Schema[] }
8
+ additionalProperties: Schema[]
9
+ strict?: boolean
10
+ }
11
+ }
12
+ strict: { keyword: 'strict' }
13
+ url: { keyword: 'url' }
14
+ readOnly: { keyword: 'readOnly' }
15
+ uuid: { keyword: 'uuid' }
16
+ email: { keyword: 'email' }
17
+ firstName: { keyword: 'firstName' }
18
+ lastName: { keyword: 'lastName' }
19
+ phone: { keyword: 'phone' }
20
+ password: { keyword: 'password' }
21
+ date: { keyword: 'date'; args: { type?: 'date' | 'string' } }
22
+ time: { keyword: 'time'; args: { type?: 'date' | 'string' } }
23
+ datetime: { keyword: 'datetime'; args: { offset?: boolean; local?: boolean } }
24
+ tuple: { keyword: 'tuple'; args: Schema[] }
25
+ array: {
26
+ keyword: 'array'
27
+ args: { items: Schema[]; min?: number; max?: number }
28
+ }
29
+ enum: {
30
+ keyword: 'enum'
31
+ args: {
32
+ name: string
33
+ typeName: string
34
+ asConst: boolean
35
+ items: Array<{
36
+ name: string | number
37
+ format: 'string' | 'number'
38
+ value?: string | number
39
+ }>
40
+ }
41
+ }
42
+ and: { keyword: 'and'; args: Schema[] }
43
+ const: {
44
+ keyword: 'const'
45
+ args: {
46
+ name: string | number
47
+ format: 'string' | 'number'
48
+ value?: string | number
49
+ }
50
+ }
51
+ union: { keyword: 'union'; args: Schema[] }
52
+ ref: {
53
+ keyword: 'ref'
54
+ args: { name: string; path: KubbFile.OptionalPath; isTypeOnly?: boolean }
55
+ }
56
+ matches: { keyword: 'matches'; args?: string }
57
+ boolean: { keyword: 'boolean' }
58
+ default: { keyword: 'default'; args: string | number | boolean }
59
+ string: { keyword: 'string' }
60
+ integer: { keyword: 'integer' }
61
+ number: { keyword: 'number' }
62
+ max: { keyword: 'max'; args: number }
63
+ min: { keyword: 'min'; args: number }
64
+ describe: { keyword: 'describe'; args: string }
65
+ example: { keyword: 'example'; args: string }
66
+ deprecated: { keyword: 'deprecated' }
67
+ optional: { keyword: 'optional' }
68
+ undefined: { keyword: 'undefined' }
69
+ nullish: { keyword: 'nullish' }
70
+ nullable: { keyword: 'nullable' }
71
+ null: { keyword: 'null' }
72
+ any: { keyword: 'any' }
73
+ unknown: { keyword: 'unknown' }
74
+ blob: { keyword: 'blob' }
75
+ schema: { keyword: 'schema'; args: { type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'; format?: string } }
76
+ name: { keyword: 'name'; args: string }
77
+ catchall: { keyword: 'catchall' }
78
+ }
79
+
80
+ export const schemaKeywords = {
81
+ any: 'any',
82
+ strict: 'strict',
83
+ unknown: 'unknown',
84
+ number: 'number',
85
+ integer: 'integer',
86
+ string: 'string',
87
+ boolean: 'boolean',
88
+ undefined: 'undefined',
89
+ nullable: 'nullable',
90
+ null: 'null',
91
+ nullish: 'nullish',
92
+ array: 'array',
93
+ tuple: 'tuple',
94
+ enum: 'enum',
95
+ union: 'union',
96
+ datetime: 'datetime',
97
+ date: 'date',
98
+ email: 'email',
99
+ uuid: 'uuid',
100
+ url: 'url',
101
+ /* intersection */
102
+ default: 'default',
103
+ const: 'const',
104
+ and: 'and',
105
+ describe: 'describe',
106
+ min: 'min',
107
+ max: 'max',
108
+ optional: 'optional',
109
+ readOnly: 'readOnly',
110
+
111
+ // custom ones
112
+ object: 'object',
113
+ ref: 'ref',
114
+ matches: 'matches',
115
+ firstName: 'firstName',
116
+ lastName: 'lastName',
117
+ password: 'password',
118
+ phone: 'phone',
119
+ blob: 'blob',
120
+ deprecated: 'deprecated',
121
+ example: 'example',
122
+ schema: 'schema',
123
+ catchall: 'catchall',
124
+ time: 'time',
125
+ name: 'name',
126
+ } satisfies {
127
+ [K in keyof SchemaKeywordMapper]: SchemaKeywordMapper[K]['keyword']
128
+ }
129
+
130
+ export type SchemaKeyword = keyof SchemaKeywordMapper
131
+
132
+ export type SchemaMapper<T = string | null | undefined> = {
133
+ [K in keyof SchemaKeywordMapper]: (() => T | undefined) | undefined
134
+ }
135
+
136
+ export type SchemaKeywordBase<T> = {
137
+ keyword: SchemaKeyword
138
+ args: T
139
+ }
140
+
141
+ export type Schema = { keyword: string } | SchemaKeywordMapper[keyof SchemaKeywordMapper]
142
+
143
+ export function isKeyword<T extends Schema, K extends keyof SchemaKeywordMapper>(meta: T, keyword: K): meta is Extract<T, SchemaKeywordMapper[K]> {
144
+ return meta.keyword === keyword
145
+ }
@@ -0,0 +1,31 @@
1
+ import { createContext } from '@kubb/react'
2
+
3
+ import { Operation } from './Operation.tsx'
4
+ import { Schema } from './Schema.tsx'
5
+
6
+ import type { Oas as OasType, Operation as OperationType } from '@kubb/oas'
7
+ import type { KubbNode } from '@kubb/react'
8
+ import type { OperationGenerator } from '../OperationGenerator.ts'
9
+
10
+ type Props = {
11
+ oas: OasType
12
+ operations?: OperationType[]
13
+ generator?: OperationGenerator
14
+ children?: KubbNode
15
+ }
16
+
17
+ type OasContextProps = {
18
+ oas?: OasType
19
+ operations?: OperationType[]
20
+ generator?: OperationGenerator
21
+ }
22
+
23
+ const OasContext = createContext<OasContextProps>({})
24
+
25
+ export function Oas({ oas, children, operations, generator }: Props): KubbNode {
26
+ return <OasContext.Provider value={{ oas, generator, operations }}>{children}</OasContext.Provider>
27
+ }
28
+
29
+ Oas.Context = OasContext
30
+ Oas.Operation = Operation
31
+ Oas.Schema = Schema
@@ -0,0 +1,21 @@
1
+ import { createContext } from '@kubb/react'
2
+
3
+ import type { Operation as OperationType } from '@kubb/oas'
4
+ import type { KubbNode } from '@kubb/react'
5
+
6
+ type Props = {
7
+ operation: OperationType
8
+ children?: KubbNode
9
+ }
10
+
11
+ type OperationContextProps = {
12
+ operation?: OperationType
13
+ }
14
+
15
+ const OperationContext = createContext<OperationContextProps>({})
16
+
17
+ export function Operation({ operation, children }: Props): KubbNode {
18
+ return <OperationContext.Provider value={{ operation }}>{children}</OperationContext.Provider>
19
+ }
20
+
21
+ Operation.Context = OperationContext
@@ -0,0 +1,156 @@
1
+ import { Parser, File, createContext, useApp, useFile } from '@kubb/react'
2
+
3
+ import { schemaKeywords } from '../SchemaMapper.ts'
4
+ import { useSchema } from '../hooks/useSchema.ts'
5
+
6
+ import type { KubbFile } from '@kubb/core'
7
+ import type { SchemaObject } from '@kubb/oas'
8
+ import type { KubbNode } from '@kubb/react'
9
+ import type { ReactNode } from 'react'
10
+ import type { SchemaGenerator, SchemaGeneratorBuildOptions } from '../SchemaGenerator.ts'
11
+ import type { Schema as SchemaType } from '../SchemaMapper.ts'
12
+ import type { PluginOas } from '../types.ts'
13
+
14
+ export type SchemaContextProps = {
15
+ name: string
16
+ object?: SchemaObject
17
+ generator?: SchemaGenerator
18
+ schemas: SchemaType[]
19
+ }
20
+
21
+ type Props = {
22
+ name: string
23
+ object?: SchemaObject
24
+ generator: SchemaGenerator<any, any, any>
25
+ children?: KubbNode
26
+ }
27
+
28
+ const SchemaContext = createContext<SchemaContextProps>({
29
+ name: 'unknown',
30
+ schemas: [],
31
+ })
32
+
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>
37
+ }
38
+
39
+ type FileProps = {
40
+ isTypeOnly?: boolean
41
+ output: string | undefined
42
+ children?: KubbNode
43
+ }
44
+
45
+ Schema.File = function ({ output, isTypeOnly, children }: FileProps): ReactNode {
46
+ const { plugin, pluginManager, mode } = useApp<PluginOas>()
47
+ const { name } = useSchema()
48
+
49
+ if (mode === 'single') {
50
+ const baseName = output as KubbFile.BaseName
51
+ const resolvedPath = pluginManager.resolvePath({
52
+ baseName: '',
53
+ pluginKey: plugin.key,
54
+ })
55
+
56
+ if (!resolvedPath) {
57
+ return null
58
+ }
59
+
60
+ return (
61
+ <Parser language="typescript">
62
+ <File
63
+ baseName={baseName}
64
+ path={resolvedPath}
65
+ meta={{
66
+ pluginKey: plugin.key,
67
+ }}
68
+ >
69
+ <File.Source>
70
+ <Schema.Source />
71
+ </File.Source>
72
+ {children}
73
+ </File>
74
+ </Parser>
75
+ )
76
+ }
77
+
78
+ const baseName = `${pluginManager.resolveName({
79
+ name,
80
+ pluginKey: plugin.key,
81
+ type: 'file',
82
+ })}.ts` as const
83
+ const resolvedPath = pluginManager.resolvePath({
84
+ baseName,
85
+ pluginKey: plugin.key,
86
+ })
87
+
88
+ if (!resolvedPath) {
89
+ return null
90
+ }
91
+
92
+ return (
93
+ <Parser language="typescript">
94
+ <File
95
+ baseName={baseName}
96
+ path={resolvedPath}
97
+ meta={{
98
+ pluginKey: plugin.key,
99
+ }}
100
+ >
101
+ <Schema.Imports isTypeOnly={isTypeOnly} />
102
+ <File.Source>
103
+ <Schema.Source />
104
+ </File.Source>
105
+ {children}
106
+ </File>
107
+ </Parser>
108
+ )
109
+ }
110
+
111
+ type SchemaImportsProps = {
112
+ isTypeOnly?: boolean
113
+ }
114
+
115
+ Schema.Imports = ({ isTypeOnly }: SchemaImportsProps): ReactNode => {
116
+ const { generator, schemas } = useSchema()
117
+ const { path: root } = useFile()
118
+
119
+ const refs = generator.deepSearch(schemas, schemaKeywords.ref)
120
+
121
+ return (
122
+ <>
123
+ {refs
124
+ ?.map((item, i) => {
125
+ if (!item.args.path) {
126
+ return undefined
127
+ }
128
+
129
+ return <File.Import key={i} root={root} name={[item.args.name]} path={item.args.path} isTypeOnly={item.args.isTypeOnly ?? isTypeOnly} />
130
+ })
131
+ .filter(Boolean)}
132
+ </>
133
+ )
134
+ }
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
+ Schema.Context = SchemaContext
@@ -0,0 +1,3 @@
1
+ export { Oas } from './Oas.tsx'
2
+ export { Operation } from './Operation.tsx'
3
+ export { Schema } from './Schema.tsx'
@@ -0,0 +1,5 @@
1
+ export { useOas } from './useOas.ts'
2
+ export { useOperation } from './useOperation.ts'
3
+ export { useOperationManager } from './useOperationManager.ts'
4
+ export { useOperations } from './useOperations.ts'
5
+ export { useSchema } from './useSchema.ts'
@@ -0,0 +1,15 @@
1
+ import { useContext } from '@kubb/react'
2
+
3
+ import { Oas } from '../components/Oas.tsx'
4
+
5
+ import type { Oas as OasType } from '@kubb/oas'
6
+
7
+ export function useOas(): OasType {
8
+ const { oas } = useContext(Oas.Context)
9
+
10
+ if (!oas) {
11
+ throw new Error('Oas is not defined')
12
+ }
13
+
14
+ return oas
15
+ }
@@ -0,0 +1,18 @@
1
+ import { useContext } from '@kubb/react'
2
+
3
+ import { Operation } from '../components/Operation.tsx'
4
+
5
+ import type { Operation as OperationType } from '@kubb/oas'
6
+
7
+ /**
8
+ * `useOperation` will return the current `Operation`
9
+ */
10
+ export function useOperation(): OperationType {
11
+ const { operation } = useContext(Operation.Context)
12
+
13
+ if (!operation) {
14
+ throw new Error('Operation is not defined')
15
+ }
16
+
17
+ return operation
18
+ }
@@ -0,0 +1,142 @@
1
+ import { useApp, useContext } from '@kubb/react'
2
+
3
+ import { Oas } from '../components/Oas.tsx'
4
+
5
+ import type { KubbFile, Plugin, ResolveNameParams } from '@kubb/core'
6
+ import type { Operation, Operation as OperationType } from '@kubb/oas'
7
+ import type { OperationSchemas } from '../types.ts'
8
+
9
+ type FileMeta = KubbFile.FileMetaBase & {
10
+ pluginKey: Plugin['key']
11
+ name: string
12
+ tag?: string
13
+ }
14
+
15
+ type SchemaNames = {
16
+ request: string | undefined
17
+ parameters: {
18
+ path: string | undefined
19
+ query: string | undefined
20
+ header: string | undefined
21
+ }
22
+ responses: Record<number, string>
23
+ }
24
+
25
+ type UseOperationManagerResult = {
26
+ getName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string
27
+ getFile: (operation: OperationType, params?: { pluginKey?: Plugin['key']; extName?: KubbFile.Extname }) => KubbFile.File<FileMeta>
28
+ groupSchemasByByName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => SchemaNames
29
+ getSchemas: (operation: Operation, forStatusCode?: string | number) => OperationSchemas
30
+ }
31
+
32
+ /**
33
+ * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
34
+ */
35
+ export function useOperationManager(): UseOperationManagerResult {
36
+ const { plugin, pluginManager } = useApp()
37
+ const { generator } = useContext(Oas.Context)
38
+
39
+ if (!generator) {
40
+ throw new Error(`'generator' is not defined`)
41
+ }
42
+
43
+ const getName: UseOperationManagerResult['getName'] = (operation, { pluginKey = plugin.key, type }) => {
44
+ return pluginManager.resolveName({
45
+ name: operation.getOperationId(),
46
+ pluginKey,
47
+ type,
48
+ })
49
+ }
50
+
51
+ const getFile: UseOperationManagerResult['getFile'] = (operation, { pluginKey = plugin.key, extName = '.ts' } = {}) => {
52
+ // needed for the `output.group`
53
+ const tag = operation.getTags().at(0)?.name
54
+ const name = getName(operation, { type: 'file', pluginKey })
55
+
56
+ const file = pluginManager.getFile({
57
+ name,
58
+ extName,
59
+ pluginKey,
60
+ options: { type: 'file', pluginKey, tag },
61
+ })
62
+
63
+ return {
64
+ ...file,
65
+ meta: {
66
+ ...file.meta,
67
+ name,
68
+ pluginKey,
69
+ tag,
70
+ },
71
+ }
72
+ }
73
+
74
+ const groupSchemasByByName: UseOperationManagerResult['groupSchemasByByName'] = (operation, { pluginKey = plugin.key, type }) => {
75
+ const schemas = generator.getSchemas(operation)
76
+
77
+ const errors = (schemas.errors || []).reduce(
78
+ (prev, acc) => {
79
+ if (!acc.statusCode) {
80
+ return prev
81
+ }
82
+
83
+ prev[acc.statusCode] = pluginManager.resolveName({
84
+ name: acc.name,
85
+ pluginKey: plugin.key,
86
+ type,
87
+ })
88
+
89
+ return prev
90
+ },
91
+ {} as Record<number, string>,
92
+ )
93
+
94
+ return {
95
+ request: schemas.request?.name
96
+ ? pluginManager.resolveName({
97
+ name: schemas.request.name,
98
+ pluginKey,
99
+ type,
100
+ })
101
+ : undefined,
102
+ parameters: {
103
+ path: schemas.pathParams?.name
104
+ ? pluginManager.resolveName({
105
+ name: schemas.pathParams.name,
106
+ pluginKey,
107
+ type,
108
+ })
109
+ : undefined,
110
+ query: schemas.queryParams?.name
111
+ ? pluginManager.resolveName({
112
+ name: schemas.queryParams.name,
113
+ pluginKey,
114
+ type,
115
+ })
116
+ : undefined,
117
+ header: schemas.headerParams?.name
118
+ ? pluginManager.resolveName({
119
+ name: schemas.headerParams.name,
120
+ pluginKey,
121
+ type,
122
+ })
123
+ : undefined,
124
+ },
125
+ responses: {
126
+ [schemas.response.statusCode || 'default']: pluginManager.resolveName({
127
+ name: schemas.response.name,
128
+ pluginKey,
129
+ type,
130
+ }),
131
+ ...errors,
132
+ },
133
+ }
134
+ }
135
+
136
+ return {
137
+ getName,
138
+ getFile,
139
+ getSchemas: (operation, forStatusCode) => generator.getSchemas(operation, forStatusCode),
140
+ groupSchemasByByName,
141
+ }
142
+ }
@@ -0,0 +1,40 @@
1
+ import { useContext } from '@kubb/react'
2
+
3
+ import { Oas } from '../components/Oas.tsx'
4
+
5
+ import type { HttpMethod, Operation } from '@kubb/oas'
6
+
7
+ type UseOperationsProps = {
8
+ /**
9
+ * Filter based on path
10
+ * Weight: 2
11
+ */
12
+ path?: string
13
+ /**
14
+ * Filter based on method
15
+ * Weight: 1
16
+ */
17
+ method?: HttpMethod
18
+ }
19
+
20
+ /**
21
+ * `useOperations` will return all the Operations
22
+ */
23
+ export function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {
24
+ const { operations } = useContext(Oas.Context)
25
+
26
+ if (!operations) {
27
+ throw new Error('Operations is not defined')
28
+ }
29
+ let items = operations
30
+
31
+ if (path) {
32
+ items = items.filter((item) => item.path === path)
33
+ }
34
+
35
+ if (method) {
36
+ items = items.filter((item) => item.method === method)
37
+ }
38
+
39
+ return items
40
+ }
@@ -0,0 +1,23 @@
1
+ import { useContext } from '@kubb/react'
2
+
3
+ import { Schema } from '../components/Schema.tsx'
4
+
5
+ import type { SchemaContextProps } from '../components/Schema.tsx'
6
+ import type { SchemaGenerator } from '../SchemaGenerator.ts'
7
+
8
+ type UseSchemaResult = Omit<SchemaContextProps, 'generator'> & {
9
+ generator: SchemaGenerator
10
+ }
11
+
12
+ /**
13
+ * `useSchema` will return the current `schema properties`
14
+ */
15
+ export function useSchema(): UseSchemaResult {
16
+ const props = useContext(Schema.Context)
17
+
18
+ if (!props.generator) {
19
+ throw new Error('Generator is not defined')
20
+ }
21
+
22
+ return props as UseSchemaResult
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { pluginOas } from './plugin.ts'
2
+
3
+ export type {
4
+ GetOperationGeneratorOptions,
5
+ OperationMethodResult,
6
+ } from './OperationGenerator.ts'
7
+ export { OperationGenerator } from './OperationGenerator.ts'
8
+ export { pluginOas, pluginOasName } from './plugin.ts'
9
+ export type {
10
+ SchemaGeneratorBuildOptions,
11
+ SchemaGeneratorOptions,
12
+ } from './SchemaGenerator.ts'
13
+ export type { SchemaMethodResult } from './SchemaGenerator.ts'
14
+ export { SchemaGenerator } from './SchemaGenerator.ts'
15
+ export type {
16
+ Schema,
17
+ SchemaKeyword,
18
+ SchemaKeywordBase,
19
+ SchemaKeywordMapper,
20
+ SchemaMapper,
21
+ } from './SchemaMapper.ts'
22
+ export { isKeyword, schemaKeywords } from './SchemaMapper.ts'
23
+ export type * from './types.ts'
24
+
25
+ /**
26
+ * @deprecated Use `import { pluginOas } from '@kubb/plugin-oas'` instead
27
+ */
28
+ const definePluginDefault = pluginOas
29
+
30
+ export default definePluginDefault