swagger-typescript-api 13.9.2 → 13.10.0
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/cli.cjs +8 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +8 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-BY1ANJEv.cjs → src-B2z6JCvN.cjs} +24 -8
- package/dist/src-B2z6JCvN.cjs.map +1 -0
- package/dist/{src-DBX_Jv-1.mjs → src-djU9KRKm.mjs} +24 -8
- package/dist/src-djU9KRKm.mjs.map +1 -0
- package/package.json +3 -3
- package/templates/base/data-contracts.ejs +10 -0
- package/templates/base/enum-data-contract.ejs +6 -1
- package/templates/base/http-clients/axios-http-client.ejs +11 -0
- package/templates/base/http-clients/fetch-http-client.ejs +11 -0
- package/templates/default/procedure-call.ejs +2 -1
- package/templates/modular/procedure-call.ejs +2 -1
- package/dist/src-BY1ANJEv.cjs.map +0 -1
- package/dist/src-DBX_Jv-1.mjs.map +0 -1
|
@@ -208,7 +208,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
208
208
|
//#endregion
|
|
209
209
|
//#region package.json
|
|
210
210
|
var name = "swagger-typescript-api";
|
|
211
|
-
var version = "13.
|
|
211
|
+
var version = "13.10.0";
|
|
212
212
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
213
213
|
//#endregion
|
|
214
214
|
//#region src/constants.ts
|
|
@@ -302,6 +302,7 @@ const TsKeyword = {
|
|
|
302
302
|
Date: "Date",
|
|
303
303
|
Type: "type",
|
|
304
304
|
Enum: "enum",
|
|
305
|
+
Const: "const",
|
|
305
306
|
Interface: "interface",
|
|
306
307
|
Array: "Array",
|
|
307
308
|
Record: "Record",
|
|
@@ -321,7 +322,9 @@ var CodeGenConfig = class {
|
|
|
321
322
|
generateRouteTypes = false;
|
|
322
323
|
/** CLI flag */
|
|
323
324
|
generateClient = true;
|
|
324
|
-
/** CLI flag */
|
|
325
|
+
/** CLI flag. Controls enum output format: "enum" (default), "union" (T1 | T2 | TN), or "const" (as const object + type alias). */
|
|
326
|
+
enumStyle = "enum";
|
|
327
|
+
/** @deprecated Use enumStyle: "union" instead */
|
|
325
328
|
generateUnionEnums = false;
|
|
326
329
|
/** CLI flag */
|
|
327
330
|
addReadonly = false;
|
|
@@ -692,6 +695,10 @@ var CodeGenConfig = class {
|
|
|
692
695
|
update = (update) => {
|
|
693
696
|
objectAssign(this, update);
|
|
694
697
|
if (this.enumNamesAsValues) this.extractEnums = true;
|
|
698
|
+
if (this.generateUnionEnums) {
|
|
699
|
+
consola.consola.warn("`generateUnionEnums` is deprecated. Use `enumStyle: \"union\"` instead.");
|
|
700
|
+
if (this.enumStyle === "enum") this.enumStyle = "union";
|
|
701
|
+
}
|
|
695
702
|
};
|
|
696
703
|
};
|
|
697
704
|
//#endregion
|
|
@@ -806,7 +813,12 @@ var SchemaFormatters = class {
|
|
|
806
813
|
}
|
|
807
814
|
base = {
|
|
808
815
|
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
809
|
-
if (this.config.
|
|
816
|
+
if (this.config.enumStyle === "const") return {
|
|
817
|
+
...parsedSchema,
|
|
818
|
+
$content: parsedSchema.content,
|
|
819
|
+
content: parsedSchema.content.map(({ key, value }) => ` ${key}: ${value}`).join(",\n")
|
|
820
|
+
};
|
|
821
|
+
if (this.config.enumStyle === "union") return {
|
|
810
822
|
...parsedSchema,
|
|
811
823
|
$content: parsedSchema.content,
|
|
812
824
|
content: this.config.Ts.UnionType(parsedSchema.content.map(({ value }) => value))
|
|
@@ -1084,7 +1096,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1084
1096
|
const enumEntries = (parsedEnum.enum || []).map((key, index) => [key, index]);
|
|
1085
1097
|
for (const [key, index] of enumEntries) {
|
|
1086
1098
|
const enumContent = parsedEnum.content?.[index];
|
|
1087
|
-
if (this.config.
|
|
1099
|
+
if (this.config.enumStyle === "union" || this.config.enumStyle === "const") {
|
|
1088
1100
|
const literalValue = enumContent?.value ?? (key !== void 0 ? ts.StringValue(key) : void 0);
|
|
1089
1101
|
if (literalValue !== void 0) mappingPropertySchemaEnumKeysMap[key] = literalValue;
|
|
1090
1102
|
} else if (parsedEnum.typeName && enumContent?.key) mappingPropertySchemaEnumKeysMap[key] = ts.EnumUsageKey(parsedEnum.typeName, enumContent.key);
|
|
@@ -1245,7 +1257,7 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1245
1257
|
schemaType: SCHEMA_TYPES$1.ENUM,
|
|
1246
1258
|
type: SCHEMA_TYPES$1.ENUM,
|
|
1247
1259
|
keyType,
|
|
1248
|
-
typeIdentifier: this.config.
|
|
1260
|
+
typeIdentifier: this.config.enumStyle === "const" ? this.config.Ts.Keyword.Const : this.config.enumStyle === "union" ? this.config.Ts.Keyword.Type : this.config.Ts.Keyword.Enum,
|
|
1249
1261
|
name: this.typeName,
|
|
1250
1262
|
description: this.schemaFormatters.formatDescription(this.schema.description),
|
|
1251
1263
|
content
|
|
@@ -2417,6 +2429,7 @@ var SchemaRoutes = class {
|
|
|
2417
2429
|
security: hasSecurity,
|
|
2418
2430
|
method,
|
|
2419
2431
|
requestParams: requestParamsSchema,
|
|
2432
|
+
requestParamsOptional: requestParamsSchema?.typeData?.allFieldsAreOptional ?? false,
|
|
2420
2433
|
payload: specificArgs.body,
|
|
2421
2434
|
query: specificArgs.query,
|
|
2422
2435
|
pathParams: specificArgs.pathParams,
|
|
@@ -3094,7 +3107,7 @@ var SwaggerSchemaResolver = class {
|
|
|
3094
3107
|
return await ResolvedSwaggerSchema.create(this.config, swaggerSchemas.usageSchema, swaggerSchemas.originalSchema, originalProducesByRoute);
|
|
3095
3108
|
}
|
|
3096
3109
|
convertSwaggerObject(swaggerSchema, converterOptions) {
|
|
3097
|
-
return new Promise((resolve) => {
|
|
3110
|
+
return new Promise((resolve, reject) => {
|
|
3098
3111
|
const result = structuredClone(swaggerSchema);
|
|
3099
3112
|
const originalSchemaForProduces = structuredClone(swaggerSchema);
|
|
3100
3113
|
result.info = (0, es_toolkit.merge)({
|
|
@@ -3111,7 +3124,10 @@ var SwaggerSchemaResolver = class {
|
|
|
3111
3124
|
rbname: "requestBodyName"
|
|
3112
3125
|
}, (err, options) => {
|
|
3113
3126
|
const parsedSwaggerSchema = (0, es_toolkit_compat.get)(err, "options.openapi") ?? (0, es_toolkit_compat.get)(options, "openapi");
|
|
3114
|
-
if (!parsedSwaggerSchema && err)
|
|
3127
|
+
if (!parsedSwaggerSchema && err) {
|
|
3128
|
+
reject(err);
|
|
3129
|
+
return;
|
|
3130
|
+
}
|
|
3115
3131
|
this.config.update({ convertedFromSwagger2: true });
|
|
3116
3132
|
resolve({
|
|
3117
3133
|
usageSchema: parsedSwaggerSchema,
|
|
@@ -4037,4 +4053,4 @@ Object.defineProperty(exports, "version", {
|
|
|
4037
4053
|
}
|
|
4038
4054
|
});
|
|
4039
4055
|
|
|
4040
|
-
//# sourceMappingURL=src-
|
|
4056
|
+
//# sourceMappingURL=src-B2z6JCvN.cjs.map
|