@kubb/plugin-ts 3.0.0-alpha.3 → 3.0.0-alpha.31
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 +13 -4
- package/dist/chunk-3KENUSSE.cjs +333 -0
- package/dist/chunk-3KENUSSE.cjs.map +1 -0
- package/dist/chunk-DHXAYDWQ.js +2521 -0
- package/dist/chunk-DHXAYDWQ.js.map +1 -0
- package/dist/chunk-GH3OAKXH.cjs +2548 -0
- package/dist/chunk-GH3OAKXH.cjs.map +1 -0
- package/dist/chunk-LVVDXT74.js +304 -0
- package/dist/chunk-LVVDXT74.js.map +1 -0
- package/dist/components.cjs +11 -6
- 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 -10
- 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 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -122
- package/dist/index.d.ts +4 -122
- package/dist/index.js +3 -8
- package/dist/index.js.map +1 -1
- package/dist/types-BOx2a6KB.d.cts +110 -0
- package/dist/types-BOx2a6KB.d.ts +110 -0
- package/package.json +21 -15
- package/src/components/OasType.tsx +11 -58
- package/src/components/Type.tsx +133 -0
- 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/generators/__snapshots__/showPetById.ts +32 -0
- 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 +13 -3
- package/src/plugin.ts +15 -17
- package/src/types.ts +14 -36
- package/dist/chunk-JF3PKBEA.cjs +0 -608
- package/dist/chunk-JF3PKBEA.cjs.map +0 -1
- package/dist/chunk-PU22CLWV.js +0 -608
- package/dist/chunk-PU22CLWV.js.map +0 -1
- package/dist/oas.cjs +0 -1
- 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 -1
- 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/Schema.tsx +0 -135
- package/src/components/__snapshots__/Schema/pets.ts +0 -23
- package/src/components/__snapshots__/Schema/showPetById.ts +0 -28
- package/src/oas/index.ts +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type ShowPetByIdPathParams = {
|
|
2
|
+
/**
|
|
3
|
+
* @description The id of the pet to retrieve
|
|
4
|
+
* @type string
|
|
5
|
+
*/
|
|
6
|
+
petId: string;
|
|
7
|
+
/**
|
|
8
|
+
* @description The id of the pet to retrieve
|
|
9
|
+
* @type string
|
|
10
|
+
*/
|
|
11
|
+
testId: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @description Expected response to a valid request
|
|
16
|
+
*/
|
|
17
|
+
export type ShowPetById200 = pet;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @description unexpected error
|
|
21
|
+
*/
|
|
22
|
+
export type ShowPetByIdError = error;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description Expected response to a valid request
|
|
26
|
+
*/
|
|
27
|
+
export type ShowPetByIdQueryResponse = pet;
|
|
28
|
+
|
|
29
|
+
export type showPetByIdQuery = {
|
|
30
|
+
Response: showPetByIdQueryResponse;
|
|
31
|
+
PathParams: showPetByIdPathParams;
|
|
32
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
2
|
+
import { useOas } from '@kubb/plugin-oas/hooks'
|
|
3
|
+
import { File, useApp } from '@kubb/react'
|
|
4
|
+
import { OasType } from '../components'
|
|
5
|
+
import type { PluginTs } from '../types.ts'
|
|
6
|
+
|
|
7
|
+
export const oasGenerator = createReactGenerator<PluginTs>({
|
|
8
|
+
name: 'oas',
|
|
9
|
+
Operations() {
|
|
10
|
+
const {
|
|
11
|
+
pluginManager,
|
|
12
|
+
plugin: {
|
|
13
|
+
options: { output },
|
|
14
|
+
key: pluginKey,
|
|
15
|
+
},
|
|
16
|
+
} = useApp<PluginTs>()
|
|
17
|
+
const oas = useOas()
|
|
18
|
+
|
|
19
|
+
const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>
|
|
23
|
+
<File.Import name={['Infer']} path="@kubb/oas" isTypeOnly />
|
|
24
|
+
|
|
25
|
+
<OasType name={'oas'} typeName={'Oas'} api={oas.api} />
|
|
26
|
+
</File>
|
|
27
|
+
)
|
|
28
|
+
},
|
|
29
|
+
})
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import type { PluginManager } from '@kubb/core'
|
|
2
|
+
import transformers from '@kubb/core/transformers'
|
|
3
|
+
import { print } from '@kubb/parser-ts'
|
|
4
|
+
import * as factory from '@kubb/parser-ts/factory'
|
|
5
|
+
import { type OperationSchema as OperationSchemaType, type OperationSchemas, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
6
|
+
import { Oas } from '@kubb/plugin-oas/components'
|
|
7
|
+
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
|
|
8
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
9
|
+
import { File, useApp } from '@kubb/react'
|
|
10
|
+
import type ts from 'typescript'
|
|
11
|
+
import { Type } from '../components'
|
|
12
|
+
import type { PluginTs } from '../types'
|
|
13
|
+
|
|
14
|
+
function printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {
|
|
15
|
+
const properties: Record<string, ts.TypeNode> = {}
|
|
16
|
+
|
|
17
|
+
if (schemas.response) {
|
|
18
|
+
const identifier = pluginManager.resolveName({
|
|
19
|
+
name: schemas.response.name,
|
|
20
|
+
pluginKey: [pluginTsName],
|
|
21
|
+
type: 'function',
|
|
22
|
+
})
|
|
23
|
+
properties['response'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (schemas.request) {
|
|
27
|
+
const identifier = pluginManager.resolveName({
|
|
28
|
+
name: schemas.request.name,
|
|
29
|
+
pluginKey: [pluginTsName],
|
|
30
|
+
type: 'function',
|
|
31
|
+
})
|
|
32
|
+
properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (schemas.pathParams) {
|
|
36
|
+
const identifier = pluginManager.resolveName({
|
|
37
|
+
name: schemas.pathParams.name,
|
|
38
|
+
pluginKey: [pluginTsName],
|
|
39
|
+
type: 'function',
|
|
40
|
+
})
|
|
41
|
+
properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (schemas.queryParams) {
|
|
45
|
+
const identifier = pluginManager.resolveName({
|
|
46
|
+
name: schemas.queryParams.name,
|
|
47
|
+
pluginKey: [pluginTsName],
|
|
48
|
+
type: 'function',
|
|
49
|
+
})
|
|
50
|
+
properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (schemas.headerParams) {
|
|
54
|
+
const identifier = pluginManager.resolveName({
|
|
55
|
+
name: schemas.headerParams.name,
|
|
56
|
+
pluginKey: [pluginTsName],
|
|
57
|
+
type: 'function',
|
|
58
|
+
})
|
|
59
|
+
properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (schemas.errors) {
|
|
63
|
+
properties['errors'] = factory.createUnionDeclaration({
|
|
64
|
+
nodes: schemas.errors.map((error) => {
|
|
65
|
+
const identifier = pluginManager.resolveName({
|
|
66
|
+
name: error.name,
|
|
67
|
+
pluginKey: [pluginTsName],
|
|
68
|
+
type: 'function',
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)
|
|
72
|
+
}),
|
|
73
|
+
})!
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const namespaceNode = factory.createTypeAliasDeclaration({
|
|
77
|
+
name,
|
|
78
|
+
type: factory.createTypeLiteralNode(
|
|
79
|
+
Object.keys(properties)
|
|
80
|
+
.map((key) => {
|
|
81
|
+
const type = properties[key]
|
|
82
|
+
if (!type) {
|
|
83
|
+
return undefined
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return factory.createPropertySignature({
|
|
87
|
+
name: transformers.pascalCase(key),
|
|
88
|
+
type,
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
.filter(Boolean),
|
|
92
|
+
),
|
|
93
|
+
modifiers: [factory.modifiers.export],
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
return print([namespaceNode])
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const typeGenerator = createReactGenerator<PluginTs>({
|
|
100
|
+
name: 'typescript',
|
|
101
|
+
Operation({ operation, options }) {
|
|
102
|
+
const { mapper, enumType, optionalType } = options
|
|
103
|
+
|
|
104
|
+
const { plugin, pluginManager, mode } = useApp<PluginTs>()
|
|
105
|
+
const oas = useOas()
|
|
106
|
+
const { getSchemas, getFile, getName } = useOperationManager()
|
|
107
|
+
const schemaManager = useSchemaManager()
|
|
108
|
+
|
|
109
|
+
const file = getFile(operation)
|
|
110
|
+
const schemas = getSchemas(operation)
|
|
111
|
+
const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })
|
|
112
|
+
const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`
|
|
113
|
+
const schemaGenerator = new SchemaGenerator(options, {
|
|
114
|
+
oas,
|
|
115
|
+
plugin,
|
|
116
|
+
pluginManager,
|
|
117
|
+
mode,
|
|
118
|
+
override: options.override,
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]
|
|
122
|
+
.flat()
|
|
123
|
+
.filter(Boolean)
|
|
124
|
+
|
|
125
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {
|
|
126
|
+
// hack so Params can be optional when needed
|
|
127
|
+
const tree = schemaGenerator.parse({ schema, name })
|
|
128
|
+
const imports = schemaManager.getImports(tree)
|
|
129
|
+
|
|
130
|
+
const type = {
|
|
131
|
+
name: schemaManager.getName(name, { type: 'type' }),
|
|
132
|
+
typedName: schemaManager.getName(name, { type: 'type' }),
|
|
133
|
+
file: schemaManager.getFile(options.operationName || name, { tag: options.operation?.getTags()[0]?.name }),
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Oas.Schema key={i} name={name} value={schema} tree={tree}>
|
|
138
|
+
{mode === 'split' && imports.map((imp, index) => <File.Import key={index} root={file.path} path={imp.path} name={imp.name} isTypeOnly />)}
|
|
139
|
+
<Type
|
|
140
|
+
name={type.name}
|
|
141
|
+
typedName={type.typedName}
|
|
142
|
+
description={description}
|
|
143
|
+
tree={tree}
|
|
144
|
+
mapper={mapper}
|
|
145
|
+
enumType={enumType}
|
|
146
|
+
optionalType={optionalType}
|
|
147
|
+
keysToOmit={keysToOmit}
|
|
148
|
+
/>
|
|
149
|
+
</Oas.Schema>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
|
|
155
|
+
{operationSchemas.map(mapOperationSchema)}
|
|
156
|
+
|
|
157
|
+
<File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>
|
|
158
|
+
{printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}
|
|
159
|
+
</File.Source>
|
|
160
|
+
</File>
|
|
161
|
+
)
|
|
162
|
+
},
|
|
163
|
+
Schema({ schema, options }) {
|
|
164
|
+
const { mapper, enumType, optionalType } = options
|
|
165
|
+
const {
|
|
166
|
+
mode,
|
|
167
|
+
plugin: {
|
|
168
|
+
options: { output },
|
|
169
|
+
},
|
|
170
|
+
} = useApp<PluginTs>()
|
|
171
|
+
|
|
172
|
+
const { getName, getImports, getFile } = useSchemaManager()
|
|
173
|
+
const imports = getImports(schema.tree)
|
|
174
|
+
|
|
175
|
+
if (enumType === 'asPascalConst') {
|
|
176
|
+
console.warn(`enumType '${enumType}' is deprecated`)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const type = {
|
|
180
|
+
name: getName(schema.name, { type: 'function' }),
|
|
181
|
+
typedName: getName(schema.name, { type: 'type' }),
|
|
182
|
+
file: getFile(schema.name),
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<File baseName={type.file.baseName} path={type.file.path} meta={type.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
187
|
+
{mode === 'split' && imports.map((imp, index) => <File.Import key={index} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />)}
|
|
188
|
+
<Type
|
|
189
|
+
name={type.name}
|
|
190
|
+
typedName={type.typedName}
|
|
191
|
+
description={schema.value.description}
|
|
192
|
+
tree={schema.tree}
|
|
193
|
+
mapper={mapper}
|
|
194
|
+
enumType={enumType}
|
|
195
|
+
optionalType={optionalType}
|
|
196
|
+
/>
|
|
197
|
+
</File>
|
|
198
|
+
)
|
|
199
|
+
},
|
|
200
|
+
})
|
package/src/parser/index.ts
CHANGED
|
@@ -2,8 +2,8 @@ import transformers from '@kubb/core/transformers'
|
|
|
2
2
|
import * as factory from '@kubb/parser-ts/factory'
|
|
3
3
|
import { isKeyword, schemaKeywords } from '@kubb/plugin-oas'
|
|
4
4
|
|
|
5
|
-
import type { ts } from '@kubb/parser-ts'
|
|
6
5
|
import type { Schema, SchemaKeywordMapper, SchemaMapper } from '@kubb/plugin-oas'
|
|
6
|
+
import type ts from 'typescript'
|
|
7
7
|
|
|
8
8
|
export const typeKeywordMapper = {
|
|
9
9
|
any: () => factory.keywordTypeNodes.any,
|
|
@@ -54,12 +54,20 @@ export const typeKeywordMapper = {
|
|
|
54
54
|
nodes,
|
|
55
55
|
})
|
|
56
56
|
},
|
|
57
|
-
const: (name?: string | number, format?: 'string' | 'number') => {
|
|
57
|
+
const: (name?: string | number | boolean, format?: 'string' | 'number' | 'boolean') => {
|
|
58
58
|
if (!name) {
|
|
59
59
|
return undefined
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
if (format === '
|
|
62
|
+
if (format === 'boolean') {
|
|
63
|
+
if (name === true) {
|
|
64
|
+
return factory.createLiteralTypeNode(factory.createTrue())
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return factory.createLiteralTypeNode(factory.createFalse())
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (format === 'number' && typeof name === 'number') {
|
|
63
71
|
return factory.createLiteralTypeNode(factory.createNumericLiteral(name))
|
|
64
72
|
}
|
|
65
73
|
|
|
@@ -95,6 +103,7 @@ export const typeKeywordMapper = {
|
|
|
95
103
|
password: undefined,
|
|
96
104
|
phone: undefined,
|
|
97
105
|
readOnly: undefined,
|
|
106
|
+
writeOnly: undefined,
|
|
98
107
|
ref: (propertyName?: string) => {
|
|
99
108
|
if (!propertyName) {
|
|
100
109
|
return undefined
|
|
@@ -120,6 +129,7 @@ type ParserOptions = {
|
|
|
120
129
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'
|
|
121
130
|
/**
|
|
122
131
|
* @default `'asConst'`
|
|
132
|
+
* asPascalConst is deprecated
|
|
123
133
|
*/
|
|
124
134
|
enumType: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
|
|
125
135
|
keysToOmit?: string[]
|
package/src/plugin.ts
CHANGED
|
@@ -3,20 +3,18 @@ import path from 'node:path'
|
|
|
3
3
|
import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
5
|
import { renderTemplate } from '@kubb/core/utils'
|
|
6
|
-
import { pluginOasName } from '@kubb/plugin-oas'
|
|
7
|
-
|
|
8
|
-
import { OperationGenerator } from './OperationGenerator.tsx'
|
|
9
|
-
import { SchemaGenerator } from './SchemaGenerator.tsx'
|
|
6
|
+
import { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
10
7
|
|
|
11
8
|
import type { Plugin } from '@kubb/core'
|
|
12
9
|
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
10
|
+
import { oasGenerator, typeGenerator } from './generators'
|
|
13
11
|
import type { PluginTs } from './types.ts'
|
|
14
12
|
|
|
15
13
|
export const pluginTsName = 'plugin-ts' satisfies PluginTs['name']
|
|
16
14
|
|
|
17
15
|
export const pluginTs = createPlugin<PluginTs>((options) => {
|
|
18
16
|
const {
|
|
19
|
-
output = { path: 'types' },
|
|
17
|
+
output = { path: 'types', barrelType: 'named' },
|
|
20
18
|
group,
|
|
21
19
|
exclude = [],
|
|
22
20
|
include,
|
|
@@ -29,13 +27,14 @@ export const pluginTs = createPlugin<PluginTs>((options) => {
|
|
|
29
27
|
transformers = {},
|
|
30
28
|
oasType = false,
|
|
31
29
|
mapper = {},
|
|
30
|
+
generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),
|
|
32
31
|
} = options
|
|
33
32
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
|
|
34
33
|
|
|
35
34
|
return {
|
|
36
35
|
name: pluginTsName,
|
|
37
36
|
options: {
|
|
38
|
-
|
|
37
|
+
output,
|
|
39
38
|
transformers,
|
|
40
39
|
dateType,
|
|
41
40
|
optionalType,
|
|
@@ -96,7 +95,7 @@ export const pluginTs = createPlugin<PluginTs>((options) => {
|
|
|
96
95
|
output: output.path,
|
|
97
96
|
})
|
|
98
97
|
|
|
99
|
-
const schemaFiles = await schemaGenerator.build()
|
|
98
|
+
const schemaFiles = await schemaGenerator.build(...generators)
|
|
100
99
|
await this.addFile(...schemaFiles)
|
|
101
100
|
|
|
102
101
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
@@ -110,22 +109,21 @@ export const pluginTs = createPlugin<PluginTs>((options) => {
|
|
|
110
109
|
mode,
|
|
111
110
|
})
|
|
112
111
|
|
|
113
|
-
const operationFiles = await operationGenerator.build()
|
|
112
|
+
const operationFiles = await operationGenerator.build(...generators)
|
|
114
113
|
await this.addFile(...operationFiles)
|
|
115
|
-
},
|
|
116
|
-
async buildEnd() {
|
|
117
|
-
if (this.config.output.write === false) {
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
114
|
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
await this.fileManager.addIndexes({
|
|
115
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
116
|
+
type: output.barrelType ?? 'named',
|
|
124
117
|
root,
|
|
125
118
|
output,
|
|
126
|
-
|
|
119
|
+
files: this.fileManager.files,
|
|
120
|
+
meta: {
|
|
121
|
+
pluginKey: this.plugin.key,
|
|
122
|
+
},
|
|
127
123
|
logger: this.logger,
|
|
128
124
|
})
|
|
125
|
+
|
|
126
|
+
await this.addFile(...barrelFiles)
|
|
129
127
|
},
|
|
130
128
|
}
|
|
131
129
|
})
|
package/src/types.ts
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
import type { ts } from '@kubb/parser-ts'
|
|
1
|
+
import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
+
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
3
|
+
import type ts from 'typescript'
|
|
5
4
|
|
|
6
5
|
export type Options = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @default 'types'
|
|
12
|
-
*/
|
|
13
|
-
path: string
|
|
14
|
-
/**
|
|
15
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
16
|
-
*/
|
|
17
|
-
exportAs?: string
|
|
18
|
-
/**
|
|
19
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
20
|
-
*/
|
|
21
|
-
extName?: KubbFile.Extname
|
|
22
|
-
/**
|
|
23
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
24
|
-
* @default `'barrel'`
|
|
25
|
-
*/
|
|
26
|
-
exportType?: 'barrel' | 'barrelNamed' | false
|
|
27
|
-
}
|
|
6
|
+
/**
|
|
7
|
+
* @default 'types'
|
|
8
|
+
*/
|
|
9
|
+
output?: Output
|
|
28
10
|
/**
|
|
29
11
|
* Group the TypeScript types based on the provided name.
|
|
30
12
|
*/
|
|
@@ -57,6 +39,7 @@ export type Options = {
|
|
|
57
39
|
/**
|
|
58
40
|
* Choose to use `enum` or `as const` for enums
|
|
59
41
|
* @default 'asConst'
|
|
42
|
+
* asPascalConst is deprecated
|
|
60
43
|
*/
|
|
61
44
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
|
|
62
45
|
/**
|
|
@@ -105,29 +88,24 @@ export type Options = {
|
|
|
105
88
|
* )
|
|
106
89
|
*/
|
|
107
90
|
mapper?: Record<string, ts.PropertySignature>
|
|
91
|
+
/**
|
|
92
|
+
* Define some generators next to the ts generators
|
|
93
|
+
*/
|
|
94
|
+
generators?: Array<Generator<PluginTs>>
|
|
108
95
|
}
|
|
109
96
|
|
|
110
97
|
type ResolvedOptions = {
|
|
111
|
-
|
|
98
|
+
output: Output
|
|
99
|
+
override: NonNullable<Options['override']>
|
|
112
100
|
enumType: NonNullable<Options['enumType']>
|
|
113
101
|
enumSuffix: NonNullable<Options['enumSuffix']>
|
|
114
102
|
dateType: NonNullable<Options['dateType']>
|
|
115
103
|
unknownType: NonNullable<Options['unknownType']>
|
|
116
104
|
optionalType: NonNullable<Options['optionalType']>
|
|
117
|
-
override: NonNullable<Options['override']>
|
|
118
105
|
transformers: NonNullable<Options['transformers']>
|
|
119
106
|
oasType: NonNullable<Options['oasType']>
|
|
120
107
|
usedEnumNames: Record<string, number>
|
|
121
108
|
mapper: Record<string, any>
|
|
122
109
|
}
|
|
123
110
|
|
|
124
|
-
export type FileMeta = {
|
|
125
|
-
pluginKey?: Plugin['key']
|
|
126
|
-
name?: string
|
|
127
|
-
tag?: string
|
|
128
|
-
}
|
|
129
|
-
|
|
130
111
|
export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>
|
|
131
|
-
|
|
132
|
-
// external packages
|
|
133
|
-
export * as Oas from './oas/index.ts'
|