Skip to content

Commit 5677f5b

Browse files
authored
Introduce option 'importFileExtension' to typescript-axios (#21343) (#21344)
1 parent 05e672d commit 5677f5b

File tree

24 files changed

+96
-83
lines changed

24 files changed

+96
-83
lines changed

docs/generators/typescript-axios.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2727
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase|
2828
|enumPropertyNamingReplaceSpecialChar|Set to true to replace '-' and '+' symbols with 'minus_' and 'plus_' in enum of type string| |false|
2929
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
30+
|importFileExtension|File extension to use with relative imports. Set it to '.js' or '.mjs' when using [ESM](https://nodejs.org/api/esm.html).| ||
3031
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
3132
|licenseName|The name of the license| |Unlicense|
3233
|modelPackage|package for generated models| |null|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
4747
public static final String WITH_NODE_IMPORTS = "withNodeImports";
4848
public static final String STRING_ENUMS = "stringEnums";
4949
public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values.";
50+
public static final String IMPORT_FILE_EXTENSION_SWITCH = "importFileExtension";
51+
public static final String IMPORT_FILE_EXTENSION_SWITCH_DESC = "File extension to use with relative imports. Set it to '.js' or '.mjs' when using [ESM](https://nodejs.org/api/esm.html).";
5052
public static final String USE_SQUARE_BRACKETS_IN_ARRAY_NAMES = "useSquareBracketsInArrayNames";
5153
public static final String AXIOS_VERSION = "axiosVersion";
5254
public static final String DEFAULT_AXIOS_VERSION = "^1.6.1";
5355

5456
@Getter @Setter
5557
protected String npmRepository = null;
5658
protected Boolean stringEnums = false;
59+
protected String importFileExtension = "";
5760

5861
@Getter @Setter
5962
protected String axiosVersion = DEFAULT_AXIOS_VERSION;
@@ -88,6 +91,7 @@ public TypeScriptAxiosClientCodegen() {
8891
this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
8992
this.cliOptions.add(new CliOption(WITH_NODE_IMPORTS, "Setting this property to true adds imports for NodeJS", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
9093
this.cliOptions.add(new CliOption(STRING_ENUMS, STRING_ENUMS_DESC).defaultValue(String.valueOf(this.stringEnums)));
94+
this.cliOptions.add(new CliOption(IMPORT_FILE_EXTENSION_SWITCH, IMPORT_FILE_EXTENSION_SWITCH_DESC, SchemaTypeUtil.STRING_TYPE).defaultValue(this.importFileExtension));
9195
this.cliOptions.add(new CliOption(USE_SQUARE_BRACKETS_IN_ARRAY_NAMES, "Setting this property to true will add brackets to array attribute names, e.g. my_values[].", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
9296
this.cliOptions.add(new CliOption(AXIOS_VERSION, "Use this property to override the axios version in package.json").defaultValue(DEFAULT_AXIOS_VERSION));
9397
// Templates have no mapping between formatted property names and original base names so use only "original" and remove this option
@@ -162,6 +166,14 @@ public void processOpts() {
162166
additionalProperties.put("stringEnums", this.stringEnums);
163167
}
164168

169+
if (additionalProperties.containsKey(IMPORT_FILE_EXTENSION_SWITCH)) {
170+
this.importFileExtension = additionalProperties.get(IMPORT_FILE_EXTENSION_SWITCH).toString();
171+
if (!this.importFileExtension.isEmpty() && !this.importFileExtension.startsWith(".")) {
172+
this.importFileExtension = "." + this.importFileExtension;
173+
}
174+
additionalProperties.put("importFileExtension", this.importFileExtension);
175+
}
176+
165177
if (additionalProperties.containsKey(NPM_NAME)) {
166178
addNpmPackageGeneration();
167179
}

modules/openapi-generator/src/main/resources/typescript-axios/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{>licenseInfo}}
44

55
{{^withSeparateModelsAndApi}}
6-
import type { Configuration } from './configuration';
6+
import type { Configuration } from './configuration{{importFileExtension}}';
77
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
88
import globalAxios from 'axios';
99
{{#withNodeImports}}
@@ -17,9 +17,9 @@ import FormData from 'form-data'
1717
// Some imports not used depending on template conditions
1818
// @ts-ignore
1919
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
20-
import type { RequestArgs } from './base';
20+
import type { RequestArgs } from './base{{importFileExtension}}';
2121
// @ts-ignore
22-
import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerMap } from './base';
22+
import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerMap } from './base{{importFileExtension}}';
2323

2424
{{#models}}
2525
{{#model}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{^isEnum}}{{^oneOf}}{{>modelGeneric}}{{/oneOf}}{{/isEnum}}{{/model}}
@@ -28,6 +28,6 @@ import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerM
2828
{{>apiInner}}
2929
{{/apis}}{{/apiInfo}}
3030
{{/withSeparateModelsAndApi}}{{#withSeparateModelsAndApi}}
31-
{{#apiInfo}}{{#apis}}{{#operations}}export * from './{{tsApiPackage}}/{{classFilename}}';
31+
{{#apiInfo}}{{#apis}}{{#operations}}export * from './{{tsApiPackage}}/{{classFilename}}{{importFileExtension}}';
3232
{{/operations}}{{/apis}}{{/apiInfo}}
3333
{{/withSeparateModelsAndApi}}

modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable */
44
{{>licenseInfo}}
55

6-
import type { Configuration } from '{{apiRelativeToRoot}}configuration';
6+
import type { Configuration } from '{{apiRelativeToRoot}}configuration{{importFileExtension}}';
77
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
88
import globalAxios from 'axios';
99
{{#withNodeImports}}
@@ -16,12 +16,12 @@ import FormData from 'form-data'
1616
{{/withNodeImports}}
1717
// Some imports not used depending on template conditions
1818
// @ts-ignore
19-
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '{{apiRelativeToRoot}}common';
19+
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '{{apiRelativeToRoot}}common{{importFileExtension}}';
2020
// @ts-ignore
21-
import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '{{apiRelativeToRoot}}base';
21+
import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '{{apiRelativeToRoot}}base{{importFileExtension}}';
2222
{{#imports}}
2323
// @ts-ignore
24-
import type { {{classname}} } from '{{apiRelativeToRoot}}{{tsModelPackage}}';
24+
import type { {{classname}} } from '{{apiRelativeToRoot}}{{tsModelPackage}}{{importFileExtension}}';
2525
{{/imports}}
2626
{{/withSeparateModelsAndApi}}
2727
{{^withSeparateModelsAndApi}}

modules/openapi-generator/src/main/resources/typescript-axios/baseApi.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable */
33
{{>licenseInfo}}
44

5-
import type { Configuration } from './configuration';
5+
import type { Configuration } from './configuration{{importFileExtension}}';
66
// Some imports not used depending on template conditions
77
// @ts-ignore
88
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';

modules/openapi-generator/src/main/resources/typescript-axios/common.mustache

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/* eslint-disable */
33
{{>licenseInfo}}
44

5-
import type { Configuration } from "./configuration";
6-
import type { RequestArgs } from "./base";
5+
import type { Configuration } from "./configuration{{importFileExtension}}";
6+
import type { RequestArgs } from "./base{{importFileExtension}}";
77
import type { AxiosInstance, AxiosResponse } from 'axios';
8-
import { RequiredError } from "./base";
8+
import { RequiredError } from "./base{{importFileExtension}}";
99
{{#withNodeImports}}
1010
import { URL, URLSearchParams } from 'url';
1111
{{/withNodeImports}}
@@ -81,17 +81,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8181
if (typeof parameter === "object") {
8282
if (Array.isArray(parameter)) {
8383
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
84-
}
84+
}
8585
else {
86-
Object.keys(parameter).forEach(currentKey =>
86+
Object.keys(parameter).forEach(currentKey =>
8787
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
8888
);
8989
}
90-
}
90+
}
9191
else {
9292
if (urlSearchParams.has(key)) {
9393
urlSearchParams.append(key, parameter);
94-
}
94+
}
9595
else {
9696
urlSearchParams.set(key, parameter);
9797
}

modules/openapi-generator/src/main/resources/typescript-axios/index.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
/* eslint-disable */
33
{{>licenseInfo}}
44

5-
export * from "./api";
6-
export * from "./configuration";
7-
{{#withSeparateModelsAndApi}}export * from "./{{tsModelPackage}}";{{/withSeparateModelsAndApi}}
5+
export * from "./api{{importFileExtension}}";
6+
export * from "./configuration{{importFileExtension}}";
7+
{{#withSeparateModelsAndApi}}export * from "./{{tsModelPackage}}{{importFileExtension}}";{{/withSeparateModelsAndApi}}

modules/openapi-generator/src/main/resources/typescript-axios/model.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
{{#withSeparateModelsAndApi}}{{#hasAllOf}}{{#allOf}}
55
// May contain unused imports in some cases
66
// @ts-ignore
7-
import type { {{class}} } from './{{filename}}';{{/allOf}}{{/hasAllOf}}{{#hasOneOf}}{{#oneOf}}
7+
import type { {{class}} } from './{{filename}}{{importFileExtension}}';{{/allOf}}{{/hasAllOf}}{{#hasOneOf}}{{#oneOf}}
88
// May contain unused imports in some cases
99
// @ts-ignore
10-
import type { {{class}} } from './{{filename}}';{{/oneOf}}{{/hasOneOf}}{{^hasAllOf}}{{^hasOneOf}}{{#imports}}
10+
import type { {{class}} } from './{{filename}}{{importFileExtension}}';{{/oneOf}}{{/hasOneOf}}{{^hasAllOf}}{{^hasOneOf}}{{#imports}}
1111
// May contain unused imports in some cases
1212
// @ts-ignore
13-
import type { {{class}} } from './{{filename}}';{{/imports}}{{/hasOneOf}}{{/hasAllOf}}{{/withSeparateModelsAndApi}}
13+
import type { {{class}} } from './{{filename}}{{importFileExtension}}';{{/imports}}{{/hasOneOf}}{{/hasAllOf}}{{/withSeparateModelsAndApi}}
1414
{{#models}}{{#model}}
1515
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{#allOf}}{{#-first}}{{>modelAllOf}}{{/-first}}{{/allOf}}{{^isEnum}}{{^oneOf}}{{^allOf}}{{>modelGeneric}}{{/allOf}}{{/oneOf}}{{/isEnum}}
1616
{{/model}}{{/models}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{{#models}}{{#model}}export * from './{{classFilename}}';{{/model}}
1+
{{#models}}{{#model}}export * from './{{classFilename}}{{importFileExtension}}';{{/model}}
22
{{/models}}

samples/client/echo_api/typescript-axios/build/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/others/typescript-axios/with-separate-models-and-api-inheritance/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/composed-schemas/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/default/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/es6-target/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/test-petstore/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/with-complex-headers/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/with-fake-endpoints-models-for-testing-with-http-signature/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/with-interfaces-and-with-single-request-param/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

samples/client/petstore/typescript-axios/builds/with-interfaces/common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: an
8989
if (typeof parameter === "object") {
9090
if (Array.isArray(parameter)) {
9191
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92-
}
92+
}
9393
else {
94-
Object.keys(parameter).forEach(currentKey =>
94+
Object.keys(parameter).forEach(currentKey =>
9595
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
9696
);
9797
}
98-
}
98+
}
9999
else {
100100
if (urlSearchParams.has(key)) {
101101
urlSearchParams.append(key, parameter);
102-
}
102+
}
103103
else {
104104
urlSearchParams.set(key, parameter);
105105
}

0 commit comments

Comments
 (0)