swagger-typescript-api 13.12.5 → 13.13.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.
@@ -171,7 +171,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
171
171
  //#endregion
172
172
  //#region package.json
173
173
  var name = "swagger-typescript-api";
174
- var version = "13.12.5";
174
+ var version = "13.13.0";
175
175
  var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
176
176
  //#endregion
177
177
  //#region src/constants.ts
@@ -296,6 +296,10 @@ var CodeGenConfig = class {
296
296
  enumStyle = "enum";
297
297
  /** @deprecated Use enumStyle: "union" instead */
298
298
  generateUnionEnums = false;
299
+ /** CLI flag. Extension appended to generated relative imports: "" (default), ".js", or ".ts". */
300
+ importFileExtension = "";
301
+ /** CLI flag. Emit `import type` / inline `type` for type-only imports. */
302
+ typeOnlyImports = false;
299
303
  /** CLI flag */
300
304
  addReadonly = false;
301
305
  enumNamesAsValues = false;
@@ -384,6 +388,7 @@ var CodeGenConfig = class {
384
388
  enumKeyPrefix = "";
385
389
  enumKeySuffix = "";
386
390
  patch = false;
391
+ disableExternalSchemas = false;
387
392
  preferExistingSchemaNamesForExternalRefs = false;
388
393
  componentTypeNameResolver;
389
394
  /** name of the main exported class */
@@ -665,6 +670,12 @@ var CodeGenConfig = class {
665
670
  }
666
671
  update = (update) => {
667
672
  objectAssign(this, update);
673
+ this.importFileExtension ??= "";
674
+ if (![
675
+ "",
676
+ ".js",
677
+ ".ts"
678
+ ].includes(this.importFileExtension)) throw new Error(`Invalid \`importFileExtension\` value "${this.importFileExtension}". Expected "", ".js", or ".ts".`);
668
679
  if (this.enumNamesAsValues) this.extractEnums = true;
669
680
  if (this.generateUnionEnums) {
670
681
  consola$1.warn("`generateUnionEnums` is deprecated. Use `enumStyle: \"union\"` instead.");
@@ -827,6 +838,7 @@ var SchemaComponentsMap = class {
827
838
  if (localFound != null) return localFound;
828
839
  const { resolvedSwaggerSchema } = this.config;
829
840
  if (resolvedSwaggerSchema.isLocalRef($ref)) return null;
841
+ if (this.config.disableExternalSchemas) return null;
830
842
  const foundByRef = resolvedSwaggerSchema.getRef($ref);
831
843
  const refDetails = resolvedSwaggerSchema.getRefDetails($ref);
832
844
  if (foundByRef != null) {
@@ -1010,10 +1022,11 @@ var MonoSchemaParser = class {
1010
1022
  var ArraySchemaParser = class extends MonoSchemaParser {
1011
1023
  parse() {
1012
1024
  let contentType;
1013
- const { type, description, items } = this.schema || {};
1014
- if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) {
1025
+ const { type, description, items, prefixItems } = this.schema || {};
1026
+ const tupleItems = Array.isArray(prefixItems) ? prefixItems : Array.isArray(items) ? items : null;
1027
+ if (tupleItems && type === SCHEMA_TYPES$1.ARRAY) {
1015
1028
  const tupleContent = [];
1016
- for (const item of items) tupleContent.push(this.schemaParserFabric.createSchemaParser({
1029
+ for (const item of tupleItems) tupleContent.push(this.schemaParserFabric.createSchemaParser({
1017
1030
  schema: item,
1018
1031
  schemaPath: this.schemaPath
1019
1032
  }).getInlineParseContent());
@@ -1046,6 +1059,7 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
1046
1059
  const complexSchemaItems = Array.isArray(this.schema[complexType]) ? this.schema[complexType] : [];
1047
1060
  const simpleSchema = omit(this.schema, Object.keys(this.schemaParser._complexSchemaParsers));
1048
1061
  const complexSchemaContent = this.schemaParser._complexSchemaParsers[complexType](this.schema);
1062
+ const shouldParseSimpleSchema = this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES$1.OBJECT || this.schemaUtils.isRefSchema(simpleSchema);
1049
1063
  return {
1050
1064
  ...typeof this.schema === "object" ? this.schema : {},
1051
1065
  $schemaPath: this.schemaPath.slice(),
@@ -1055,10 +1069,10 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
1055
1069
  typeIdentifier: this.config.Ts.Keyword.Type,
1056
1070
  name: this.typeName,
1057
1071
  description: this.schemaFormatters.formatDescription(this.schema.description || compact(complexSchemaItems.map((item) => item.description))[0] || ""),
1058
- content: this.config.Ts.IntersectionType(compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES$1.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
1072
+ content: this.config.Ts.IntersectionType(this.schemaUtils.filterSchemaContents(compact([complexSchemaContent, shouldParseSimpleSchema && this.schemaParserFabric.createSchemaParser({
1059
1073
  schema: simpleSchema,
1060
1074
  schemaPath: this.schemaPath
1061
- }).getInlineParseContent())])) || this.config.Ts.Keyword.Any
1075
+ }).getInlineParseContent()]), (content) => content !== this.config.Ts.Keyword.Any).map((content) => this.config.Ts.ExpressionGroup(content))) || this.config.Ts.Keyword.Any
1062
1076
  };
1063
1077
  }
1064
1078
  };
@@ -1570,6 +1584,7 @@ var SchemaParser = class {
1570
1584
  if (!this.schema.$parsed) {
1571
1585
  if (!this.typeName && this.schemaUtils.isRefSchema(this.schema)) this.typeName = this.schemaUtils.getSchemaType(this.schema);
1572
1586
  if (this.schema.items && !Array.isArray(this.schema.items) && !this.schema.type) this.schema.type = SCHEMA_TYPES$1.ARRAY;
1587
+ if (this.schema.additionalProperties && !this.schema.type) this.schema.type = SCHEMA_TYPES$1.OBJECT;
1573
1588
  if (Array.isArray(this.schema.enum) && this.schema.enum.length === 1 && this.schema.enum[0] == null) {
1574
1589
  consola$1.debug("invalid enum schema", this.schema);
1575
1590
  this.schema = { type: this.config.Ts.Keyword.Null };
@@ -1922,10 +1937,12 @@ var SchemaRoutes = class {
1922
1937
  })]);
1923
1938
  }
1924
1939
  /**
1925
- * `extractResponseBody` / `extractResponseError` call `createParsedComponent`, which
1926
- * registers `#/components/schemas/<typeName>`. If that key already exists (e.g.
1927
- * `MergeFluffyData` in definitions), the map entry would be overwritten unless we
1928
- * pick another name via `resolveTypeName` after reserving the colliding one.
1940
+ * `extractResponseBody` / `extractResponseError` / `extractRequestParams` call
1941
+ * `createParsedComponent`, which registers `#/components/schemas/<typeName>`. If that
1942
+ * key already exists (e.g. `MergeFluffyData` in definitions, or a request-body model
1943
+ * named `GetOrderParams` next to a `getOrder` operation), the map entry would be
1944
+ * overwritten unless we pick another name via `resolveTypeName` after reserving the
1945
+ * colliding one.
1929
1946
  *
1930
1947
  * `getComponents` may be missing in narrow unit tests that pass a stub map.
1931
1948
  *
@@ -2289,7 +2306,7 @@ var SchemaRoutes = class {
2289
2306
  const fixedSchema = this.config.hooks.onCreateRequestParams(schema);
2290
2307
  if (fixedSchema) return fixedSchema;
2291
2308
  if (extractRequestParams) {
2292
- const generatedTypeName = this.schemaUtils.resolveTypeName(routeName.usage, {
2309
+ const generatedTypeName = this.extractTypeNameWithoutSchemaKeyCollision(routeName.usage, {
2293
2310
  suffixes: this.config.extractingOptions.requestParamsSuffix,
2294
2311
  resolver: this.config.extractingOptions.requestParamsNameResolver
2295
2312
  });
@@ -4225,4 +4242,4 @@ async function generateApi(config) {
4225
4242
  //#endregion
4226
4243
  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 };
4227
4244
 
4228
- //# sourceMappingURL=src-BTi82JcX.mjs.map
4245
+ //# sourceMappingURL=src-DXotSN2p.mjs.map