@kubb/plugin-ts 3.0.0-alpha.9 → 3.0.0-beta.2
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/README.md +14 -5
- package/dist/{chunk-UVAKTXUA.js → chunk-AG2BUY33.js} +86 -398
- package/dist/chunk-AG2BUY33.js.map +1 -0
- package/dist/chunk-L7QZ6DBL.cjs +332 -0
- package/dist/chunk-L7QZ6DBL.cjs.map +1 -0
- package/dist/chunk-QZ2DBYXR.js +303 -0
- package/dist/chunk-QZ2DBYXR.js.map +1 -0
- package/dist/{chunk-PV5Q7I5O.cjs → chunk-XMTK3ZZE.cjs} +185 -470
- package/dist/chunk-XMTK3ZZE.cjs.map +1 -0
- package/dist/components.cjs +11 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +14 -44
- package/dist/components.d.ts +14 -44
- package/dist/components.js +2 -16
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -123
- package/dist/index.d.ts +4 -123
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -1
- package/dist/types-DoCOabdx.d.cts +98 -0
- package/dist/types-DoCOabdx.d.ts +98 -0
- package/package.json +21 -15
- package/src/components/OasType.tsx +3 -50
- package/src/components/{Schema.tsx → Type.tsx} +19 -54
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
- package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/createPet.ts +41 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +41 -0
- package/src/generators/__snapshots__/deletePet.ts +5 -0
- package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/enumAllOf.ts +10 -0
- package/src/generators/__snapshots__/enumArray.ts +19 -0
- package/src/generators/__snapshots__/enumInObject.ts +13 -0
- package/src/generators/__snapshots__/enumItems.ts +8 -0
- package/src/generators/__snapshots__/enumNames.ts +6 -0
- package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
- package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
- package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
- package/src/generators/__snapshots__/enumNamesType.ts +8 -0
- package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
- package/src/generators/__snapshots__/enumNullableType.ts +8 -0
- package/src/generators/__snapshots__/enumString.ts +10 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
- package/src/generators/__snapshots__/getPets.ts +27 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
- package/src/generators/__snapshots__/nullConstNull.ts +7 -0
- package/src/generators/__snapshots__/numberValueConst.ts +9 -0
- package/src/generators/__snapshots__/petMapper.ts +15 -0
- package/src/generators/__snapshots__/petQuestionToken.ts +19 -0
- package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +19 -0
- package/src/generators/__snapshots__/petUndefined.ts +19 -0
- package/src/generators/__snapshots__/pets.ts +14 -0
- package/src/generators/__snapshots__/petsStoreAdvancedDiscriminator.ts +31 -0
- package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
- package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
- package/src/generators/__snapshots__/plainDateDate.ts +1 -0
- package/src/generators/__snapshots__/plainDateString.ts +1 -0
- package/src/generators/__snapshots__/plainEmail.ts +1 -0
- package/src/generators/__snapshots__/plainFile.ts +1 -0
- package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
- package/src/generators/__snapshots__/plainUuid.ts +1 -0
- package/src/generators/__snapshots__/readOnly.ts +20 -0
- package/src/{components/__snapshots__/Schema → generators/__snapshots__}/showPetById.ts +9 -9
- package/src/generators/__snapshots__/stringValueConst.ts +9 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/oasGenerator.tsx +29 -0
- package/src/generators/typeGenerator.tsx +200 -0
- package/src/parser/index.ts +12 -3
- package/src/plugin.ts +26 -33
- package/src/types.ts +16 -52
- package/dist/chunk-PV5Q7I5O.cjs.map +0 -1
- package/dist/chunk-SEH6NUCX.cjs +0 -42
- package/dist/chunk-SEH6NUCX.cjs.map +0 -1
- package/dist/chunk-TTGZBH7H.js +0 -42
- package/dist/chunk-TTGZBH7H.js.map +0 -1
- package/dist/chunk-UVAKTXUA.js.map +0 -1
- package/dist/oas.cjs +0 -7
- package/dist/oas.cjs.map +0 -1
- package/dist/oas.d.cts +0 -1
- package/dist/oas.d.ts +0 -1
- package/dist/oas.js +0 -7
- package/dist/oas.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -49
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -161
- package/src/components/__snapshots__/Schema/pets.ts +0 -27
- package/src/oas/index.ts +0 -1
package/src/SchemaGenerator.tsx
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { SchemaObject } from '@kubb/oas'
|
|
2
|
-
import { SchemaGenerator as Generator } from '@kubb/plugin-oas'
|
|
3
|
-
import type { SchemaMethodResult } from '@kubb/plugin-oas'
|
|
4
|
-
import { Oas } from '@kubb/plugin-oas/components'
|
|
5
|
-
import { App, createRoot } from '@kubb/react'
|
|
6
|
-
import { Schema } from './components/Schema.tsx'
|
|
7
|
-
import type { FileMeta, PluginTs } from './types.ts'
|
|
8
|
-
|
|
9
|
-
export class SchemaGenerator extends Generator<PluginTs['resolvedOptions'], PluginTs> {
|
|
10
|
-
async schema(name: string, schema: SchemaObject, options: PluginTs['resolvedOptions']): SchemaMethodResult<FileMeta> {
|
|
11
|
-
const { oas, pluginManager, plugin, mode, output } = this.context
|
|
12
|
-
|
|
13
|
-
const root = createRoot({
|
|
14
|
-
logger: pluginManager.logger,
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const tree = this.parse({ schema, name })
|
|
18
|
-
|
|
19
|
-
root.render(
|
|
20
|
-
<App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
|
|
21
|
-
<Oas oas={oas}>
|
|
22
|
-
<Oas.Schema name={name} value={schema} tree={tree}>
|
|
23
|
-
<Schema.File />
|
|
24
|
-
</Oas.Schema>
|
|
25
|
-
</Oas>
|
|
26
|
-
</App>,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
return root.files
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import transformers from '@kubb/core/transformers'
|
|
2
|
-
import { print } from '@kubb/parser-ts'
|
|
3
|
-
import * as factory from '@kubb/parser-ts/factory'
|
|
4
|
-
import { Oas } from '@kubb/plugin-oas/components'
|
|
5
|
-
import { useOas, useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
6
|
-
import { File, useApp } from '@kubb/react'
|
|
7
|
-
|
|
8
|
-
import { SchemaGenerator } from '../SchemaGenerator.tsx'
|
|
9
|
-
|
|
10
|
-
import type { PluginManager } from '@kubb/core'
|
|
11
|
-
import type { Operation } from '@kubb/oas'
|
|
12
|
-
import type { ts } from '@kubb/parser-ts'
|
|
13
|
-
import type { OperationSchema as OperationSchemaType } from '@kubb/plugin-oas'
|
|
14
|
-
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
15
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
16
|
-
import type { ReactNode } from 'react'
|
|
17
|
-
import type { FileMeta, PluginTs } from '../types.ts'
|
|
18
|
-
import { Schema } from './Schema.tsx'
|
|
19
|
-
|
|
20
|
-
function printCombinedSchema({
|
|
21
|
-
name,
|
|
22
|
-
operation,
|
|
23
|
-
schemas,
|
|
24
|
-
pluginManager,
|
|
25
|
-
}: { name: string; operation: Operation; schemas: OperationSchemas; pluginManager: PluginManager }): string {
|
|
26
|
-
const properties: Record<string, ts.TypeNode> = {}
|
|
27
|
-
|
|
28
|
-
if (schemas.response) {
|
|
29
|
-
const identifier = pluginManager.resolveName({
|
|
30
|
-
name: schemas.response.name,
|
|
31
|
-
pluginKey: [pluginTsName],
|
|
32
|
-
type: 'function',
|
|
33
|
-
})
|
|
34
|
-
properties['response'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (schemas.request) {
|
|
38
|
-
const identifier = pluginManager.resolveName({
|
|
39
|
-
name: schemas.request.name,
|
|
40
|
-
pluginKey: [pluginTsName],
|
|
41
|
-
type: 'function',
|
|
42
|
-
})
|
|
43
|
-
properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (schemas.pathParams) {
|
|
47
|
-
const identifier = pluginManager.resolveName({
|
|
48
|
-
name: schemas.pathParams.name,
|
|
49
|
-
pluginKey: [pluginTsName],
|
|
50
|
-
type: 'function',
|
|
51
|
-
})
|
|
52
|
-
properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (schemas.queryParams) {
|
|
56
|
-
const identifier = pluginManager.resolveName({
|
|
57
|
-
name: schemas.queryParams.name,
|
|
58
|
-
pluginKey: [pluginTsName],
|
|
59
|
-
type: 'function',
|
|
60
|
-
})
|
|
61
|
-
properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (schemas.headerParams) {
|
|
65
|
-
const identifier = pluginManager.resolveName({
|
|
66
|
-
name: schemas.headerParams.name,
|
|
67
|
-
pluginKey: [pluginTsName],
|
|
68
|
-
type: 'function',
|
|
69
|
-
})
|
|
70
|
-
properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (schemas.errors) {
|
|
74
|
-
properties['errors'] = factory.createUnionDeclaration({
|
|
75
|
-
nodes: schemas.errors.map((error) => {
|
|
76
|
-
const identifier = pluginManager.resolveName({
|
|
77
|
-
name: error.name,
|
|
78
|
-
pluginKey: [pluginTsName],
|
|
79
|
-
type: 'function',
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
83
|
-
}),
|
|
84
|
-
})!
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const namespaceNode = factory.createTypeAliasDeclaration({
|
|
88
|
-
name,
|
|
89
|
-
type: factory.createTypeLiteralNode(
|
|
90
|
-
Object.keys(properties)
|
|
91
|
-
.map((key) => {
|
|
92
|
-
const type = properties[key]
|
|
93
|
-
if (!type) {
|
|
94
|
-
return undefined
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return factory.createPropertySignature({
|
|
98
|
-
name: transformers.pascalCase(key),
|
|
99
|
-
type,
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
.filter(Boolean),
|
|
103
|
-
),
|
|
104
|
-
modifiers: [factory.modifiers.export],
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
return print(namespaceNode)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
type Props = {
|
|
111
|
-
description?: string
|
|
112
|
-
keysToOmit?: string[]
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function OperationSchema({ keysToOmit, description }: Props): ReactNode {
|
|
116
|
-
return <Schema keysToOmit={keysToOmit} description={description} />
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
type FileProps = {}
|
|
120
|
-
|
|
121
|
-
OperationSchema.File = function ({}: FileProps): ReactNode {
|
|
122
|
-
const { pluginManager, plugin, mode } = useApp<PluginTs>()
|
|
123
|
-
const oas = useOas()
|
|
124
|
-
const { getSchemas, getFile, getName } = useOperationManager()
|
|
125
|
-
const operation = useOperation()
|
|
126
|
-
|
|
127
|
-
const file = getFile(operation)
|
|
128
|
-
const schemas = getSchemas(operation)
|
|
129
|
-
const factoryName = getName(operation, { type: 'type' })
|
|
130
|
-
const generator = new SchemaGenerator(plugin.options, {
|
|
131
|
-
oas,
|
|
132
|
-
plugin,
|
|
133
|
-
pluginManager,
|
|
134
|
-
mode,
|
|
135
|
-
override: plugin.options.override,
|
|
136
|
-
})
|
|
137
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean)
|
|
138
|
-
|
|
139
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {
|
|
140
|
-
const tree = generator.parse({ schema, name })
|
|
141
|
-
|
|
142
|
-
return (
|
|
143
|
-
<Oas.Schema key={i} name={name} value={schema} tree={tree}>
|
|
144
|
-
{mode === 'split' && <Oas.Schema.Imports isTypeOnly />}
|
|
145
|
-
<OperationSchema description={description} keysToOmit={keysToOmit} />
|
|
146
|
-
</Oas.Schema>
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const combinedSchemaName = operation.method === 'get' ? `${factoryName}Query` : `${factoryName}Mutation`
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
154
|
-
{items.map(mapItem)}
|
|
155
|
-
|
|
156
|
-
<File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>
|
|
157
|
-
{printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager })}
|
|
158
|
-
</File.Source>
|
|
159
|
-
</File>
|
|
160
|
-
)
|
|
161
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Null response
|
|
3
|
-
*/
|
|
4
|
-
export type createPets201 = any;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @description unexpected error
|
|
8
|
-
*/
|
|
9
|
-
export type createPetsError = error;
|
|
10
|
-
|
|
11
|
-
export type createPetsMutationRequest = {
|
|
12
|
-
/**
|
|
13
|
-
* @type string
|
|
14
|
-
*/
|
|
15
|
-
name: string;
|
|
16
|
-
/**
|
|
17
|
-
* @type string
|
|
18
|
-
*/
|
|
19
|
-
tag: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type createPetsMutationResponse = any;
|
|
23
|
-
|
|
24
|
-
export type CreatePetsMutation = {
|
|
25
|
-
Response: createPetsMutationResponse;
|
|
26
|
-
Request: createPetsMutationRequest;
|
|
27
|
-
};
|
package/src/oas/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { Infer, Response, RequestParams, Model } from '@kubb/oas'
|