@kubb/plugin-ts 0.0.0-canary-20241104172400
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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/chunk-HJ6SFXKJ.js +306 -0
- package/dist/chunk-HJ6SFXKJ.js.map +1 -0
- package/dist/chunk-HZ6BGJL7.js +2539 -0
- package/dist/chunk-HZ6BGJL7.js.map +1 -0
- package/dist/chunk-PTC7IOBI.cjs +335 -0
- package/dist/chunk-PTC7IOBI.cjs.map +1 -0
- package/dist/chunk-RORQTUX5.cjs +2566 -0
- package/dist/chunk-RORQTUX5.cjs.map +1 -0
- package/dist/components.cjs +16 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +30 -0
- package/dist/components.d.ts +30 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- 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 +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types-zQCmVvxv.d.cts +97 -0
- package/dist/types-zQCmVvxv.d.ts +97 -0
- package/package.json +97 -0
- package/src/components/OasType.tsx +29 -0
- package/src/components/Type.tsx +141 -0
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
- package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/createPet.ts +34 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +34 -0
- package/src/generators/__snapshots__/deletePet.ts +7 -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 +26 -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 +31 -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 +205 -0
- package/src/index.ts +2 -0
- package/src/parser/index.ts +279 -0
- package/src/plugin.ts +127 -0
- package/src/types.ts +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Stijn Van Hulle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
|
|
4
|
+
<h1>@kubb/plugin-ts</h1>
|
|
5
|
+
|
|
6
|
+
<p>
|
|
7
|
+
Swagger integration for TypeScript to generate all the different types based on an OpenAPI specification.
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<img src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/banner.png" alt="logo" height="auto" />
|
|
11
|
+
|
|
12
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
13
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
14
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
15
|
+
[![License][license-src]][license-href]
|
|
16
|
+
|
|
17
|
+
<h4>
|
|
18
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
19
|
+
<span> · </span>
|
|
20
|
+
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
21
|
+
<span> · </span>
|
|
22
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
23
|
+
<span> · </span>
|
|
24
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
25
|
+
</h4>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
## Supporting Kubb
|
|
29
|
+
|
|
30
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
31
|
+
|
|
32
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
36
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
37
|
+
</a>
|
|
38
|
+
</p>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
<!-- Badges -->
|
|
42
|
+
|
|
43
|
+
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-ts?flat&colorA=18181B&colorB=f58517
|
|
44
|
+
[npm-version-href]: https://npmjs.com/package/@kubb/plugin-ts
|
|
45
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-ts?flat&colorA=18181B&colorB=f58517
|
|
46
|
+
[npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-ts
|
|
47
|
+
[license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
|
|
48
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
49
|
+
[build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
|
|
50
|
+
[build-href]: https://www.npmjs.com/package/@kubb/plugin-ts
|
|
51
|
+
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-ts?style=flat&colorA=18181B&colorB=f58517
|
|
52
|
+
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-ts
|
|
53
|
+
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
54
|
+
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-ts
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { init_esm_shims, Type, OasType } from './chunk-HZ6BGJL7.js';
|
|
2
|
+
import transformers, { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
3
|
+
import { print } from '@kubb/parser-ts';
|
|
4
|
+
import * as factory from '@kubb/parser-ts/factory';
|
|
5
|
+
import { pluginOasName, SchemaGenerator, OperationGenerator, createReactGenerator } from '@kubb/plugin-oas';
|
|
6
|
+
import { Oas } from '@kubb/plugin-oas/components';
|
|
7
|
+
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
10
|
+
import { useApp, File } from '@kubb/react';
|
|
11
|
+
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
12
|
+
|
|
13
|
+
// src/generators/index.ts
|
|
14
|
+
init_esm_shims();
|
|
15
|
+
|
|
16
|
+
// src/generators/typeGenerator.tsx
|
|
17
|
+
init_esm_shims();
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
init_esm_shims();
|
|
21
|
+
|
|
22
|
+
// src/plugin.ts
|
|
23
|
+
init_esm_shims();
|
|
24
|
+
var pluginTsName = "plugin-ts";
|
|
25
|
+
var pluginTs = createPlugin((options) => {
|
|
26
|
+
const {
|
|
27
|
+
output = { path: "types", barrelType: "named" },
|
|
28
|
+
group,
|
|
29
|
+
exclude = [],
|
|
30
|
+
include,
|
|
31
|
+
override = [],
|
|
32
|
+
enumType = "asConst",
|
|
33
|
+
enumSuffix = "enum",
|
|
34
|
+
dateType = "string",
|
|
35
|
+
unknownType = "any",
|
|
36
|
+
optionalType = "questionToken",
|
|
37
|
+
transformers: transformers2 = {},
|
|
38
|
+
oasType = false,
|
|
39
|
+
mapper = {},
|
|
40
|
+
generators = [typeGenerator, oasType === "infer" ? oasGenerator : void 0].filter(Boolean)
|
|
41
|
+
} = options;
|
|
42
|
+
return {
|
|
43
|
+
name: pluginTsName,
|
|
44
|
+
options: {
|
|
45
|
+
output,
|
|
46
|
+
transformers: transformers2,
|
|
47
|
+
dateType,
|
|
48
|
+
optionalType,
|
|
49
|
+
oasType,
|
|
50
|
+
enumType,
|
|
51
|
+
enumSuffix,
|
|
52
|
+
// keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
|
|
53
|
+
usedEnumNames: {},
|
|
54
|
+
unknownType,
|
|
55
|
+
override,
|
|
56
|
+
mapper
|
|
57
|
+
},
|
|
58
|
+
pre: [pluginOasName],
|
|
59
|
+
resolvePath(baseName, pathMode, options2) {
|
|
60
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
61
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
62
|
+
if (options2?.tag && group?.type === "tag") {
|
|
63
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
64
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
65
|
+
}
|
|
66
|
+
if (mode === "single") {
|
|
67
|
+
return path.resolve(root, output.path);
|
|
68
|
+
}
|
|
69
|
+
return path.resolve(root, output.path, baseName);
|
|
70
|
+
},
|
|
71
|
+
resolveName(name, type) {
|
|
72
|
+
const resolvedName = pascalCase(name, { isFile: type === "file" });
|
|
73
|
+
if (type) {
|
|
74
|
+
return transformers2?.name?.(resolvedName, type) || resolvedName;
|
|
75
|
+
}
|
|
76
|
+
return resolvedName;
|
|
77
|
+
},
|
|
78
|
+
async buildStart() {
|
|
79
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
80
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
81
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
82
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
83
|
+
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
84
|
+
oas,
|
|
85
|
+
pluginManager: this.pluginManager,
|
|
86
|
+
plugin: this.plugin,
|
|
87
|
+
contentType: swaggerPlugin.context.contentType,
|
|
88
|
+
include: void 0,
|
|
89
|
+
override,
|
|
90
|
+
mode,
|
|
91
|
+
output: output.path
|
|
92
|
+
});
|
|
93
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
94
|
+
await this.addFile(...schemaFiles);
|
|
95
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
96
|
+
oas,
|
|
97
|
+
pluginManager: this.pluginManager,
|
|
98
|
+
plugin: this.plugin,
|
|
99
|
+
contentType: swaggerPlugin.context.contentType,
|
|
100
|
+
exclude,
|
|
101
|
+
include,
|
|
102
|
+
override,
|
|
103
|
+
mode
|
|
104
|
+
});
|
|
105
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
106
|
+
await this.addFile(...operationFiles);
|
|
107
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
108
|
+
type: output.barrelType ?? "named",
|
|
109
|
+
root,
|
|
110
|
+
output,
|
|
111
|
+
files: this.fileManager.files,
|
|
112
|
+
meta: {
|
|
113
|
+
pluginKey: this.plugin.key
|
|
114
|
+
},
|
|
115
|
+
logger: this.logger
|
|
116
|
+
});
|
|
117
|
+
await this.addFile(...barrelFiles);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
122
|
+
const properties = {};
|
|
123
|
+
if (schemas.response) {
|
|
124
|
+
properties["response"] = factory.createUnionDeclaration({
|
|
125
|
+
nodes: schemas.responses.map((res) => {
|
|
126
|
+
const identifier = pluginManager.resolveName({
|
|
127
|
+
name: res.name,
|
|
128
|
+
pluginKey: [pluginTsName],
|
|
129
|
+
type: "function"
|
|
130
|
+
});
|
|
131
|
+
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (schemas.request) {
|
|
136
|
+
const identifier = pluginManager.resolveName({
|
|
137
|
+
name: schemas.request.name,
|
|
138
|
+
pluginKey: [pluginTsName],
|
|
139
|
+
type: "function"
|
|
140
|
+
});
|
|
141
|
+
properties["request"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
142
|
+
}
|
|
143
|
+
if (schemas.pathParams) {
|
|
144
|
+
const identifier = pluginManager.resolveName({
|
|
145
|
+
name: schemas.pathParams.name,
|
|
146
|
+
pluginKey: [pluginTsName],
|
|
147
|
+
type: "function"
|
|
148
|
+
});
|
|
149
|
+
properties["pathParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
150
|
+
}
|
|
151
|
+
if (schemas.queryParams) {
|
|
152
|
+
const identifier = pluginManager.resolveName({
|
|
153
|
+
name: schemas.queryParams.name,
|
|
154
|
+
pluginKey: [pluginTsName],
|
|
155
|
+
type: "function"
|
|
156
|
+
});
|
|
157
|
+
properties["queryParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
158
|
+
}
|
|
159
|
+
if (schemas.headerParams) {
|
|
160
|
+
const identifier = pluginManager.resolveName({
|
|
161
|
+
name: schemas.headerParams.name,
|
|
162
|
+
pluginKey: [pluginTsName],
|
|
163
|
+
type: "function"
|
|
164
|
+
});
|
|
165
|
+
properties["headerParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
166
|
+
}
|
|
167
|
+
if (schemas.errors) {
|
|
168
|
+
properties["errors"] = factory.createUnionDeclaration({
|
|
169
|
+
nodes: schemas.errors.map((error) => {
|
|
170
|
+
const identifier = pluginManager.resolveName({
|
|
171
|
+
name: error.name,
|
|
172
|
+
pluginKey: [pluginTsName],
|
|
173
|
+
type: "function"
|
|
174
|
+
});
|
|
175
|
+
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
176
|
+
})
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const namespaceNode = factory.createTypeAliasDeclaration({
|
|
180
|
+
name,
|
|
181
|
+
type: factory.createTypeLiteralNode(
|
|
182
|
+
Object.keys(properties).map((key) => {
|
|
183
|
+
const type = properties[key];
|
|
184
|
+
if (!type) {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
return factory.createPropertySignature({
|
|
188
|
+
name: transformers.pascalCase(key),
|
|
189
|
+
type
|
|
190
|
+
});
|
|
191
|
+
}).filter(Boolean)
|
|
192
|
+
),
|
|
193
|
+
modifiers: [factory.modifiers.export]
|
|
194
|
+
});
|
|
195
|
+
return print([namespaceNode]);
|
|
196
|
+
}
|
|
197
|
+
var typeGenerator = createReactGenerator({
|
|
198
|
+
name: "typescript",
|
|
199
|
+
Operation({ operation, options }) {
|
|
200
|
+
const { mapper, enumType, optionalType } = options;
|
|
201
|
+
const { plugin, pluginManager, mode } = useApp();
|
|
202
|
+
const oas = useOas();
|
|
203
|
+
const { getSchemas, getFile, getName } = useOperationManager();
|
|
204
|
+
const schemaManager = useSchemaManager();
|
|
205
|
+
const file = getFile(operation);
|
|
206
|
+
const schemas = getSchemas(operation);
|
|
207
|
+
const type = getName(operation, { type: "function", pluginKey: [pluginTsName] });
|
|
208
|
+
const combinedSchemaName = operation.method === "get" ? `${type}Query` : `${type}Mutation`;
|
|
209
|
+
const schemaGenerator = new SchemaGenerator(options, {
|
|
210
|
+
oas,
|
|
211
|
+
plugin,
|
|
212
|
+
pluginManager,
|
|
213
|
+
mode,
|
|
214
|
+
override: options.override
|
|
215
|
+
});
|
|
216
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
217
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
|
|
218
|
+
const tree = schemaGenerator.parse({ schema, name });
|
|
219
|
+
const imports = schemaManager.getImports(tree);
|
|
220
|
+
const type2 = {
|
|
221
|
+
name: schemaManager.getName(name, { type: "type" }),
|
|
222
|
+
typedName: schemaManager.getName(name, { type: "type" }),
|
|
223
|
+
file: schemaManager.getFile(options2.operationName || name, { tag: options2.operation?.getTags()[0]?.name })
|
|
224
|
+
};
|
|
225
|
+
return /* @__PURE__ */ jsxs(Oas.Schema, { name, value: schema, tree, children: [
|
|
226
|
+
mode === "split" && imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: file.path, path: imp.path, name: imp.name, isTypeOnly: true }, index)),
|
|
227
|
+
/* @__PURE__ */ jsx(
|
|
228
|
+
Type,
|
|
229
|
+
{
|
|
230
|
+
name: type2.name,
|
|
231
|
+
typedName: type2.typedName,
|
|
232
|
+
description,
|
|
233
|
+
tree,
|
|
234
|
+
mapper,
|
|
235
|
+
enumType,
|
|
236
|
+
optionalType,
|
|
237
|
+
keysToOmit
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
] }, i);
|
|
241
|
+
};
|
|
242
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
243
|
+
operationSchemas.map(mapOperationSchema),
|
|
244
|
+
/* @__PURE__ */ jsx(File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager }) })
|
|
245
|
+
] });
|
|
246
|
+
},
|
|
247
|
+
Schema({ schema, options }) {
|
|
248
|
+
const { mapper, enumType, optionalType } = options;
|
|
249
|
+
const {
|
|
250
|
+
mode,
|
|
251
|
+
plugin: {
|
|
252
|
+
options: { output }
|
|
253
|
+
}
|
|
254
|
+
} = useApp();
|
|
255
|
+
const { getName, getImports, getFile } = useSchemaManager();
|
|
256
|
+
const imports = getImports(schema.tree);
|
|
257
|
+
if (enumType === "asPascalConst") {
|
|
258
|
+
console.warn(`enumType '${enumType}' is deprecated`);
|
|
259
|
+
}
|
|
260
|
+
const type = {
|
|
261
|
+
name: getName(schema.name, { type: "function" }),
|
|
262
|
+
typedName: getName(schema.name, { type: "type" }),
|
|
263
|
+
file: getFile(schema.name)
|
|
264
|
+
};
|
|
265
|
+
return /* @__PURE__ */ jsxs(File, { baseName: type.file.baseName, path: type.file.path, meta: type.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
266
|
+
mode === "split" && imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: type.file.path, path: imp.path, name: imp.name, isTypeOnly: true }, index)),
|
|
267
|
+
/* @__PURE__ */ jsx(
|
|
268
|
+
Type,
|
|
269
|
+
{
|
|
270
|
+
name: type.name,
|
|
271
|
+
typedName: type.typedName,
|
|
272
|
+
description: schema.value.description,
|
|
273
|
+
tree: schema.tree,
|
|
274
|
+
mapper,
|
|
275
|
+
enumType,
|
|
276
|
+
optionalType
|
|
277
|
+
}
|
|
278
|
+
)
|
|
279
|
+
] });
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// src/generators/oasGenerator.tsx
|
|
284
|
+
init_esm_shims();
|
|
285
|
+
var oasGenerator = createReactGenerator({
|
|
286
|
+
name: "oas",
|
|
287
|
+
Operations() {
|
|
288
|
+
const {
|
|
289
|
+
pluginManager,
|
|
290
|
+
plugin: {
|
|
291
|
+
options: { output },
|
|
292
|
+
key: pluginKey
|
|
293
|
+
}
|
|
294
|
+
} = useApp();
|
|
295
|
+
const oas = useOas();
|
|
296
|
+
const file = pluginManager.getFile({ name: "oas", extname: ".ts", pluginKey });
|
|
297
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
298
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
299
|
+
/* @__PURE__ */ jsx(OasType, { name: "oas", typeName: "Oas", api: oas.api })
|
|
300
|
+
] });
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
export { oasGenerator, pluginTs, pluginTsName, typeGenerator };
|
|
305
|
+
//# sourceMappingURL=chunk-HJ6SFXKJ.js.map
|
|
306
|
+
//# sourceMappingURL=chunk-HJ6SFXKJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/index.ts","../src/generators/typeGenerator.tsx","../src/index.ts","../src/plugin.ts","../src/generators/oasGenerator.tsx"],"names":["transformers","options","SchemaGenerator","type","createReactGenerator","useApp","useOas","jsxs","File","jsx"],"mappings":";;;;;;;;;;;;;AAAA,cAAA,EAAA;;;ACAA,cAAA,EAAA;;;ACAA,cAAA,EAAA;;;ACAA,cAAA,EAAA;AAWO,IAAM,YAAe,GAAA;AAEf,IAAA,QAAA,GAAW,YAAuB,CAAA,CAAC,OAAY,KAAA;AAC1D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,O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AA,UAAA,EAAU,IAAC,EAAA,CAAA;AAAA,sBAE1DC,IAAC,OAAQ,EAAA,EAAA,IAAA,EAAM,OAAO,QAAU,EAAA,KAAA,EAAO,GAAK,EAAA,GAAA,CAAI,GAAK,EAAA;AAAA,KACvD,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-HJ6SFXKJ.js","sourcesContent":["export { typeGenerator } from './typeGenerator.tsx'\nexport { oasGenerator } from './oasGenerator.tsx'\n","import type { PluginManager } from '@kubb/core'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/parser-ts'\nimport * as factory from '@kubb/parser-ts/factory'\nimport { createPropertySignature, modifiers } from '@kubb/parser-ts/factory'\nimport { type OperationSchema as OperationSchemaType, type OperationSchemas, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return print([namespaceNode])\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, options }) {\n const { mapper, enumType, optionalType } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginTs>()\n const oas = useOas()\n const { getSchemas, getFile, getName } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n const tree = schemaGenerator.parse({ schema, name })\n const imports = schemaManager.getImports(tree)\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { tag: options.operation?.getTags()[0]?.name }),\n }\n\n return (\n <Oas.Schema key={i} name={name} value={schema} tree={tree}>\n {mode === 'split' && imports.map((imp, index) => <File.Import key={index} root={file.path} path={imp.path} name={imp.name} isTypeOnly />)}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, options }) {\n const { mapper, enumType, optionalType } = options\n const {\n mode,\n plugin: {\n options: { output },\n },\n } = useApp<PluginTs>()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n\n if (enumType === 'asPascalConst') {\n console.warn(`enumType '${enumType}' is deprecated`)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n return (\n <File baseName={type.file.baseName} path={type.file.path} meta={type.file.meta} banner={output?.banner} footer={output?.footer}>\n {mode === 'split' && imports.map((imp, index) => <File.Import key={index} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />)}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n />\n </File>\n )\n },\n})\n","export { pluginTs, pluginTsName } from './plugin.ts'\nexport type { PluginTs } from './types.ts'\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = createPlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n transformers = {},\n oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n // keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)\n usedEnumNames: {},\n unknownType,\n override,\n mapper,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations() {\n const {\n pluginManager,\n plugin: {\n options: { output },\n key: pluginKey,\n },\n } = useApp<PluginTs>()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n"]}
|