@kubb/swagger-ts 2.0.0-beta.5 → 2.0.0-beta.7
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/dist/components.cjs +80 -42
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +61 -16
- package/dist/components.d.ts +61 -16
- package/dist/components.js +85 -45
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +82 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +409 -11
- package/dist/index.d.ts +409 -11
- package/dist/index.js +83 -39
- package/dist/index.js.map +1 -1
- package/dist/infer.d.ts +381 -0
- package/dist/infer.js +5 -0
- package/dist/infer.js.map +1 -0
- package/package.json +14 -8
- package/src/OperationGenerator.tsx +15 -3
- package/src/TypeGenerator.ts +1 -0
- package/src/components/Oas.tsx +84 -0
- package/src/components/index.ts +1 -0
- package/src/infer/index.ts +7 -0
- package/src/infer/mappers.ts +93 -0
- package/src/infer/model.ts +38 -0
- package/src/infer/parse.ts +58 -0
- package/src/infer/requestParams.ts +170 -0
- package/src/infer/response.ts +39 -0
- package/src/infer/security.ts +158 -0
- package/src/plugin.ts +10 -24
- package/src/types.ts +21 -10
package/dist/components.cjs
CHANGED
@@ -3163,11 +3163,11 @@ var require_react_jsx_runtime_development = __commonJS({
|
|
3163
3163
|
return jsxWithValidation(type, props, key, false);
|
3164
3164
|
}
|
3165
3165
|
}
|
3166
|
-
var
|
3167
|
-
var
|
3166
|
+
var jsx5 = jsxWithValidationDynamic;
|
3167
|
+
var jsxs4 = jsxWithValidationStatic;
|
3168
3168
|
exports.Fragment = REACT_FRAGMENT_TYPE;
|
3169
|
-
exports.jsx =
|
3170
|
-
exports.jsxs =
|
3169
|
+
exports.jsx = jsx5;
|
3170
|
+
exports.jsxs = jsxs4;
|
3171
3171
|
})();
|
3172
3172
|
}
|
3173
3173
|
}
|
@@ -3203,9 +3203,51 @@ init_cjs_shims();
|
|
3203
3203
|
// src/OperationGenerator.tsx
|
3204
3204
|
init_cjs_shims();
|
3205
3205
|
|
3206
|
-
// src/components/
|
3206
|
+
// src/components/Oas.tsx
|
3207
3207
|
init_cjs_shims();
|
3208
3208
|
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
3209
|
+
function Template({
|
3210
|
+
name,
|
3211
|
+
typeName,
|
3212
|
+
api
|
3213
|
+
}) {
|
3214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
3215
|
+
`export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
|
3216
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
3217
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(react.Type, { name: typeName, export: true, children: `Parse<typeof ${name}>` })
|
3218
|
+
] });
|
3219
|
+
}
|
3220
|
+
var defaultTemplates = { default: Template };
|
3221
|
+
function Oas({
|
3222
|
+
name,
|
3223
|
+
typeName,
|
3224
|
+
Template: Template2 = defaultTemplates.default
|
3225
|
+
}) {
|
3226
|
+
const oas = hooks.useOas();
|
3227
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Template2, { name, typeName, api: oas.api });
|
3228
|
+
}
|
3229
|
+
Oas.File = function({ name, typeName, templates = defaultTemplates }) {
|
3230
|
+
const { key: pluginKey2 } = react.usePlugin();
|
3231
|
+
const file = react.useFile({ name, pluginKey: pluginKey2 });
|
3232
|
+
const Template2 = templates.default;
|
3233
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
3234
|
+
react.File,
|
3235
|
+
{
|
3236
|
+
baseName: file.baseName,
|
3237
|
+
path: file.path,
|
3238
|
+
meta: file.meta,
|
3239
|
+
children: [
|
3240
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(react.File.Import, { name: ["Parse"], path: "@kubb/swagger-ts/infer", isTypeOnly: true }),
|
3241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(react.File.Source, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Oas, { Template: Template2, name, typeName }) })
|
3242
|
+
]
|
3243
|
+
}
|
3244
|
+
);
|
3245
|
+
};
|
3246
|
+
Oas.templates = defaultTemplates;
|
3247
|
+
|
3248
|
+
// src/components/Query.tsx
|
3249
|
+
init_cjs_shims();
|
3250
|
+
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
3209
3251
|
function printCombinedSchema(name, operation, schemas) {
|
3210
3252
|
const properties = {
|
3211
3253
|
"response": factory2__namespace.createTypeReferenceNode(
|
@@ -3267,7 +3309,7 @@ function Query({
|
|
3267
3309
|
builder
|
3268
3310
|
}) {
|
3269
3311
|
const { source } = builder.build();
|
3270
|
-
return /* @__PURE__ */ (0,
|
3312
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: source });
|
3271
3313
|
}
|
3272
3314
|
Query.File = function({ mode }) {
|
3273
3315
|
const { options } = react.usePlugin();
|
@@ -3279,7 +3321,7 @@ Query.File = function({ mode }) {
|
|
3279
3321
|
const operation = hooks.useOperation();
|
3280
3322
|
const builder = new TypeBuilder(options, { oas, pluginManager }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors);
|
3281
3323
|
const { source, imports } = builder.build();
|
3282
|
-
return /* @__PURE__ */ (0,
|
3324
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
3283
3325
|
react.File,
|
3284
3326
|
{
|
3285
3327
|
baseName: file.baseName,
|
@@ -3287,9 +3329,9 @@ Query.File = function({ mode }) {
|
|
3287
3329
|
meta: file.meta,
|
3288
3330
|
children: [
|
3289
3331
|
mode === "directory" && imports.map((item, index) => {
|
3290
|
-
return /* @__PURE__ */ (0,
|
3332
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(react.File.Import, { root: file.path, ...item }, index);
|
3291
3333
|
}),
|
3292
|
-
/* @__PURE__ */ (0,
|
3334
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(react.File.Source, { children: [
|
3293
3335
|
source,
|
3294
3336
|
printCombinedSchema(factoryName, operation, schemas)
|
3295
3337
|
] })
|
@@ -3299,16 +3341,25 @@ Query.File = function({ mode }) {
|
|
3299
3341
|
};
|
3300
3342
|
|
3301
3343
|
// src/OperationGenerator.tsx
|
3302
|
-
var
|
3344
|
+
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
|
3303
3345
|
var OperationGenerator = class extends swagger.OperationGenerator {
|
3304
3346
|
async all() {
|
3305
|
-
|
3347
|
+
const { oas, pluginManager, plugin } = this.context;
|
3348
|
+
if (!plugin.options.oasType) {
|
3349
|
+
return null;
|
3350
|
+
}
|
3351
|
+
const root = react.createRoot({ logger: pluginManager.logger });
|
3352
|
+
root.render(
|
3353
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Oas.File, { name: "oas", typeName: "Oas" }),
|
3354
|
+
{ meta: { oas, pluginManager, plugin } }
|
3355
|
+
);
|
3356
|
+
return root.files;
|
3306
3357
|
}
|
3307
3358
|
async get(operation, schemas, options) {
|
3308
3359
|
const { oas, pluginManager, plugin, mode = "directory" } = this.context;
|
3309
3360
|
const root = react.createRoot({ logger: pluginManager.logger });
|
3310
3361
|
root.render(
|
3311
|
-
/* @__PURE__ */ (0,
|
3362
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Query.File, { mode }),
|
3312
3363
|
{ meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } }
|
3313
3364
|
);
|
3314
3365
|
return root.files;
|
@@ -3317,7 +3368,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
3317
3368
|
const { oas, pluginManager, plugin, mode = "directory" } = this.context;
|
3318
3369
|
const root = react.createRoot({ logger: pluginManager.logger });
|
3319
3370
|
root.render(
|
3320
|
-
/* @__PURE__ */ (0,
|
3371
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Mutation.File, { mode }),
|
3321
3372
|
{ meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } }
|
3322
3373
|
);
|
3323
3374
|
return root.files;
|
@@ -3338,7 +3389,7 @@ var pluginName = "swagger-ts";
|
|
3338
3389
|
var pluginKey = [pluginName];
|
3339
3390
|
core.createPlugin((options) => {
|
3340
3391
|
const {
|
3341
|
-
output = "types",
|
3392
|
+
output = { path: "types" },
|
3342
3393
|
group,
|
3343
3394
|
exclude = [],
|
3344
3395
|
include,
|
@@ -3347,9 +3398,9 @@ core.createPlugin((options) => {
|
|
3347
3398
|
dateType = "string",
|
3348
3399
|
optionalType = "questionToken",
|
3349
3400
|
transformers: transformers5 = {},
|
3350
|
-
|
3401
|
+
oasType = false
|
3351
3402
|
} = options;
|
3352
|
-
const template = group?.output ? group.output : `${output}/{{tag}}Controller`;
|
3403
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
3353
3404
|
return {
|
3354
3405
|
name: pluginName,
|
3355
3406
|
options: {
|
@@ -3357,21 +3408,22 @@ core.createPlugin((options) => {
|
|
3357
3408
|
dateType,
|
3358
3409
|
enumType,
|
3359
3410
|
optionalType,
|
3411
|
+
oasType,
|
3360
3412
|
// keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)
|
3361
3413
|
usedEnumNames: {}
|
3362
3414
|
},
|
3363
3415
|
pre: [swagger.pluginName],
|
3364
3416
|
resolvePath(baseName, directory, options2) {
|
3365
3417
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
3366
|
-
const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
|
3418
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
3367
3419
|
if (mode === "file") {
|
3368
|
-
return path__default.default.resolve(root, output);
|
3420
|
+
return path__default.default.resolve(root, output.path);
|
3369
3421
|
}
|
3370
3422
|
if (options2?.tag && group?.type === "tag") {
|
3371
3423
|
const tag = transformers2.camelCase(options2.tag);
|
3372
3424
|
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
3373
3425
|
}
|
3374
|
-
return path__default.default.resolve(root, output, baseName);
|
3426
|
+
return path__default.default.resolve(root, output.path, baseName);
|
3375
3427
|
},
|
3376
3428
|
resolveName(name, type) {
|
3377
3429
|
const resolvedName = transformers2.pascalCase(name);
|
@@ -3391,7 +3443,7 @@ core.createPlugin((options) => {
|
|
3391
3443
|
const oas = await swaggerPlugin.api.getOas();
|
3392
3444
|
const schemas = await swaggerPlugin.api.getSchemas();
|
3393
3445
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
3394
|
-
const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
|
3446
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
3395
3447
|
const builder = new TypeBuilder(this.plugin.options, { oas, pluginManager: this.pluginManager });
|
3396
3448
|
builder.add(
|
3397
3449
|
Object.entries(schemas).map(([name, schema]) => ({ name, schema }))
|
@@ -3425,7 +3477,7 @@ core.createPlugin((options) => {
|
|
3425
3477
|
}
|
3426
3478
|
await this.addFile({
|
3427
3479
|
path: resolvedPath,
|
3428
|
-
baseName: output,
|
3480
|
+
baseName: output.path,
|
3429
3481
|
source,
|
3430
3482
|
imports: [],
|
3431
3483
|
meta: {
|
@@ -3456,25 +3508,10 @@ core.createPlugin((options) => {
|
|
3456
3508
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
3457
3509
|
await this.fileManager.addIndexes({
|
3458
3510
|
root,
|
3511
|
+
output,
|
3459
3512
|
extName: ".ts",
|
3460
3513
|
meta: { pluginKey: this.plugin.key },
|
3461
3514
|
options: {
|
3462
|
-
map: (file) => {
|
3463
|
-
return {
|
3464
|
-
...file,
|
3465
|
-
exports: file.exports?.map((item) => {
|
3466
|
-
if (exportAs) {
|
3467
|
-
return {
|
3468
|
-
...item,
|
3469
|
-
name: exportAs,
|
3470
|
-
asAlias: !!exportAs
|
3471
|
-
};
|
3472
|
-
}
|
3473
|
-
return item;
|
3474
|
-
})
|
3475
|
-
};
|
3476
|
-
},
|
3477
|
-
output,
|
3478
3515
|
isTypeOnly: true
|
3479
3516
|
}
|
3480
3517
|
});
|
@@ -3808,7 +3845,7 @@ var TypeBuilder = class extends swagger.OasBuilder {
|
|
3808
3845
|
};
|
3809
3846
|
|
3810
3847
|
// src/components/Mutation.tsx
|
3811
|
-
var
|
3848
|
+
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
3812
3849
|
function printCombinedSchema2(name, operation, schemas) {
|
3813
3850
|
const properties = {
|
3814
3851
|
"response": factory2__namespace.createTypeReferenceNode(
|
@@ -3870,7 +3907,7 @@ function Mutation({
|
|
3870
3907
|
builder
|
3871
3908
|
}) {
|
3872
3909
|
const { source } = builder.build();
|
3873
|
-
return /* @__PURE__ */ (0,
|
3910
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: source });
|
3874
3911
|
}
|
3875
3912
|
Mutation.File = function({ mode }) {
|
3876
3913
|
const { options } = react.usePlugin();
|
@@ -3882,7 +3919,7 @@ Mutation.File = function({ mode }) {
|
|
3882
3919
|
const operation = hooks.useOperation();
|
3883
3920
|
const builder = new TypeBuilder(options, { oas, pluginManager }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.request).add(schemas.errors);
|
3884
3921
|
const { source, imports } = builder.build();
|
3885
|
-
return /* @__PURE__ */ (0,
|
3922
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
3886
3923
|
react.File,
|
3887
3924
|
{
|
3888
3925
|
baseName: file.baseName,
|
@@ -3890,9 +3927,9 @@ Mutation.File = function({ mode }) {
|
|
3890
3927
|
meta: file.meta,
|
3891
3928
|
children: [
|
3892
3929
|
mode === "directory" && imports.map((item, index) => {
|
3893
|
-
return /* @__PURE__ */ (0,
|
3930
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(react.File.Import, { root: file.path, ...item }, index);
|
3894
3931
|
}),
|
3895
|
-
/* @__PURE__ */ (0,
|
3932
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(react.File.Source, { children: [
|
3896
3933
|
source,
|
3897
3934
|
printCombinedSchema2(factoryName, operation, schemas)
|
3898
3935
|
] })
|
@@ -3948,6 +3985,7 @@ react/cjs/react-jsx-runtime.development.js:
|
|
3948
3985
|
*/
|
3949
3986
|
|
3950
3987
|
exports.Mutation = Mutation;
|
3988
|
+
exports.Oas = Oas;
|
3951
3989
|
exports.Query = Query;
|
3952
3990
|
//# sourceMappingURL=out.js.map
|
3953
3991
|
//# sourceMappingURL=components.cjs.map
|