Skip to content

Commit

Permalink
[typescript-axios] Respect User Supplied Header Params (#20040)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoegel authored Nov 6, 2024
1 parent 57cfff1 commit 98cd9bd
Show file tree
Hide file tree
Showing 28 changed files with 3,370 additions and 115 deletions.
1 change: 1 addition & 0 deletions CI/circle_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ elif [ "$NODE_INDEX" = "3" ]; then
(cd samples/client/petstore/typescript-rxjs/builds/with-npm-version && mvn integration-test)
(cd samples/client/petstore/typescript-axios/builds/with-npm-version && mvn integration-test)
(cd samples/client/petstore/typescript-axios/tests/default && mvn integration-test)
(cd samples/client/petstore/typescript-axios/tests/with-complex-headers && mvn integration-test)
(cd samples/client/petstore/javascript-flowtyped && mvn integration-test)
(cd samples/client/petstore/javascript-es6 && mvn integration-test)
(cd samples/client/petstore/javascript-promise-es6 && mvn integration-test)
Expand Down
5 changes: 5 additions & 0 deletions bin/configs/typescript-axios-with-complex-headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ generatorName: typescript-axios
outputDir: samples/client/petstore/typescript-axios/builds/with-complex-headers
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-complex-headers.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-axios
additionalProperties:
npmVersion: 1.0.0
npmName: '@openapitools/typescript-axios-petstore'
npmRepository: https://skimdb.npmjs.com/registry
snapshot: false
Original file line number Diff line number Diff line change
Expand Up @@ -156,34 +156,6 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{/isArray}}
{{/queryParams}}
{{#headerParams}}
{{#isArray}}
if ({{paramName}}) {
{{#uniqueItems}}
let mapped = Array.from({{paramName}}).map(value => (<any>"{{{dataType}}}" !== "Set<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
{{^uniqueItems}}
let mapped = {{paramName}}.map(value => (<any>"{{{dataType}}}" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
localVarHeaderParameter['{{baseName}}'] = mapped.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
}
{{/isArray}}
{{^isArray}}
{{! `val == null` covers for both `null` and `undefined`}}
if ({{paramName}} != null) {
{{#isString}}
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
{{/isString}}
{{^isString}}
{{! isString is falsy also for $ref that defines a string or enum type}}
localVarHeaderParameter['{{baseName}}'] = typeof {{paramName}} === 'string'
? {{paramName}}
: JSON.stringify({{paramName}});
{{/isString}}
}
{{/isArray}}
{{/headerParams}}
{{#vendorExtensions}}
{{#formParams}}
{{#isArray}}
Expand Down Expand Up @@ -224,6 +196,33 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
{{/consumes.0}}
{{/bodyParam}}
{{#headerParams}}
{{#isArray}}
if ({{paramName}}) {
{{#uniqueItems}}
let mapped = Array.from({{paramName}}).map(value => (<any>"{{{dataType}}}" !== "Set<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
{{^uniqueItems}}
let mapped = {{paramName}}.map(value => (<any>"{{{dataType}}}" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
{{/uniqueItems}}
localVarHeaderParameter['{{baseName}}'] = mapped.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
}
{{/isArray}}
{{^isArray}}
{{! `val == null` covers for both `null` and `undefined`}}
if ({{paramName}} != null) {
{{#isString}}
localVarHeaderParameter['{{baseName}}'] = String({{paramName}});
{{/isString}}
{{^isString}}
{{! isString is falsy also for $ref that defines a string or enum type}}
localVarHeaderParameter['{{baseName}}'] = typeof {{paramName}} === 'string'
? {{paramName}}
: JSON.stringify({{paramName}});
{{/isString}}
}
{{/isArray}}
{{/headerParams}}
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions,{{#hasFormParams}}{{#multipartFormData}} ...(localVarFormParams as any).getHeaders?.(),{{/multipartFormData}}{{/hasFormParams}} ...options.headers};
Expand Down Expand Up @@ -465,4 +464,4 @@ export type {{operationIdCamelCase}}{{enumName}} = typeof {{operationIdCamelCase
{{/isEnum}}
{{/allParams}}
{{/operation}}
{{/operations}}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ paths:
schema:
type: integer
format: int64
- name: Content-Type
in: header
style: simple
description: Content type header parameter
required: false
schema:
type: string
responses:
'200':
description: successful operation
Expand Down
9 changes: 2 additions & 7 deletions samples/client/echo_api/typescript-axios/build/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1605,34 +1605,29 @@ export const HeaderApiAxiosParamCreator = function (configuration?: Configuratio
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



if (integerHeader != null) {
localVarHeaderParameter['integer_header'] = typeof integerHeader === 'string'
? integerHeader
: JSON.stringify(integerHeader);
}

if (booleanHeader != null) {
localVarHeaderParameter['boolean_header'] = typeof booleanHeader === 'string'
? booleanHeader
: JSON.stringify(booleanHeader);
}

if (stringHeader != null) {
localVarHeaderParameter['string_header'] = String(stringHeader);
}

if (enumNonrefStringHeader != null) {
localVarHeaderParameter['enum_nonref_string_header'] = String(enumNonrefStringHeader);
}

if (enumRefStringHeader != null) {
localVarHeaderParameter['enum_ref_string_header'] = typeof enumRefStringHeader === 'string'
? enumRefStringHeader
: JSON.stringify(enumRefStringHeader);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)



if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)



if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2484,15 +2484,6 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['enum_query_double'] = enumQueryDouble;
}

if (enumHeaderStringArray) {
let mapped = enumHeaderStringArray.map(value => (<any>"Array<'>' | '$'>" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
localVarHeaderParameter['enum_header_string_array'] = mapped.join(COLLECTION_FORMATS["csv"]);
}

if (enumHeaderString != null) {
localVarHeaderParameter['enum_header_string'] = String(enumHeaderString);
}

if (enumFormStringArray) {
localVarFormParams.set('enum_form_string_array', enumFormStringArray.join(COLLECTION_FORMATS.csv));
}
Expand All @@ -2505,6 +2496,13 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)

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

if (enumHeaderStringArray) {
let mapped = enumHeaderStringArray.map(value => (<any>"Array<'>' | '$'>" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
localVarHeaderParameter['enum_header_string_array'] = mapped.join(COLLECTION_FORMATS["csv"]);
}
if (enumHeaderString != null) {
localVarHeaderParameter['enum_header_string'] = String(enumHeaderString);
}
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down Expand Up @@ -2566,20 +2564,18 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['int64_group'] = int64Group;
}



if (requiredBooleanGroup != null) {
localVarHeaderParameter['required_boolean_group'] = typeof requiredBooleanGroup === 'string'
? requiredBooleanGroup
: JSON.stringify(requiredBooleanGroup);
}

if (booleanGroup != null) {
localVarHeaderParameter['boolean_group'] = typeof booleanGroup === 'string'
? booleanGroup
: JSON.stringify(booleanGroup);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down Expand Up @@ -3829,12 +3825,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)



if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.gitignore
.npmignore
README.md
api.ts
base.ts
common.ts
configuration.ts
git_push.sh
index.ts
package.json
tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## @openapitools/typescript-axios-petstore@1.0.0

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:

Environment
* Node.js
* Webpack
* Browserify

Language level
* ES5 - you must have a Promises/A+ library installed
* ES6

Module system
* CommonJS
* ES6 module system

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))

### Building

To build and compile the typescript sources to javascript use:
```
npm install
npm run build
```

### Publishing

First build the package then run `npm publish`

### Consuming

navigate to the folder of your consuming project and run one of the following commands.

_published:_

```
npm install @openapitools/[email protected] --save
```

_unPublished (not recommended):_

```
npm install PATH_TO_GENERATED_PACKAGE --save
```
Loading

0 comments on commit 98cd9bd

Please sign in to comment.