@kubb/swagger-ts 2.0.0-beta.6 → 2.0.0-beta.8
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 -43
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +66 -17
- package/dist/components.d.ts +66 -17
- package/dist/components.js +85 -46
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +82 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +414 -12
- package/dist/index.d.ts +414 -12
- package/dist/index.js +83 -40
- 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/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 -25
- package/src/types.ts +26 -11
package/dist/index.cjs
CHANGED
@@ -3165,11 +3165,11 @@ var require_react_jsx_runtime_development = __commonJS({
|
|
3165
3165
|
return jsxWithValidation(type, props, key, false);
|
3166
3166
|
}
|
3167
3167
|
}
|
3168
|
-
var
|
3169
|
-
var
|
3168
|
+
var jsx5 = jsxWithValidationDynamic;
|
3169
|
+
var jsxs4 = jsxWithValidationStatic;
|
3170
3170
|
exports.Fragment = REACT_FRAGMENT_TYPE;
|
3171
|
-
exports.jsx =
|
3172
|
-
exports.jsxs =
|
3171
|
+
exports.jsx = jsx5;
|
3172
|
+
exports.jsxs = jsxs4;
|
3173
3173
|
})();
|
3174
3174
|
}
|
3175
3175
|
}
|
@@ -3622,9 +3622,51 @@ Mutation.File = function({ mode }) {
|
|
3622
3622
|
) });
|
3623
3623
|
};
|
3624
3624
|
|
3625
|
-
// src/components/
|
3625
|
+
// src/components/Oas.tsx
|
3626
3626
|
init_cjs_shims();
|
3627
3627
|
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
3628
|
+
function Template({
|
3629
|
+
name,
|
3630
|
+
typeName,
|
3631
|
+
api
|
3632
|
+
}) {
|
3633
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
3634
|
+
`export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
|
3635
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("br", {}),
|
3636
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(react.Type, { name: typeName, export: true, children: `Parse<typeof ${name}>` })
|
3637
|
+
] });
|
3638
|
+
}
|
3639
|
+
var defaultTemplates = { default: Template };
|
3640
|
+
function Oas({
|
3641
|
+
name,
|
3642
|
+
typeName,
|
3643
|
+
Template: Template2 = defaultTemplates.default
|
3644
|
+
}) {
|
3645
|
+
const oas = hooks.useOas();
|
3646
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Template2, { name, typeName, api: oas.api });
|
3647
|
+
}
|
3648
|
+
Oas.File = function({ name, typeName, templates = defaultTemplates }) {
|
3649
|
+
const { key: pluginKey2 } = react.usePlugin();
|
3650
|
+
const file = react.useFile({ name, pluginKey: pluginKey2 });
|
3651
|
+
const Template2 = templates.default;
|
3652
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
3653
|
+
react.File,
|
3654
|
+
{
|
3655
|
+
baseName: file.baseName,
|
3656
|
+
path: file.path,
|
3657
|
+
meta: file.meta,
|
3658
|
+
children: [
|
3659
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(react.File.Import, { name: ["Parse"], path: "@kubb/swagger-ts/infer", isTypeOnly: true }),
|
3660
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(react.File.Source, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Oas, { Template: Template2, name, typeName }) })
|
3661
|
+
]
|
3662
|
+
}
|
3663
|
+
);
|
3664
|
+
};
|
3665
|
+
Oas.templates = defaultTemplates;
|
3666
|
+
|
3667
|
+
// src/components/Query.tsx
|
3668
|
+
init_cjs_shims();
|
3669
|
+
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
|
3628
3670
|
function printCombinedSchema2(name, operation, schemas) {
|
3629
3671
|
const properties = {
|
3630
3672
|
"response": factory__namespace.createTypeReferenceNode(
|
@@ -3686,7 +3728,7 @@ function Query({
|
|
3686
3728
|
builder
|
3687
3729
|
}) {
|
3688
3730
|
const { source } = builder.build();
|
3689
|
-
return /* @__PURE__ */ (0,
|
3731
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: source });
|
3690
3732
|
}
|
3691
3733
|
Query.File = function({ mode }) {
|
3692
3734
|
const { options } = react.usePlugin();
|
@@ -3698,7 +3740,7 @@ Query.File = function({ mode }) {
|
|
3698
3740
|
const operation = hooks.useOperation();
|
3699
3741
|
const builder = new TypeBuilder(options, { oas, pluginManager }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors);
|
3700
3742
|
const { source, imports } = builder.build();
|
3701
|
-
return /* @__PURE__ */ (0,
|
3743
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
3702
3744
|
react.File,
|
3703
3745
|
{
|
3704
3746
|
baseName: file.baseName,
|
@@ -3706,9 +3748,9 @@ Query.File = function({ mode }) {
|
|
3706
3748
|
meta: file.meta,
|
3707
3749
|
children: [
|
3708
3750
|
mode === "directory" && imports.map((item, index) => {
|
3709
|
-
return /* @__PURE__ */ (0,
|
3751
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(react.File.Import, { root: file.path, ...item }, index);
|
3710
3752
|
}),
|
3711
|
-
/* @__PURE__ */ (0,
|
3753
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(react.File.Source, { children: [
|
3712
3754
|
source,
|
3713
3755
|
printCombinedSchema2(factoryName, operation, schemas)
|
3714
3756
|
] })
|
@@ -3718,16 +3760,25 @@ Query.File = function({ mode }) {
|
|
3718
3760
|
};
|
3719
3761
|
|
3720
3762
|
// src/OperationGenerator.tsx
|
3721
|
-
var
|
3763
|
+
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
3722
3764
|
var OperationGenerator = class extends swagger.OperationGenerator {
|
3723
3765
|
async all() {
|
3724
|
-
|
3766
|
+
const { oas, pluginManager, plugin } = this.context;
|
3767
|
+
if (!plugin.options.oasType) {
|
3768
|
+
return null;
|
3769
|
+
}
|
3770
|
+
const root = react.createRoot({ logger: pluginManager.logger });
|
3771
|
+
root.render(
|
3772
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Oas.File, { name: "oas", typeName: "Oas" }),
|
3773
|
+
{ meta: { oas, pluginManager, plugin } }
|
3774
|
+
);
|
3775
|
+
return root.files;
|
3725
3776
|
}
|
3726
3777
|
async get(operation, schemas, options) {
|
3727
3778
|
const { oas, pluginManager, plugin, mode = "directory" } = this.context;
|
3728
3779
|
const root = react.createRoot({ logger: pluginManager.logger });
|
3729
3780
|
root.render(
|
3730
|
-
/* @__PURE__ */ (0,
|
3781
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Query.File, { mode }),
|
3731
3782
|
{ meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } }
|
3732
3783
|
);
|
3733
3784
|
return root.files;
|
@@ -3736,7 +3787,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
3736
3787
|
const { oas, pluginManager, plugin, mode = "directory" } = this.context;
|
3737
3788
|
const root = react.createRoot({ logger: pluginManager.logger });
|
3738
3789
|
root.render(
|
3739
|
-
/* @__PURE__ */ (0,
|
3790
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Mutation.File, { mode }),
|
3740
3791
|
{ meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } }
|
3741
3792
|
);
|
3742
3793
|
return root.files;
|
@@ -3757,7 +3808,7 @@ var pluginName = "swagger-ts";
|
|
3757
3808
|
var pluginKey = [pluginName];
|
3758
3809
|
var definePlugin = core.createPlugin((options) => {
|
3759
3810
|
const {
|
3760
|
-
output = "types",
|
3811
|
+
output = { path: "types" },
|
3761
3812
|
group,
|
3762
3813
|
exclude = [],
|
3763
3814
|
include,
|
@@ -3766,9 +3817,9 @@ var definePlugin = core.createPlugin((options) => {
|
|
3766
3817
|
dateType = "string",
|
3767
3818
|
optionalType = "questionToken",
|
3768
3819
|
transformers: transformers5 = {},
|
3769
|
-
|
3820
|
+
oasType = false
|
3770
3821
|
} = options;
|
3771
|
-
const template = group?.output ? group.output : `${output}/{{tag}}Controller`;
|
3822
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
3772
3823
|
return {
|
3773
3824
|
name: pluginName,
|
3774
3825
|
options: {
|
@@ -3776,21 +3827,22 @@ var definePlugin = core.createPlugin((options) => {
|
|
3776
3827
|
dateType,
|
3777
3828
|
enumType,
|
3778
3829
|
optionalType,
|
3830
|
+
oasType,
|
3779
3831
|
// keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)
|
3780
3832
|
usedEnumNames: {}
|
3781
3833
|
},
|
3782
3834
|
pre: [swagger.pluginName],
|
3783
3835
|
resolvePath(baseName, directory, options2) {
|
3784
3836
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
3785
|
-
const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
|
3837
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
3786
3838
|
if (mode === "file") {
|
3787
|
-
return path__default.default.resolve(root, output);
|
3839
|
+
return path__default.default.resolve(root, output.path);
|
3788
3840
|
}
|
3789
3841
|
if (options2?.tag && group?.type === "tag") {
|
3790
3842
|
const tag = transformers.camelCase(options2.tag);
|
3791
3843
|
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
3792
3844
|
}
|
3793
|
-
return path__default.default.resolve(root, output, baseName);
|
3845
|
+
return path__default.default.resolve(root, output.path, baseName);
|
3794
3846
|
},
|
3795
3847
|
resolveName(name, type) {
|
3796
3848
|
const resolvedName = transformers.pascalCase(name);
|
@@ -3810,7 +3862,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
3810
3862
|
const oas = await swaggerPlugin.api.getOas();
|
3811
3863
|
const schemas = await swaggerPlugin.api.getSchemas();
|
3812
3864
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
3813
|
-
const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
|
3865
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
3814
3866
|
const builder = new TypeBuilder(this.plugin.options, { oas, pluginManager: this.pluginManager });
|
3815
3867
|
builder.add(
|
3816
3868
|
Object.entries(schemas).map(([name, schema]) => ({ name, schema }))
|
@@ -3844,7 +3896,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
3844
3896
|
}
|
3845
3897
|
await this.addFile({
|
3846
3898
|
path: resolvedPath,
|
3847
|
-
baseName: output,
|
3899
|
+
baseName: output.path,
|
3848
3900
|
source,
|
3849
3901
|
imports: [],
|
3850
3902
|
meta: {
|
@@ -3875,25 +3927,9 @@ var definePlugin = core.createPlugin((options) => {
|
|
3875
3927
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
3876
3928
|
await this.fileManager.addIndexes({
|
3877
3929
|
root,
|
3878
|
-
|
3930
|
+
output,
|
3879
3931
|
meta: { pluginKey: this.plugin.key },
|
3880
3932
|
options: {
|
3881
|
-
map: (file) => {
|
3882
|
-
return {
|
3883
|
-
...file,
|
3884
|
-
exports: file.exports?.map((item) => {
|
3885
|
-
if (exportAs) {
|
3886
|
-
return {
|
3887
|
-
...item,
|
3888
|
-
name: exportAs,
|
3889
|
-
asAlias: !!exportAs
|
3890
|
-
};
|
3891
|
-
}
|
3892
|
-
return item;
|
3893
|
-
})
|
3894
|
-
};
|
3895
|
-
},
|
3896
|
-
output,
|
3897
3933
|
isTypeOnly: true
|
3898
3934
|
}
|
3899
3935
|
});
|
@@ -3901,6 +3937,13 @@ var definePlugin = core.createPlugin((options) => {
|
|
3901
3937
|
};
|
3902
3938
|
});
|
3903
3939
|
|
3940
|
+
// src/types.ts
|
3941
|
+
init_cjs_shims();
|
3942
|
+
|
3943
|
+
// src/infer/index.ts
|
3944
|
+
var infer_exports = {};
|
3945
|
+
init_cjs_shims();
|
3946
|
+
|
3904
3947
|
// src/index.ts
|
3905
3948
|
var src_default = definePlugin;
|
3906
3949
|
/*! Bundled license information:
|
@@ -3950,6 +3993,7 @@ react/cjs/react-jsx-runtime.development.js:
|
|
3950
3993
|
*)
|
3951
3994
|
*/
|
3952
3995
|
|
3996
|
+
exports.Infer = infer_exports;
|
3953
3997
|
exports.default = src_default;
|
3954
3998
|
exports.definePlugin = definePlugin;
|
3955
3999
|
exports.pluginKey = pluginKey;
|