@povio/openapi-codegen-cli 2.0.8-rc.10 → 2.0.8-rc.11
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/{generate.runner-CHLAT44S.mjs → generate.runner-DpXZK8Yc.mjs} +35 -3
- package/dist/{generateCodeFromOpenAPIDoc-CQZ2OLwB.mjs → generateCodeFromOpenAPIDoc-CfeJeQ0w.mjs} +107 -104
- package/dist/generator.mjs +1 -1
- package/dist/sh.mjs +3 -3
- package/dist/vite.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-CfeJeQ0w.mjs";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
@@ -30,18 +30,24 @@ async function runGenerate({ fileConfig, params, profiler = new Profiler(process
|
|
|
30
30
|
const cached = readCache(cacheFilePath);
|
|
31
31
|
if (cached && cached.openApiHash === openApiHash && cached.optionsHash === optionsHash) return {
|
|
32
32
|
skipped: true,
|
|
33
|
-
config
|
|
33
|
+
config,
|
|
34
|
+
stats: {
|
|
35
|
+
generatedFilesCount: 0,
|
|
36
|
+
generatedModulesCount: 0
|
|
37
|
+
}
|
|
34
38
|
};
|
|
35
39
|
}
|
|
36
40
|
const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
|
|
37
41
|
profiler.runSync("files.write", () => writeGenerateFileData(filesData));
|
|
42
|
+
const stats = getGenerateStats(filesData, config);
|
|
38
43
|
if (config.incremental) writeCache(cacheFilePath, {
|
|
39
44
|
openApiHash,
|
|
40
45
|
optionsHash
|
|
41
46
|
});
|
|
42
47
|
return {
|
|
43
48
|
skipped: false,
|
|
44
|
-
config
|
|
49
|
+
config,
|
|
50
|
+
stats
|
|
45
51
|
};
|
|
46
52
|
}
|
|
47
53
|
async function getOpenApiDoc(input, profiler) {
|
|
@@ -93,6 +99,32 @@ function stableStringify(input) {
|
|
|
93
99
|
const obj = input;
|
|
94
100
|
return `{${Object.keys(obj).sort((a, b) => a.localeCompare(b)).map((key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`).join(",")}}`;
|
|
95
101
|
}
|
|
102
|
+
function getGenerateStats(filesData, config) {
|
|
103
|
+
const generatedFilesCount = filesData.length;
|
|
104
|
+
if (generatedFilesCount === 0) return {
|
|
105
|
+
generatedFilesCount,
|
|
106
|
+
generatedModulesCount: 0
|
|
107
|
+
};
|
|
108
|
+
if (!config.splitByTags) return {
|
|
109
|
+
generatedFilesCount,
|
|
110
|
+
generatedModulesCount: 1
|
|
111
|
+
};
|
|
112
|
+
const moduleSuffixes = new Set(Object.values(config.configs).map((generateConfig) => generateConfig.outputFileNameSuffix).filter(Boolean));
|
|
113
|
+
const modules = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const file of filesData) {
|
|
115
|
+
const segments = path.relative(config.output, file.fileName).split(path.sep).filter(Boolean);
|
|
116
|
+
if (segments.length < 2) continue;
|
|
117
|
+
const moduleName = segments[0];
|
|
118
|
+
const fileName = segments[segments.length - 1];
|
|
119
|
+
if (!fileName.startsWith(`${moduleName}.`)) continue;
|
|
120
|
+
const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
|
|
121
|
+
if (moduleSuffixes.has(suffix)) modules.add(moduleName);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
generatedFilesCount,
|
|
125
|
+
generatedModulesCount: modules.size
|
|
126
|
+
};
|
|
127
|
+
}
|
|
96
128
|
|
|
97
129
|
//#endregion
|
|
98
130
|
export { resolveConfig as n, runGenerate as t };
|
package/dist/{generateCodeFromOpenAPIDoc-CQZ2OLwB.mjs → generateCodeFromOpenAPIDoc-CfeJeQ0w.mjs}
RENAMED
|
@@ -606,6 +606,79 @@ const CASL_ABILITY_IMPORT = {
|
|
|
606
606
|
from: "@casl/ability"
|
|
607
607
|
};
|
|
608
608
|
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region src/generators/const/options.const.ts
|
|
611
|
+
const DEFAULT_GENERATE_OPTIONS = {
|
|
612
|
+
input: "http://localhost:4000/docs-json/",
|
|
613
|
+
output: "output",
|
|
614
|
+
incremental: true,
|
|
615
|
+
splitByTags: true,
|
|
616
|
+
defaultTag: "Common",
|
|
617
|
+
excludeTags: [],
|
|
618
|
+
excludePathRegex: "",
|
|
619
|
+
excludeRedundantZodSchemas: true,
|
|
620
|
+
tsNamespaces: true,
|
|
621
|
+
tsPath: "@/data",
|
|
622
|
+
importPath: "ts",
|
|
623
|
+
configs: {
|
|
624
|
+
[GenerateType.Models]: {
|
|
625
|
+
outputFileNameSuffix: "models",
|
|
626
|
+
namespaceSuffix: "Models"
|
|
627
|
+
},
|
|
628
|
+
[GenerateType.Endpoints]: {
|
|
629
|
+
outputFileNameSuffix: "api",
|
|
630
|
+
namespaceSuffix: "Api"
|
|
631
|
+
},
|
|
632
|
+
[GenerateType.Queries]: {
|
|
633
|
+
outputFileNameSuffix: "queries",
|
|
634
|
+
namespaceSuffix: "Queries"
|
|
635
|
+
},
|
|
636
|
+
[GenerateType.Acl]: {
|
|
637
|
+
outputFileNameSuffix: "acl",
|
|
638
|
+
namespaceSuffix: "Acl"
|
|
639
|
+
},
|
|
640
|
+
[GenerateType.Configs]: {
|
|
641
|
+
outputFileNameSuffix: "configs",
|
|
642
|
+
namespaceSuffix: "Configs"
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
baseUrl: "",
|
|
646
|
+
modelsOnly: false,
|
|
647
|
+
standalone: false,
|
|
648
|
+
schemaSuffix: SCHEMA_SUFFIX,
|
|
649
|
+
enumSuffix: ENUM_SUFFIX,
|
|
650
|
+
modelsInCommon: false,
|
|
651
|
+
withDefaultValues: true,
|
|
652
|
+
extractEnums: true,
|
|
653
|
+
replaceOptionalWithNullish: false,
|
|
654
|
+
restClientImportPath: "",
|
|
655
|
+
errorHandlingImportPath: "",
|
|
656
|
+
removeOperationPrefixEndingWith: "Controller_",
|
|
657
|
+
parseRequestParams: true,
|
|
658
|
+
inlineEndpoints: false,
|
|
659
|
+
inlineEndpointsExcludeModules: [],
|
|
660
|
+
queryTypesImportPath: PACKAGE_IMPORT_PATH,
|
|
661
|
+
axiosRequestConfig: false,
|
|
662
|
+
mutationEffects: true,
|
|
663
|
+
workspaceContext: false,
|
|
664
|
+
infiniteQueries: false,
|
|
665
|
+
infiniteQueryParamNames: { page: "page" },
|
|
666
|
+
infiniteQueryResponseParamNames: {
|
|
667
|
+
page: "page",
|
|
668
|
+
totalItems: "totalItems",
|
|
669
|
+
limit: "limit"
|
|
670
|
+
},
|
|
671
|
+
acl: true,
|
|
672
|
+
checkAcl: true,
|
|
673
|
+
abilityContextGenericAppAbilities: false,
|
|
674
|
+
abilityContextImportPath: "",
|
|
675
|
+
builderConfigs: false,
|
|
676
|
+
filterParamName: "filter",
|
|
677
|
+
dataResponseParamNames: ["data", "items"],
|
|
678
|
+
dynamicInputsImportPath: "@povio/ui",
|
|
679
|
+
dynamicColumnsImportPath: "@povio/ui"
|
|
680
|
+
};
|
|
681
|
+
|
|
609
682
|
//#endregion
|
|
610
683
|
//#region src/generators/utils/array.utils.ts
|
|
611
684
|
const getUniqueArray = (...arrs) => [...new Set(arrs.flat())];
|
|
@@ -780,18 +853,19 @@ function getSchemaDescriptions(schemaObj) {
|
|
|
780
853
|
//#endregion
|
|
781
854
|
//#region src/generators/utils/generate/generate.zod.utils.ts
|
|
782
855
|
const getZodSchemaInferedTypeName = (zodSchemaName, options) => removeSuffix(zodSchemaName, options.schemaSuffix);
|
|
783
|
-
const getImportedZodSchemaName = (resolver, zodSchemaName) => {
|
|
856
|
+
const getImportedZodSchemaName = (resolver, zodSchemaName, namespaceTag) => {
|
|
784
857
|
if (!isNamedZodSchema(zodSchemaName)) return zodSchemaName;
|
|
858
|
+
const tag = namespaceTag ?? resolver.getTagByZodSchemaName(zodSchemaName);
|
|
785
859
|
return `${resolver.options.tsNamespaces ? `${getNamespaceName({
|
|
786
860
|
type: GenerateType.Models,
|
|
787
|
-
tag
|
|
861
|
+
tag,
|
|
788
862
|
options: resolver.options
|
|
789
863
|
})}.` : ""}${zodSchemaName}`;
|
|
790
864
|
};
|
|
791
|
-
const getImportedZodSchemaInferedTypeName = (resolver, zodSchemaName, currentTag) => {
|
|
865
|
+
const getImportedZodSchemaInferedTypeName = (resolver, zodSchemaName, currentTag, namespaceTag) => {
|
|
792
866
|
if (!isNamedZodSchema(zodSchemaName)) return zodSchemaName === VOID_SCHEMA ? "void" : zodSchemaName;
|
|
793
|
-
const tag = resolver.getTagByZodSchemaName(zodSchemaName);
|
|
794
|
-
return `${resolver.options.tsNamespaces && tag !== currentTag ? `${getNamespaceName({
|
|
867
|
+
const tag = namespaceTag ?? resolver.getTagByZodSchemaName(zodSchemaName);
|
|
868
|
+
return `${resolver.options.tsNamespaces && (Boolean(namespaceTag) || tag !== currentTag) ? `${getNamespaceName({
|
|
795
869
|
type: GenerateType.Models,
|
|
796
870
|
tag,
|
|
797
871
|
options: resolver.options
|
|
@@ -987,14 +1061,14 @@ function getTagFileName(...args) {
|
|
|
987
1061
|
return `${getTagFileNameWithoutExtension(...args)}.ts`;
|
|
988
1062
|
}
|
|
989
1063
|
function getAppRestClientImportPath(options) {
|
|
990
|
-
if (
|
|
1064
|
+
if (options.restClientImportPath === DEFAULT_GENERATE_OPTIONS.restClientImportPath) return `${getImportPath(options)}${APP_REST_CLIENT_FILE.fileName}`;
|
|
991
1065
|
return options.restClientImportPath;
|
|
992
1066
|
}
|
|
993
1067
|
function getQueryModulesImportPath(options) {
|
|
994
1068
|
return `${getImportPath(options)}${QUERY_MODULES_FILE.fileName}`;
|
|
995
1069
|
}
|
|
996
1070
|
function getQueryTypesImportPath(options) {
|
|
997
|
-
return options.queryTypesImportPath
|
|
1071
|
+
return options.queryTypesImportPath;
|
|
998
1072
|
}
|
|
999
1073
|
function getMutationEffectsImportPath(options) {
|
|
1000
1074
|
return `${getImportPath(options)}${MUTATION_EFFECTS_FILE.fileName}`;
|
|
@@ -1180,7 +1254,7 @@ const getEndpointPath = (endpoint) => endpoint.path.replace(/:([a-zA-Z0-9_]+)/g,
|
|
|
1180
1254
|
function mapEndpointParamsToFunctionParams(resolver, endpoint, options) {
|
|
1181
1255
|
const params = endpoint.parameters.map((param) => {
|
|
1182
1256
|
let type = "string";
|
|
1183
|
-
if (isNamedZodSchema(param.zodSchema)) type = getImportedZodSchemaInferedTypeName(resolver, param.zodSchema);
|
|
1257
|
+
if (isNamedZodSchema(param.zodSchema)) type = getImportedZodSchemaInferedTypeName(resolver, param.zodSchema, void 0, options?.modelNamespaceTag);
|
|
1184
1258
|
else if (param.parameterObject?.schema && isSchemaObject(param.parameterObject.schema)) {
|
|
1185
1259
|
const openApiSchemaType = (param.parameterObject?.schema)?.type;
|
|
1186
1260
|
if (openApiSchemaType && isPrimitiveType(openApiSchemaType)) type = primitiveTypeToTsType(openApiSchemaType);
|
|
@@ -3007,79 +3081,6 @@ function writeGenerateFileData(filesData) {
|
|
|
3007
3081
|
filesData.forEach(writeFileSync$1);
|
|
3008
3082
|
}
|
|
3009
3083
|
|
|
3010
|
-
//#endregion
|
|
3011
|
-
//#region src/generators/const/options.const.ts
|
|
3012
|
-
const DEFAULT_GENERATE_OPTIONS = {
|
|
3013
|
-
input: "http://localhost:4000/docs-json/",
|
|
3014
|
-
output: "output",
|
|
3015
|
-
incremental: true,
|
|
3016
|
-
splitByTags: true,
|
|
3017
|
-
defaultTag: "Common",
|
|
3018
|
-
excludeTags: [],
|
|
3019
|
-
excludePathRegex: "",
|
|
3020
|
-
excludeRedundantZodSchemas: true,
|
|
3021
|
-
tsNamespaces: true,
|
|
3022
|
-
tsPath: "@/data",
|
|
3023
|
-
importPath: "ts",
|
|
3024
|
-
configs: {
|
|
3025
|
-
[GenerateType.Models]: {
|
|
3026
|
-
outputFileNameSuffix: "models",
|
|
3027
|
-
namespaceSuffix: "Models"
|
|
3028
|
-
},
|
|
3029
|
-
[GenerateType.Endpoints]: {
|
|
3030
|
-
outputFileNameSuffix: "api",
|
|
3031
|
-
namespaceSuffix: "Api"
|
|
3032
|
-
},
|
|
3033
|
-
[GenerateType.Queries]: {
|
|
3034
|
-
outputFileNameSuffix: "queries",
|
|
3035
|
-
namespaceSuffix: "Queries"
|
|
3036
|
-
},
|
|
3037
|
-
[GenerateType.Acl]: {
|
|
3038
|
-
outputFileNameSuffix: "acl",
|
|
3039
|
-
namespaceSuffix: "Acl"
|
|
3040
|
-
},
|
|
3041
|
-
[GenerateType.Configs]: {
|
|
3042
|
-
outputFileNameSuffix: "configs",
|
|
3043
|
-
namespaceSuffix: "Configs"
|
|
3044
|
-
}
|
|
3045
|
-
},
|
|
3046
|
-
baseUrl: "",
|
|
3047
|
-
modelsOnly: false,
|
|
3048
|
-
standalone: false,
|
|
3049
|
-
schemaSuffix: SCHEMA_SUFFIX,
|
|
3050
|
-
enumSuffix: ENUM_SUFFIX,
|
|
3051
|
-
modelsInCommon: false,
|
|
3052
|
-
withDefaultValues: true,
|
|
3053
|
-
extractEnums: true,
|
|
3054
|
-
replaceOptionalWithNullish: false,
|
|
3055
|
-
restClientImportPath: "",
|
|
3056
|
-
errorHandlingImportPath: "",
|
|
3057
|
-
removeOperationPrefixEndingWith: "Controller_",
|
|
3058
|
-
parseRequestParams: true,
|
|
3059
|
-
inlineEndpoints: false,
|
|
3060
|
-
inlineEndpointsExcludeModules: [],
|
|
3061
|
-
queryTypesImportPath: PACKAGE_IMPORT_PATH,
|
|
3062
|
-
axiosRequestConfig: false,
|
|
3063
|
-
mutationEffects: true,
|
|
3064
|
-
workspaceContext: false,
|
|
3065
|
-
infiniteQueries: false,
|
|
3066
|
-
infiniteQueryParamNames: { page: "page" },
|
|
3067
|
-
infiniteQueryResponseParamNames: {
|
|
3068
|
-
page: "page",
|
|
3069
|
-
totalItems: "totalItems",
|
|
3070
|
-
limit: "limit"
|
|
3071
|
-
},
|
|
3072
|
-
acl: true,
|
|
3073
|
-
checkAcl: true,
|
|
3074
|
-
abilityContextGenericAppAbilities: false,
|
|
3075
|
-
abilityContextImportPath: "",
|
|
3076
|
-
builderConfigs: false,
|
|
3077
|
-
filterParamName: "filter",
|
|
3078
|
-
dataResponseParamNames: ["data", "items"],
|
|
3079
|
-
dynamicInputsImportPath: "@povio/ui",
|
|
3080
|
-
dynamicColumnsImportPath: "@povio/ui"
|
|
3081
|
-
};
|
|
3082
|
-
|
|
3083
3084
|
//#endregion
|
|
3084
3085
|
//#region src/generators/generate/generateAcl.ts
|
|
3085
3086
|
function generateAcl({ resolver, data, tag }) {
|
|
@@ -3536,16 +3537,17 @@ function generateEndpoints({ resolver, data, tag }) {
|
|
|
3536
3537
|
options: resolver.options
|
|
3537
3538
|
})} {`);
|
|
3538
3539
|
for (const endpoint of endpoints) {
|
|
3539
|
-
const
|
|
3540
|
-
|
|
3540
|
+
const endpointParamOptions = { modelNamespaceTag: tag };
|
|
3541
|
+
const endpointParams = renderEndpointParams$1(resolver, endpoint, endpointParamOptions);
|
|
3542
|
+
renderEndpointArgs$1(resolver, endpoint, endpointParamOptions);
|
|
3541
3543
|
const endpointBody = getEndpointBody$1(endpoint);
|
|
3542
3544
|
const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
|
|
3543
|
-
const endpointConfig = renderEndpointConfig(resolver, endpoint);
|
|
3545
|
+
const endpointConfig = renderEndpointConfig(resolver, endpoint, tag);
|
|
3544
3546
|
lines.push(`export const ${getEndpointName(endpoint)} = (${endpointParams}${hasAxiosRequestConfig ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
3545
3547
|
lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
3546
|
-
lines.push(` { resSchema: ${getImportedZodSchemaName(resolver, endpoint.response)} },`);
|
|
3548
|
+
lines.push(` { resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, tag)} },`);
|
|
3547
3549
|
lines.push(` \`${getEndpointPath(endpoint)}\`,`);
|
|
3548
|
-
if (endpointBody) lines.push(` ${generateParse ? renderEndpointParamParse(resolver, endpointBody, endpointBody.name) : endpointBody.name},`);
|
|
3550
|
+
if (endpointBody) lines.push(` ${generateParse ? renderEndpointParamParse(resolver, endpointBody, endpointBody.name, tag) : endpointBody.name},`);
|
|
3549
3551
|
else if (hasUndefinedEndpointBody) lines.push(" undefined,");
|
|
3550
3552
|
lines.push(` ${endpointConfig}`);
|
|
3551
3553
|
lines.push(" )");
|
|
@@ -3563,13 +3565,13 @@ function renderEndpointParams$1(resolver, endpoint, options) {
|
|
|
3563
3565
|
function renderEndpointArgs$1(resolver, endpoint, options) {
|
|
3564
3566
|
return mapEndpointParamsToFunctionParams(resolver, endpoint, options).map((param) => param.name).join(", ");
|
|
3565
3567
|
}
|
|
3566
|
-
function renderEndpointParamParse(resolver, param, paramName) {
|
|
3568
|
+
function renderEndpointParamParse(resolver, param, paramName, modelNamespaceTag) {
|
|
3567
3569
|
const addOptional = !(param.parameterObject ?? param.bodyObject)?.required && (Boolean(param.parameterSortingEnumSchemaName) || isNamedZodSchema(param.zodSchema));
|
|
3568
|
-
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName)})${addOptional ? ".optional()" : ""}` : `${getImportedZodSchemaName(resolver, param.zodSchema)}${addOptional ? ".optional()" : ""}`;
|
|
3570
|
+
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName, modelNamespaceTag)})${addOptional ? ".optional()" : ""}` : `${getImportedZodSchemaName(resolver, param.zodSchema, modelNamespaceTag)}${addOptional ? ".optional()" : ""}`;
|
|
3569
3571
|
const queryArgs = param.type === "Query" ? `, { type: "query", name: "${paramName}" }` : "";
|
|
3570
3572
|
return `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.parse}(${schemaValue}, ${paramName}${queryArgs})`;
|
|
3571
3573
|
}
|
|
3572
|
-
function renderEndpointConfig(resolver, endpoint) {
|
|
3574
|
+
function renderEndpointConfig(resolver, endpoint, modelNamespaceTag) {
|
|
3573
3575
|
const endpointConfig = getEndpointConfig(endpoint);
|
|
3574
3576
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
3575
3577
|
if (Object.keys(endpointConfig).length === 0) return hasAxiosRequestConfig ? AXIOS_REQUEST_CONFIG_NAME : "";
|
|
@@ -3579,7 +3581,7 @@ function renderEndpointConfig(resolver, endpoint) {
|
|
|
3579
3581
|
if (endpointConfig.params) {
|
|
3580
3582
|
lines.push(" params: {");
|
|
3581
3583
|
for (const param of endpointConfig.params) {
|
|
3582
|
-
const value = resolver.options.parseRequestParams ? renderEndpointParamParse(resolver, param, param.value) : param.value;
|
|
3584
|
+
const value = resolver.options.parseRequestParams ? renderEndpointParamParse(resolver, param, param.value, modelNamespaceTag) : param.value;
|
|
3583
3585
|
lines.push(` ${param.name}: ${value},`);
|
|
3584
3586
|
}
|
|
3585
3587
|
lines.push(" },");
|
|
@@ -3862,7 +3864,8 @@ function generateQueries(params) {
|
|
|
3862
3864
|
if (inlineEndpoints) {
|
|
3863
3865
|
lines.push(...renderInlineEndpoints({
|
|
3864
3866
|
resolver,
|
|
3865
|
-
endpoints
|
|
3867
|
+
endpoints,
|
|
3868
|
+
tag
|
|
3866
3869
|
}));
|
|
3867
3870
|
lines.push("");
|
|
3868
3871
|
}
|
|
@@ -4019,18 +4022,18 @@ function renderQueryKeys({ resolver, queryEndpoints }) {
|
|
|
4019
4022
|
lines.push("};");
|
|
4020
4023
|
return lines.join("\n");
|
|
4021
4024
|
}
|
|
4022
|
-
function renderInlineEndpoints({ resolver, endpoints }) {
|
|
4025
|
+
function renderInlineEndpoints({ resolver, endpoints, tag }) {
|
|
4023
4026
|
const lines = [];
|
|
4024
4027
|
for (const endpoint of endpoints) {
|
|
4025
|
-
const endpointParams = renderEndpointParams(resolver, endpoint, {});
|
|
4028
|
+
const endpointParams = renderEndpointParams(resolver, endpoint, { modelNamespaceTag: tag });
|
|
4026
4029
|
const endpointBody = getEndpointBody$1(endpoint);
|
|
4027
4030
|
const hasUndefinedEndpointBody = requiresBody(endpoint) && !endpointBody && hasEndpointConfig(endpoint, resolver);
|
|
4028
|
-
const endpointConfig = renderInlineEndpointConfig(resolver, endpoint);
|
|
4031
|
+
const endpointConfig = renderInlineEndpointConfig(resolver, endpoint, tag);
|
|
4029
4032
|
lines.push(`const ${getEndpointName(endpoint)} = (${endpointParams}${resolver.options.axiosRequestConfig ? `${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4030
4033
|
lines.push(` return ${APP_REST_CLIENT_NAME}.${endpoint.method}(`);
|
|
4031
|
-
lines.push(` { resSchema: ${getImportedZodSchemaName(resolver, endpoint.response)} },`);
|
|
4034
|
+
lines.push(` { resSchema: ${getImportedZodSchemaName(resolver, endpoint.response, tag)} },`);
|
|
4032
4035
|
lines.push(` \`${getEndpointPath(endpoint)}\`,`);
|
|
4033
|
-
if (endpointBody) lines.push(` ${resolver.options.parseRequestParams ? renderInlineEndpointParamParse(resolver, endpointBody, endpointBody.name) : endpointBody.name},`);
|
|
4036
|
+
if (endpointBody) lines.push(` ${resolver.options.parseRequestParams ? renderInlineEndpointParamParse(resolver, endpointBody, endpointBody.name, tag) : endpointBody.name},`);
|
|
4034
4037
|
else if (hasUndefinedEndpointBody) lines.push(" undefined,");
|
|
4035
4038
|
lines.push(` ${endpointConfig}`);
|
|
4036
4039
|
lines.push(" );");
|
|
@@ -4039,13 +4042,13 @@ function renderInlineEndpoints({ resolver, endpoints }) {
|
|
|
4039
4042
|
}
|
|
4040
4043
|
return lines;
|
|
4041
4044
|
}
|
|
4042
|
-
function renderInlineEndpointParamParse(resolver, param, paramName) {
|
|
4045
|
+
function renderInlineEndpointParamParse(resolver, param, paramName, modelNamespaceTag) {
|
|
4043
4046
|
const addOptional = !(param.parameterObject ?? param.bodyObject)?.required && (Boolean(param.parameterSortingEnumSchemaName) || isNamedZodSchema(param.zodSchema));
|
|
4044
|
-
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName)})${addOptional ? ".optional()" : ""}` : `${getImportedZodSchemaName(resolver, param.zodSchema)}${addOptional ? ".optional()" : ""}`;
|
|
4047
|
+
const schemaValue = param.parameterSortingEnumSchemaName ? `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.sortExp}(${getImportedZodSchemaName(resolver, param.parameterSortingEnumSchemaName, modelNamespaceTag)})${addOptional ? ".optional()" : ""}` : `${getImportedZodSchemaName(resolver, param.zodSchema, modelNamespaceTag)}${addOptional ? ".optional()" : ""}`;
|
|
4045
4048
|
const queryArgs = param.type === "Query" ? `, { type: "query", name: "${paramName}" }` : "";
|
|
4046
4049
|
return `${ZOD_EXTENDED.namespace}.${ZOD_EXTENDED.exports.parse}(${schemaValue}, ${paramName}${queryArgs})`;
|
|
4047
4050
|
}
|
|
4048
|
-
function renderInlineEndpointConfig(resolver, endpoint) {
|
|
4051
|
+
function renderInlineEndpointConfig(resolver, endpoint, modelNamespaceTag) {
|
|
4049
4052
|
const endpointConfig = getEndpointConfig(endpoint);
|
|
4050
4053
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
4051
4054
|
if (Object.keys(endpointConfig).length === 0) return hasAxiosRequestConfig ? AXIOS_REQUEST_CONFIG_NAME : "";
|
|
@@ -4055,7 +4058,7 @@ function renderInlineEndpointConfig(resolver, endpoint) {
|
|
|
4055
4058
|
if (endpointConfig.params) {
|
|
4056
4059
|
lines.push(" params: {");
|
|
4057
4060
|
for (const param of endpointConfig.params) {
|
|
4058
|
-
const value = resolver.options.parseRequestParams ? renderInlineEndpointParamParse(resolver, param, param.value) : param.value;
|
|
4061
|
+
const value = resolver.options.parseRequestParams ? renderInlineEndpointParamParse(resolver, param, param.value, modelNamespaceTag) : param.value;
|
|
4059
4062
|
lines.push(` ${param.name}: ${value},`);
|
|
4060
4063
|
}
|
|
4061
4064
|
lines.push(" },");
|
|
@@ -4269,9 +4272,9 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4269
4272
|
//#endregion
|
|
4270
4273
|
//#region src/generators/generate/generateAclCheck.ts
|
|
4271
4274
|
function generateAclCheck(resolver) {
|
|
4272
|
-
const abilityContextImportPath = resolver.options.abilityContextImportPath
|
|
4275
|
+
const abilityContextImportPath = resolver.options.abilityContextImportPath ?? ABILITY_CONTEXT_IMPORT.from;
|
|
4273
4276
|
const appAbilitiesImportPath = getAppAbilitiesImportPath(resolver.options);
|
|
4274
|
-
const errorHandlingImportPath = resolver.options.errorHandlingImportPath
|
|
4277
|
+
const errorHandlingImportPath = resolver.options.errorHandlingImportPath ?? ERROR_HANDLING_IMPORT.from;
|
|
4275
4278
|
const genericAppAbilities = resolver.options.abilityContextGenericAppAbilities ? `<${ACL_APP_ABILITIES}>` : "";
|
|
4276
4279
|
return `import { ${CASL_ABILITY_BINDING.abilityTuple} } from "@casl/ability";
|
|
4277
4280
|
import { type ${ERROR_HANDLERS.ErrorHandler}, ${ERROR_HANDLERS.SharedErrorHandler} } from "${errorHandlingImportPath}";
|
|
@@ -4338,7 +4341,7 @@ function generateQueryModules({ resolver, data }) {
|
|
|
4338
4341
|
function generateZodExtended(resolver) {
|
|
4339
4342
|
const errorHandlingImport = {
|
|
4340
4343
|
...ERROR_HANDLING_IMPORT,
|
|
4341
|
-
from: resolver.options.errorHandlingImportPath
|
|
4344
|
+
from: resolver.options.errorHandlingImportPath ?? ERROR_HANDLING_IMPORT.from
|
|
4342
4345
|
};
|
|
4343
4346
|
return `${renderImport(ZOD_IMPORT)}
|
|
4344
4347
|
${renderImport(errorHandlingImport)}
|
|
@@ -4519,4 +4522,4 @@ function generateCodeFromOpenAPIDoc(openApiDoc, options, profiler) {
|
|
|
4519
4522
|
}
|
|
4520
4523
|
|
|
4521
4524
|
//#endregion
|
|
4522
|
-
export { VALIDATION_ERROR_TYPE_TITLE as S, isMediaTypeAllowed as _,
|
|
4525
|
+
export { VALIDATION_ERROR_TYPE_TITLE as S, isMediaTypeAllowed as _, deepMerge as a, formatTag as b, getSchemaTsMetaType as c, getTagImportPath as d, getQueryName as f, groupByType as g, GenerateType as h, getDataFromOpenAPIDoc as i, getTsTypeBase as l, getNamespaceName as m, getOutputFileName as n, isMutation as o, DEFAULT_GENERATE_OPTIONS as p, writeGenerateFileData as r, isQuery as s, generateCodeFromOpenAPIDoc as t, getTagFileName as u, isParamMediaTypeAllowed as v, Profiler as x, invalidVariableNameCharactersToCamel as y };
|
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as isMediaTypeAllowed,
|
|
1
|
+
import { _ as isMediaTypeAllowed, b as formatTag, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, h as GenerateType, i as getDataFromOpenAPIDoc, l as getTsTypeBase, m as getNamespaceName, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as isParamMediaTypeAllowed, y as invalidVariableNameCharactersToCamel } from "./generateCodeFromOpenAPIDoc-CfeJeQ0w.mjs";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
package/dist/sh.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { S as VALIDATION_ERROR_TYPE_TITLE,
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
2
|
+
import { S as VALIDATION_ERROR_TYPE_TITLE, g as groupByType, h as GenerateType, i as getDataFromOpenAPIDoc, n as getOutputFileName, u as getTagFileName, x as Profiler } from "./generateCodeFromOpenAPIDoc-CfeJeQ0w.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-DpXZK8Yc.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
@@ -39,7 +39,7 @@ function logBanner(message) {
|
|
|
39
39
|
* Fetch the version from package.json
|
|
40
40
|
*/
|
|
41
41
|
function getVersion() {
|
|
42
|
-
return "2.0.8-rc.
|
|
42
|
+
return "2.0.8-rc.11";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as runGenerate } from "./generate.runner-
|
|
1
|
+
import { x as Profiler } from "./generateCodeFromOpenAPIDoc-CfeJeQ0w.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-DpXZK8Yc.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.ts
|