Skip to content

Commit 98cd9bd

Browse files
authored
[typescript-axios] Respect User Supplied Header Params (#20040)
1 parent 57cfff1 commit 98cd9bd

File tree

28 files changed

+3370
-115
lines changed

28 files changed

+3370
-115
lines changed

CI/circle_parallel.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ elif [ "$NODE_INDEX" = "3" ]; then
100100
(cd samples/client/petstore/typescript-rxjs/builds/with-npm-version && mvn integration-test)
101101
(cd samples/client/petstore/typescript-axios/builds/with-npm-version && mvn integration-test)
102102
(cd samples/client/petstore/typescript-axios/tests/default && mvn integration-test)
103+
(cd samples/client/petstore/typescript-axios/tests/with-complex-headers && mvn integration-test)
103104
(cd samples/client/petstore/javascript-flowtyped && mvn integration-test)
104105
(cd samples/client/petstore/javascript-es6 && mvn integration-test)
105106
(cd samples/client/petstore/javascript-promise-es6 && mvn integration-test)

bin/configs/typescript-axios-with-complex-headers.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ generatorName: typescript-axios
22
outputDir: samples/client/petstore/typescript-axios/builds/with-complex-headers
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-complex-headers.yaml
44
templateDir: modules/openapi-generator/src/main/resources/typescript-axios
5+
additionalProperties:
6+
npmVersion: 1.0.0
7+
npmName: '@openapitools/typescript-axios-petstore'
8+
npmRepository: https://skimdb.npmjs.com/registry
9+
snapshot: false

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -156,34 +156,6 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
156156
{{/isArray}}
157157
158158
{{/queryParams}}
159-
{{#headerParams}}
160-
{{#isArray}}
161-
if ({{paramName}}) {
162-
{{#uniqueItems}}
163-
let mapped = Array.from({{paramName}}).map(value => (<any>"{{{dataType}}}" !== "Set<string>") ? JSON.stringify(value) : (value || ""));
164-
{{/uniqueItems}}
165-
{{^uniqueItems}}
166-
let mapped = {{paramName}}.map(value => (<any>"{{{dataType}}}" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
167-
{{/uniqueItems}}
168-
localVarHeaderParameter['{{baseName}}'] = mapped.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
169-
}
170-
{{/isArray}}
171-
{{^isArray}}
172-
{{! `val == null` covers for both `null` and `undefined`}}
173-
if ({{paramName}} != null) {
174-
{{#isString}}
175-
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
176-
{{/isString}}
177-
{{^isString}}
178-
{{! isString is falsy also for $ref that defines a string or enum type}}
179-
localVarHeaderParameter['{{baseName}}'] = typeof {{paramName}} === 'string'
180-
? {{paramName}}
181-
: JSON.stringify({{paramName}});
182-
{{/isString}}
183-
}
184-
{{/isArray}}
185-
186-
{{/headerParams}}
187159
{{#vendorExtensions}}
188160
{{#formParams}}
189161
{{#isArray}}
@@ -224,6 +196,33 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
224196
{{/consumes.0}}
225197
226198
{{/bodyParam}}
199+
{{#headerParams}}
200+
{{#isArray}}
201+
if ({{paramName}}) {
202+
{{#uniqueItems}}
203+
let mapped = Array.from({{paramName}}).map(value => (<any>"{{{dataType}}}" !== "Set<string>") ? JSON.stringify(value) : (value || ""));
204+
{{/uniqueItems}}
205+
{{^uniqueItems}}
206+
let mapped = {{paramName}}.map(value => (<any>"{{{dataType}}}" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
207+
{{/uniqueItems}}
208+
localVarHeaderParameter['{{baseName}}'] = mapped.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
209+
}
210+
{{/isArray}}
211+
{{^isArray}}
212+
{{! `val == null` covers for both `null` and `undefined`}}
213+
if ({{paramName}} != null) {
214+
{{#isString}}
215+
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
216+
{{/isString}}
217+
{{^isString}}
218+
{{! isString is falsy also for $ref that defines a string or enum type}}
219+
localVarHeaderParameter['{{baseName}}'] = typeof {{paramName}} === 'string'
220+
? {{paramName}}
221+
: JSON.stringify({{paramName}});
222+
{{/isString}}
223+
}
224+
{{/isArray}}
225+
{{/headerParams}}
227226
setSearchParams(localVarUrlObj, localVarQueryParameter);
228227
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
229228
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions,{{#hasFormParams}}{{#multipartFormData}} ...(localVarFormParams as any).getHeaders?.(),{{/multipartFormData}}{{/hasFormParams}} ...options.headers};
@@ -465,4 +464,4 @@ export type {{operationIdCamelCase}}{{enumName}} = typeof {{operationIdCamelCase
465464
{{/isEnum}}
466465
{{/allParams}}
467466
{{/operation}}
468-
{{/operations}}
467+
{{/operations}}

modules/openapi-generator/src/test/resources/3_0/petstore-with-complex-headers.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ paths:
257257
schema:
258258
type: integer
259259
format: int64
260+
- name: Content-Type
261+
in: header
262+
style: simple
263+
description: Content type header parameter
264+
required: false
265+
schema:
266+
type: string
260267
responses:
261268
'200':
262269
description: successful operation

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,34 +1605,29 @@ export const HeaderApiAxiosParamCreator = function (configuration?: Configuratio
16051605
const localVarHeaderParameter = {} as any;
16061606
const localVarQueryParameter = {} as any;
16071607

1608+
1609+
16081610
if (integerHeader != null) {
16091611
localVarHeaderParameter['integer_header'] = typeof integerHeader === 'string'
16101612
? integerHeader
16111613
: JSON.stringify(integerHeader);
16121614
}
1613-
16141615
if (booleanHeader != null) {
16151616
localVarHeaderParameter['boolean_header'] = typeof booleanHeader === 'string'
16161617
? booleanHeader
16171618
: JSON.stringify(booleanHeader);
16181619
}
1619-
16201620
if (stringHeader != null) {
16211621
localVarHeaderParameter['string_header'] = String(stringHeader);
16221622
}
1623-
16241623
if (enumNonrefStringHeader != null) {
16251624
localVarHeaderParameter['enum_nonref_string_header'] = String(enumNonrefStringHeader);
16261625
}
1627-
16281626
if (enumRefStringHeader != null) {
16291627
localVarHeaderParameter['enum_ref_string_header'] = typeof enumRefStringHeader === 'string'
16301628
? enumRefStringHeader
16311629
: JSON.stringify(enumRefStringHeader);
16321630
}
1633-
1634-
1635-
16361631
setSearchParams(localVarUrlObj, localVarQueryParameter);
16371632
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
16381633
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
320320
// oauth required
321321
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
322322

323+
324+
323325
if (apiKey != null) {
324326
localVarHeaderParameter['api_key'] = String(apiKey);
325327
}
326-
327-
328-
329328
setSearchParams(localVarUrlObj, localVarQueryParameter);
330329
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
331330
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
320320
// oauth required
321321
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
322322

323+
324+
323325
if (apiKey != null) {
324326
localVarHeaderParameter['api_key'] = String(apiKey);
325327
}
326-
327-
328-
329328
setSearchParams(localVarUrlObj, localVarQueryParameter);
330329
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
331330
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,15 +2484,6 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
24842484
localVarQueryParameter['enum_query_double'] = enumQueryDouble;
24852485
}
24862486

2487-
if (enumHeaderStringArray) {
2488-
let mapped = enumHeaderStringArray.map(value => (<any>"Array<'>' | '$'>" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
2489-
localVarHeaderParameter['enum_header_string_array'] = mapped.join(COLLECTION_FORMATS["csv"]);
2490-
}
2491-
2492-
if (enumHeaderString != null) {
2493-
localVarHeaderParameter['enum_header_string'] = String(enumHeaderString);
2494-
}
2495-
24962487
if (enumFormStringArray) {
24972488
localVarFormParams.set('enum_form_string_array', enumFormStringArray.join(COLLECTION_FORMATS.csv));
24982489
}
@@ -2505,6 +2496,13 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
25052496

25062497
localVarHeaderParameter['Content-Type'] = 'application/x-www-form-urlencoded';
25072498

2499+
if (enumHeaderStringArray) {
2500+
let mapped = enumHeaderStringArray.map(value => (<any>"Array<'>' | '$'>" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
2501+
localVarHeaderParameter['enum_header_string_array'] = mapped.join(COLLECTION_FORMATS["csv"]);
2502+
}
2503+
if (enumHeaderString != null) {
2504+
localVarHeaderParameter['enum_header_string'] = String(enumHeaderString);
2505+
}
25082506
setSearchParams(localVarUrlObj, localVarQueryParameter);
25092507
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
25102508
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
@@ -2566,20 +2564,18 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
25662564
localVarQueryParameter['int64_group'] = int64Group;
25672565
}
25682566

2567+
2568+
25692569
if (requiredBooleanGroup != null) {
25702570
localVarHeaderParameter['required_boolean_group'] = typeof requiredBooleanGroup === 'string'
25712571
? requiredBooleanGroup
25722572
: JSON.stringify(requiredBooleanGroup);
25732573
}
2574-
25752574
if (booleanGroup != null) {
25762575
localVarHeaderParameter['boolean_group'] = typeof booleanGroup === 'string'
25772576
? booleanGroup
25782577
: JSON.stringify(booleanGroup);
25792578
}
2580-
2581-
2582-
25832579
setSearchParams(localVarUrlObj, localVarQueryParameter);
25842580
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
25852581
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
@@ -3829,12 +3825,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
38293825
// oauth required
38303826
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
38313827

3828+
3829+
38323830
if (apiKey != null) {
38333831
localVarHeaderParameter['api_key'] = String(apiKey);
38343832
}
3835-
3836-
3837-
38383833
setSearchParams(localVarUrlObj, localVarQueryParameter);
38393834
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
38403835
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
.gitignore
22
.npmignore
3+
README.md
34
api.ts
45
base.ts
56
common.ts
67
configuration.ts
78
git_push.sh
89
index.ts
10+
package.json
11+
tsconfig.json
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## @openapitools/typescript-axios-petstore@1.0.0
2+
3+
This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
4+
5+
Environment
6+
* Node.js
7+
* Webpack
8+
* Browserify
9+
10+
Language level
11+
* ES5 - you must have a Promises/A+ library installed
12+
* ES6
13+
14+
Module system
15+
* CommonJS
16+
* ES6 module system
17+
18+
It can be used in both TypeScript and JavaScript. In TypeScript, the definition will be automatically resolved via `package.json`. ([Reference](https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html))
19+
20+
### Building
21+
22+
To build and compile the typescript sources to javascript use:
23+
```
24+
npm install
25+
npm run build
26+
```
27+
28+
### Publishing
29+
30+
First build the package then run `npm publish`
31+
32+
### Consuming
33+
34+
navigate to the folder of your consuming project and run one of the following commands.
35+
36+
_published:_
37+
38+
```
39+
npm install @openapitools/typescript-axios-petstore@1.0.0 --save
40+
```
41+
42+
_unPublished (not recommended):_
43+
44+
```
45+
npm install PATH_TO_GENERATED_PACKAGE --save
46+
```

0 commit comments

Comments
 (0)