swagger-typescript-api 13.9.3 → 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.
@@ -169,7 +169,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
169
169
  //#endregion
170
170
  //#region package.json
171
171
  var name = "swagger-typescript-api";
172
- var version = "13.9.3";
172
+ var version = "13.10.0";
173
173
  var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
174
174
  //#endregion
175
175
  //#region src/constants.ts
@@ -263,6 +263,7 @@ const TsKeyword = {
263
263
  Date: "Date",
264
264
  Type: "type",
265
265
  Enum: "enum",
266
+ Const: "const",
266
267
  Interface: "interface",
267
268
  Array: "Array",
268
269
  Record: "Record",
@@ -282,7 +283,9 @@ var CodeGenConfig = class {
282
283
  generateRouteTypes = false;
283
284
  /** CLI flag */
284
285
  generateClient = true;
285
- /** CLI flag */
286
+ /** CLI flag. Controls enum output format: "enum" (default), "union" (T1 | T2 | TN), or "const" (as const object + type alias). */
287
+ enumStyle = "enum";
288
+ /** @deprecated Use enumStyle: "union" instead */
286
289
  generateUnionEnums = false;
287
290
  /** CLI flag */
288
291
  addReadonly = false;
@@ -653,6 +656,10 @@ var CodeGenConfig = class {
653
656
  update = (update) => {
654
657
  objectAssign(this, update);
655
658
  if (this.enumNamesAsValues) this.extractEnums = true;
659
+ if (this.generateUnionEnums) {
660
+ consola$1.warn("`generateUnionEnums` is deprecated. Use `enumStyle: \"union\"` instead.");
661
+ if (this.enumStyle === "enum") this.enumStyle = "union";
662
+ }
656
663
  };
657
664
  };
658
665
  //#endregion
@@ -767,7 +774,12 @@ var SchemaFormatters = class {
767
774
  }
768
775
  base = {
769
776
  [SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
770
- if (this.config.generateUnionEnums) return {
777
+ if (this.config.enumStyle === "const") return {
778
+ ...parsedSchema,
779
+ $content: parsedSchema.content,
780
+ content: parsedSchema.content.map(({ key, value }) => ` ${key}: ${value}`).join(",\n")
781
+ };
782
+ if (this.config.enumStyle === "union") return {
771
783
  ...parsedSchema,
772
784
  $content: parsedSchema.content,
773
785
  content: this.config.Ts.UnionType(parsedSchema.content.map(({ value }) => value))
@@ -1045,7 +1057,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
1045
1057
  const enumEntries = (parsedEnum.enum || []).map((key, index) => [key, index]);
1046
1058
  for (const [key, index] of enumEntries) {
1047
1059
  const enumContent = parsedEnum.content?.[index];
1048
- if (this.config.generateUnionEnums) {
1060
+ if (this.config.enumStyle === "union" || this.config.enumStyle === "const") {
1049
1061
  const literalValue = enumContent?.value ?? (key !== void 0 ? ts.StringValue(key) : void 0);
1050
1062
  if (literalValue !== void 0) mappingPropertySchemaEnumKeysMap[key] = literalValue;
1051
1063
  } else if (parsedEnum.typeName && enumContent?.key) mappingPropertySchemaEnumKeysMap[key] = ts.EnumUsageKey(parsedEnum.typeName, enumContent.key);
@@ -1206,7 +1218,7 @@ var EnumSchemaParser = class extends MonoSchemaParser {
1206
1218
  schemaType: SCHEMA_TYPES$1.ENUM,
1207
1219
  type: SCHEMA_TYPES$1.ENUM,
1208
1220
  keyType,
1209
- typeIdentifier: this.config.generateUnionEnums ? this.config.Ts.Keyword.Type : this.config.Ts.Keyword.Enum,
1221
+ typeIdentifier: this.config.enumStyle === "const" ? this.config.Ts.Keyword.Const : this.config.enumStyle === "union" ? this.config.Ts.Keyword.Type : this.config.Ts.Keyword.Enum,
1210
1222
  name: this.typeName,
1211
1223
  description: this.schemaFormatters.formatDescription(this.schema.description),
1212
1224
  content
@@ -2378,6 +2390,7 @@ var SchemaRoutes = class {
2378
2390
  security: hasSecurity,
2379
2391
  method,
2380
2392
  requestParams: requestParamsSchema,
2393
+ requestParamsOptional: requestParamsSchema?.typeData?.allFieldsAreOptional ?? false,
2381
2394
  payload: specificArgs.body,
2382
2395
  query: specificArgs.query,
2383
2396
  pathParams: specificArgs.pathParams,
@@ -3930,4 +3943,4 @@ async function generateApi(config) {
3930
3943
  //#endregion
3931
3944
  export { SCHEMA_TYPES as a, constants_exports as c, version as d, RequestContentKind as i, description as l, generateTemplates as n, CodeGenConfig as o, TemplatesGenConfig as r, HTTP_CLIENT as s, generateApi as t, name as u };
3932
3945
 
3933
- //# sourceMappingURL=src-D2qG03ZJ.mjs.map
3946
+ //# sourceMappingURL=src-djU9KRKm.mjs.map