@povio/openapi-codegen-cli 3.1.0 → 3.1.1
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-DnUDkoAZ.mjs → generate.runner-C1HrS_9G.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-CbQ9gQss.mjs → generateCodeFromOpenAPIDoc-DseBECa-.mjs} +39 -3
- package/dist/generator.mjs +1 -1
- package/dist/metro.cjs +39 -3
- package/dist/metro.mjs +3 -3
- package/dist/{openapi-codegen.runner-BqOhUduF.mjs → openapi-codegen.runner-Co_bG00_.mjs} +2 -2
- package/dist/sh.mjs +3 -3
- package/dist/vite.mjs +3 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
4
4
|
|
package/dist/{generateCodeFromOpenAPIDoc-CbQ9gQss.mjs → generateCodeFromOpenAPIDoc-DseBECa-.mjs}
RENAMED
|
@@ -4028,7 +4028,7 @@ function generateModels({ resolver, data, tag }) {
|
|
|
4028
4028
|
const schemaRef = resolver.getRefByZodSchemaName(key);
|
|
4029
4029
|
zodSchemasData[key] = {
|
|
4030
4030
|
code,
|
|
4031
|
-
|
|
4031
|
+
isCircular: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
|
|
4032
4032
|
isEnum: isEnumZodSchema(code),
|
|
4033
4033
|
schemaObj: resolver.getZodSchemaObj(key)
|
|
4034
4034
|
};
|
|
@@ -4049,14 +4049,50 @@ function generateModels({ resolver, data, tag }) {
|
|
|
4049
4049
|
tag,
|
|
4050
4050
|
resolver
|
|
4051
4051
|
}));
|
|
4052
|
-
|
|
4053
|
-
lines.push(`export type ${
|
|
4052
|
+
const inferredTypeName = getZodSchemaInferedTypeName(name, resolver.options);
|
|
4053
|
+
if (zodSchema.isCircular && zodSchema.schemaObj) lines.push(`export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
|
|
4054
|
+
const typeAnnotation = zodSchema.isCircular ? `: z.ZodObject<z.ZodRawShape> & z.ZodType<${inferredTypeName}>` : "";
|
|
4055
|
+
lines.push(`export const ${name}${typeAnnotation} = ${zodSchema.code};`);
|
|
4056
|
+
if (!zodSchema.isCircular) lines.push(`export type ${inferredTypeName} = z.infer<typeof ${name}>;`);
|
|
4054
4057
|
if (zodSchema.isEnum) lines.push(`export const ${getZodSchemaInferedTypeName(name, resolver.options)} = ${name}.enum;`);
|
|
4055
4058
|
lines.push("");
|
|
4056
4059
|
}
|
|
4057
4060
|
if (resolver.options.tsNamespaces) lines.push("}");
|
|
4058
4061
|
return lines.join("\n").trimEnd() + "\n";
|
|
4059
4062
|
}
|
|
4063
|
+
function renderSchemaType(schema, resolver) {
|
|
4064
|
+
if (isReferenceObject(schema)) {
|
|
4065
|
+
const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
|
|
4066
|
+
return schemaName ? getZodSchemaInferedTypeName(schemaName, resolver.options) : "unknown";
|
|
4067
|
+
}
|
|
4068
|
+
const composite = schema.allOf ?? schema.oneOf ?? schema.anyOf;
|
|
4069
|
+
if (composite?.length) {
|
|
4070
|
+
const separator = schema.allOf ? " & " : " | ";
|
|
4071
|
+
return addNullable(schema, composite.map((part) => renderSchemaType(part, resolver)).join(separator));
|
|
4072
|
+
}
|
|
4073
|
+
if (schema.enum?.length) return addNullable(schema, schema.enum.map((value) => JSON.stringify(value)).join(" | "));
|
|
4074
|
+
if (schema.type === "array") return addNullable(schema, `Array<${schema.items ? renderSchemaType(schema.items, resolver) : "unknown"}>`);
|
|
4075
|
+
if (schema.type === "object" || schema.properties || schema.additionalProperties) {
|
|
4076
|
+
const properties = Object.entries(schema.properties ?? {}).map(([name, property]) => {
|
|
4077
|
+
const isRequired = resolver.options.withImplicitRequiredProps || schema.required?.includes(name);
|
|
4078
|
+
const hasDefault = !isReferenceObject(property) && property.default !== void 0;
|
|
4079
|
+
const optional = isRequired || hasDefault ? "" : "?";
|
|
4080
|
+
const propertyType = renderSchemaType(property, resolver);
|
|
4081
|
+
const outputType = resolver.options.replaceOptionalWithNullish && optional && (isReferenceObject(property) || !property.nullable) ? `${propertyType} | null` : propertyType;
|
|
4082
|
+
return `${wrapWithQuotesIfNeeded(name)}${optional}: ${outputType}`;
|
|
4083
|
+
});
|
|
4084
|
+
if (schema.additionalProperties) {
|
|
4085
|
+
const valueType = typeof schema.additionalProperties === "object" ? renderSchemaType(schema.additionalProperties, resolver) : "unknown";
|
|
4086
|
+
properties.push(`[key: string]: ${valueType}`);
|
|
4087
|
+
}
|
|
4088
|
+
return addNullable(schema, `{ ${properties.join("; ")} }`);
|
|
4089
|
+
}
|
|
4090
|
+
const primitiveType = schema.type;
|
|
4091
|
+
return addNullable(schema, primitiveType === "string" ? "string" : primitiveType === "number" || primitiveType === "integer" ? "number" : primitiveType === "boolean" ? "boolean" : primitiveType === "null" ? "null" : "unknown");
|
|
4092
|
+
}
|
|
4093
|
+
function addNullable(schema, type) {
|
|
4094
|
+
return schema.nullable && type !== "null" ? `${type} | null` : type;
|
|
4095
|
+
}
|
|
4060
4096
|
function renderModelsProxy({ resolver, data, tag }) {
|
|
4061
4097
|
const commonZodSchemas = data.get(resolver.options.defaultTag)?.zodSchemas ?? {};
|
|
4062
4098
|
const schemaNames = getUsedSchemaNames({
|
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { _ as getNamespaceName, a as getDataFromOpenAPIDoc, b as isParamMediaTypeAllowed, c as getSchemaTsMetaType, d as getTagImportPath, f as getQueryName, g as invalidVariableNameCharactersToCamel, l as getTsTypeBase, o as isMutation, p as DEFAULT_GENERATE_OPTIONS, s as isQuery, t as generateCodeFromOpenAPIDoc, v as GenerateType, x as formatTag, y as isMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
package/dist/metro.cjs
CHANGED
|
@@ -3838,7 +3838,7 @@ function generateModels({ resolver, data, tag }) {
|
|
|
3838
3838
|
const schemaRef = resolver.getRefByZodSchemaName(key);
|
|
3839
3839
|
zodSchemasData[key] = {
|
|
3840
3840
|
code,
|
|
3841
|
-
|
|
3841
|
+
isCircular: schemaRef ? resolver.isSchemaCircular(schemaRef) : false,
|
|
3842
3842
|
isEnum: isEnumZodSchema(code),
|
|
3843
3843
|
schemaObj: resolver.getZodSchemaObj(key)
|
|
3844
3844
|
};
|
|
@@ -3859,14 +3859,50 @@ function generateModels({ resolver, data, tag }) {
|
|
|
3859
3859
|
tag,
|
|
3860
3860
|
resolver
|
|
3861
3861
|
}));
|
|
3862
|
-
|
|
3863
|
-
lines.push(`export type ${
|
|
3862
|
+
const inferredTypeName = getZodSchemaInferedTypeName(name, resolver.options);
|
|
3863
|
+
if (zodSchema.isCircular && zodSchema.schemaObj) lines.push(`export type ${inferredTypeName} = ${renderSchemaType(zodSchema.schemaObj, resolver)};`);
|
|
3864
|
+
const typeAnnotation = zodSchema.isCircular ? `: z.ZodObject<z.ZodRawShape> & z.ZodType<${inferredTypeName}>` : "";
|
|
3865
|
+
lines.push(`export const ${name}${typeAnnotation} = ${zodSchema.code};`);
|
|
3866
|
+
if (!zodSchema.isCircular) lines.push(`export type ${inferredTypeName} = z.infer<typeof ${name}>;`);
|
|
3864
3867
|
if (zodSchema.isEnum) lines.push(`export const ${getZodSchemaInferedTypeName(name, resolver.options)} = ${name}.enum;`);
|
|
3865
3868
|
lines.push("");
|
|
3866
3869
|
}
|
|
3867
3870
|
if (resolver.options.tsNamespaces) lines.push("}");
|
|
3868
3871
|
return lines.join("\n").trimEnd() + "\n";
|
|
3869
3872
|
}
|
|
3873
|
+
function renderSchemaType(schema, resolver) {
|
|
3874
|
+
if (isReferenceObject(schema)) {
|
|
3875
|
+
const schemaName = resolver.getZodSchemaNameByRef(schema.$ref);
|
|
3876
|
+
return schemaName ? getZodSchemaInferedTypeName(schemaName, resolver.options) : "unknown";
|
|
3877
|
+
}
|
|
3878
|
+
const composite = schema.allOf ?? schema.oneOf ?? schema.anyOf;
|
|
3879
|
+
if (composite?.length) {
|
|
3880
|
+
const separator = schema.allOf ? " & " : " | ";
|
|
3881
|
+
return addNullable(schema, composite.map((part) => renderSchemaType(part, resolver)).join(separator));
|
|
3882
|
+
}
|
|
3883
|
+
if (schema.enum?.length) return addNullable(schema, schema.enum.map((value) => JSON.stringify(value)).join(" | "));
|
|
3884
|
+
if (schema.type === "array") return addNullable(schema, `Array<${schema.items ? renderSchemaType(schema.items, resolver) : "unknown"}>`);
|
|
3885
|
+
if (schema.type === "object" || schema.properties || schema.additionalProperties) {
|
|
3886
|
+
const properties = Object.entries(schema.properties ?? {}).map(([name, property]) => {
|
|
3887
|
+
const isRequired = resolver.options.withImplicitRequiredProps || schema.required?.includes(name);
|
|
3888
|
+
const hasDefault = !isReferenceObject(property) && property.default !== void 0;
|
|
3889
|
+
const optional = isRequired || hasDefault ? "" : "?";
|
|
3890
|
+
const propertyType = renderSchemaType(property, resolver);
|
|
3891
|
+
const outputType = resolver.options.replaceOptionalWithNullish && optional && (isReferenceObject(property) || !property.nullable) ? `${propertyType} | null` : propertyType;
|
|
3892
|
+
return `${wrapWithQuotesIfNeeded(name)}${optional}: ${outputType}`;
|
|
3893
|
+
});
|
|
3894
|
+
if (schema.additionalProperties) {
|
|
3895
|
+
const valueType = typeof schema.additionalProperties === "object" ? renderSchemaType(schema.additionalProperties, resolver) : "unknown";
|
|
3896
|
+
properties.push(`[key: string]: ${valueType}`);
|
|
3897
|
+
}
|
|
3898
|
+
return addNullable(schema, `{ ${properties.join("; ")} }`);
|
|
3899
|
+
}
|
|
3900
|
+
const primitiveType = schema.type;
|
|
3901
|
+
return addNullable(schema, primitiveType === "string" ? "string" : primitiveType === "number" || primitiveType === "integer" ? "number" : primitiveType === "boolean" ? "boolean" : primitiveType === "null" ? "null" : "unknown");
|
|
3902
|
+
}
|
|
3903
|
+
function addNullable(schema, type) {
|
|
3904
|
+
return schema.nullable && type !== "null" ? `${type} | null` : type;
|
|
3905
|
+
}
|
|
3870
3906
|
function renderModelsProxy({ resolver, data, tag }) {
|
|
3871
3907
|
const commonZodSchemas = data.get(resolver.options.defaultTag)?.zodSchemas ?? {};
|
|
3872
3908
|
const schemaNames = getUsedSchemaNames({
|
package/dist/metro.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import "./generate.runner-
|
|
3
|
-
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-
|
|
1
|
+
import "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
|
|
2
|
+
import "./generate.runner-C1HrS_9G.mjs";
|
|
3
|
+
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-Co_bG00_.mjs";
|
|
4
4
|
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-wLs5vqw6.mjs";
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import path from "path";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as runGenerate } from "./generate.runner-
|
|
1
|
+
import { S as Profiler } from "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-C1HrS_9G.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/openapi-codegen.runner.ts
|
package/dist/sh.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
2
|
+
import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, a as getDataFromOpenAPIDoc, m as groupByType, n as getOutputFileName, u as getTagFileName, v as GenerateType } from "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-C1HrS_9G.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 "3.1.
|
|
42
|
+
return "3.1.1";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
package/dist/vite.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import "./generate.runner-
|
|
3
|
-
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-
|
|
1
|
+
import "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
|
|
2
|
+
import "./generate.runner-C1HrS_9G.mjs";
|
|
3
|
+
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-Co_bG00_.mjs";
|
|
4
4
|
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-wLs5vqw6.mjs";
|
|
5
5
|
import path from "path";
|
|
6
6
|
|
package/package.json
CHANGED