[typescript-axios] Respect User Supplied Header Params (#20040)

This commit is contained in:
Cameron Koegel 2024-11-06 12:01:59 -05:00 committed by GitHub
parent 57cfff1950
commit 98cd9bd803
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 3370 additions and 115 deletions

View File

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

View File

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

View File

@ -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}}
@ -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};

View File

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

View File

@ -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};

View File

@ -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};

View File

@ -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};

View File

@ -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));
}
@ -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};
@ -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};
@ -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};

View File

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

View File

@ -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/typescript-axios-petstore@1.0.0 --save
```
_unPublished (not recommended):_
```
npm install PATH_TO_GENERATED_PACKAGE --save
```

View File

@ -295,27 +295,24 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
// oauth required
await setOAuthToObject(localVarHeaderParameter, "petstore_auth", ["write:pets", "read:pets"], configuration)
localVarHeaderParameter['Content-Type'] = 'application/json';
if (header1 != null) {
localVarHeaderParameter['header1'] = typeof header1 === 'string'
? header1
: JSON.stringify(header1);
}
if (header2) {
let mapped = header2.map(value => (<any>"Array<Pet>" !== "Array<string>") ? JSON.stringify(value) : (value || ""));
localVarHeaderParameter['header2'] = mapped.join(COLLECTION_FORMATS["csv"]);
}
if (accept != null) {
localVarHeaderParameter['Accept'] = typeof accept === 'string'
? accept
: JSON.stringify(accept);
}
localVarHeaderParameter['Content-Type'] = 'application/json';
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
@ -354,12 +351,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};
@ -585,12 +581,13 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
*
* @summary uploads an image
* @param {number} petId ID of pet to update
* @param {string} [contentType] Content type header parameter
* @param {string} [additionalMetadata] Additional data to pass to server
* @param {File} [file] file to upload
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
uploadFile: async (petId: number, additionalMetadata?: string, file?: File, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
uploadFile: async (petId: number, contentType?: string, additionalMetadata?: string, file?: File, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'petId' is not null or undefined
assertParamExists('uploadFile', 'petId', petId)
const localVarPath = `/pet/{petId}/uploadImage`
@ -623,6 +620,9 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
if (contentType != null) {
localVarHeaderParameter['Content-Type'] = String(contentType);
}
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
@ -745,13 +745,14 @@ export const PetApiFp = function(configuration?: Configuration) {
*
* @summary uploads an image
* @param {number} petId ID of pet to update
* @param {string} [contentType] Content type header parameter
* @param {string} [additionalMetadata] Additional data to pass to server
* @param {File} [file] file to upload
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async uploadFile(petId: number, additionalMetadata?: string, file?: File, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.uploadFile(petId, additionalMetadata, file, options);
async uploadFile(petId: number, contentType?: string, additionalMetadata?: string, file?: File, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ApiResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.uploadFile(petId, contentType, additionalMetadata, file, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['PetApi.uploadFile']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
@ -847,13 +848,14 @@ export const PetApiFactory = function (configuration?: Configuration, basePath?:
*
* @summary uploads an image
* @param {number} petId ID of pet to update
* @param {string} [contentType] Content type header parameter
* @param {string} [additionalMetadata] Additional data to pass to server
* @param {File} [file] file to upload
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
uploadFile(petId: number, additionalMetadata?: string, file?: File, options?: RawAxiosRequestConfig): AxiosPromise<ApiResponse> {
return localVarFp.uploadFile(petId, additionalMetadata, file, options).then((request) => request(axios, basePath));
uploadFile(petId: number, contentType?: string, additionalMetadata?: string, file?: File, options?: RawAxiosRequestConfig): AxiosPromise<ApiResponse> {
return localVarFp.uploadFile(petId, contentType, additionalMetadata, file, options).then((request) => request(axios, basePath));
},
};
};
@ -960,14 +962,15 @@ export class PetApi extends BaseAPI {
*
* @summary uploads an image
* @param {number} petId ID of pet to update
* @param {string} [contentType] Content type header parameter
* @param {string} [additionalMetadata] Additional data to pass to server
* @param {File} [file] file to upload
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof PetApi
*/
public uploadFile(petId: number, additionalMetadata?: string, file?: File, options?: RawAxiosRequestConfig) {
return PetApiFp(this.configuration).uploadFile(petId, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
public uploadFile(petId: number, contentType?: string, additionalMetadata?: string, file?: File, options?: RawAxiosRequestConfig) {
return PetApiFp(this.configuration).uploadFile(petId, contentType, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
}
}

View File

@ -0,0 +1,116 @@
{
"name": "with-complex-headers",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/@types/node": {
"version": "12.20.42",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.42.tgz",
"integrity": "sha512-aI3/oo5DzyiI5R/xAhxxRzfZlWlsbbqdgxfTPkqu/Zt+23GXiJvMCyPJT4+xKSXOnLqoL8jJYMLTwvK2M3a5hw==",
"dev": true
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios": {
"version": "1.7.7",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz",
"integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/typescript": {
"version": "5.6.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
"integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
}
}
}

View File

@ -0,0 +1,34 @@
{
"name": "@openapitools/typescript-axios-petstore",
"version": "1.0.0",
"description": "OpenAPI client for @openapitools/typescript-axios-petstore",
"author": "OpenAPI-Generator Contributors",
"repository": {
"type": "git",
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
},
"keywords": [
"axios",
"typescript",
"openapi-client",
"openapi-generator",
"@openapitools/typescript-axios-petstore"
],
"license": "Unlicense",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"prepare": "npm run build"
},
"dependencies": {
"axios": "^1.6.1"
},
"devDependencies": {
"@types/node": "12.11.5 - 12.20.42",
"typescript": "^4.0 || ^5.0"
},
"publishConfig": {
"registry": "https://skimdb.npmjs.com/registry"
}
}

View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"declaration": true,
"target": "ES5",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist",
"rootDir": ".",
"lib": [
"es6",
"dom"
],
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"dist",
"node_modules"
]
}

View File

@ -2034,15 +2034,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));
}
@ -2055,6 +2046,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};
@ -2116,20 +2114,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};
@ -2387,13 +2383,12 @@ export const FakeApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['queryUnique'] = Array.from(queryUnique);
}
if (headerUnique) {
let mapped = Array.from(headerUnique).map(value => (<any>"Set<string>" !== "Set<string>") ? JSON.stringify(value) : (value || ""));
localVarHeaderParameter['headerUnique'] = mapped.join(COLLECTION_FORMATS["csv"]);
}
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
@ -3391,12 +3386,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};

View File

@ -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};

View File

@ -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};

View File

@ -324,12 +324,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};

View File

@ -99,12 +99,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};

View File

@ -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};

View File

@ -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};

View File

@ -324,12 +324,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};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
{
"private": true,
"dependencies": {
"@openapitools/typescript-axios-petstore": "file:../../builds/with-complex-headers"
},
"scripts": {
"preinstall": "npm --prefix ../../builds/with-complex-headers install && npm run build",
"test": "mocha test/*.ts --require ts-node/register --timeout 10000",
"build": "tsc",
"browserify": "browserify test -p [ tsify ] > ./dist/test.browserify-bundle.js"
},
"devDependencies": {
"@types/chai": "^4.2.14",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.14",
"axios": "*",
"browserify": "^17.0.0",
"chai": "^4.2.0",
"mocha": "^8.2.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.2"
},
"name": "typescript-axios-test-with-complex-headers",
"version": "1.0.0",
"directories": {
"test": "test"
},
"author": "",
"license": "ISC",
"description": ""
}

View File

@ -0,0 +1,59 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>TypeScriptAxiosPetstoreClientWithComplexHeadersTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>TS Axios Petstore Test Client With Complex Headers</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>npm-install</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>npm-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,112 @@
import { expect } from "chai";
import { PetApi, Pet, PetStatusEnum, Category, ApiResponse } from "@openapitools/typescript-axios-petstore";
import axios, {AxiosInstance, AxiosResponse} from "axios";
import * as fs from "fs";
describe("PetApi", () => {
function runSuite(description: string, requestOptions?: any, customAxiosInstance?: AxiosInstance): void {
describe(description, () => {
let api: PetApi;
const fixture: Pet = createTestFixture();
beforeEach(() => {
api = new PetApi(undefined, undefined, customAxiosInstance);
});
it("should add and delete Pet", () => {
return api.addPet(fixture, requestOptions).then(() => {});
});
it("should get Pet by ID", () => {
return api
.getPetById(fixture.id, requestOptions)
.then((result: AxiosResponse<Pet>) => {
return expect(result.data).to.deep.equal(fixture);
});
});
it("should update Pet by ID", () => {
return api
.getPetById(fixture.id, requestOptions)
.then((response: AxiosResponse<Pet>) => {
const result = response.data;
result.name = "newname";
return api.updatePet(result, requestOptions).then(() => {
return api
.getPetById(fixture.id, requestOptions)
.then((response: AxiosResponse<Pet>) => {
return expect(response.data.name).to.deep.equal("newname");
});
});
});
});
it("should upload file with defined contentType", () => {
fs.writeFileSync("/tmp/file.txt", "file content");
const fileObject = fs.readFileSync("/tmp/file.txt");
return api
//@ts-ignore
.uploadFile(fixture.id, "text/plain", "text file", fileObject, requestOptions)
.then((response: AxiosResponse<ApiResponse>) => expect(response.status).to.eq(200));
});
it("should upload file with default contentType", () => {
fs.writeFileSync("/tmp/file.txt", "file content");
const fileObject = fs.readFileSync("/tmp/file.txt");
return api
//@ts-ignore
.uploadFile(fixture.id, undefined, "text file", fileObject, requestOptions)
.then((response: AxiosResponse<ApiResponse>) => expect(response.status).to.eq(200));
});
it("should delete Pet", () => {
return api.deletePet(fixture.id, requestOptions);
});
it("should not contain deleted Pet", () => {
return api.getPetById(fixture.id, requestOptions).then(
(result: AxiosResponse<Pet>) => {
return expect(result.data).to.not.exist;
},
(err: any) => {
return expect(err).to.exist;
}
);
});
});
}
runSuite("without custom request options");
runSuite("with custom request options", {
credentials: "include",
mode: "cors"
});
runSuite("without custom axios instance");
runSuite("with custom axios instance",{}, axios);
runSuite("with custom request options and custom axios instance",{
credentials: "include",
mode: "cors"
}, axios);
});
function createTestFixture(ts = Date.now()) {
const category: Category = {
id: ts,
name: `category${ts}`
};
const pet: Pet = {
id: ts,
name: `pet${ts}`,
category: category,
photoUrls: ["http://foo.bar.com/1", "http://foo.bar.com/2"],
status: PetStatusEnum.Available,
tags: []
};
return pet;
}

View File

@ -0,0 +1 @@
import './PetApi';

View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "CommonJS",
"target": "ES5",
"noImplicitAny": true,
"sourceMap": false,
"outDir": "dist",
"types": [
"mocha",
"node"
],
"lib": [
"es6",
"dom"
]
},
"exclude": [
"node_modules"
]
}