diff --git a/package.json b/package.json index fb058fd6..d9e6f259 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.12.0-alpha.0", + "version": "0.12.0-alpha", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", @@ -56,7 +56,7 @@ "eslint:fix": "eslint \"./src/**/*.ts\" \"./bin/index.js\" \"./types/index.d.ts\" --fix", "prettier": "prettier \"./src/**/*.ts\" \"./bin/index.js\" \"./types/index.d.ts\" --check", "prettier:fix": "prettier \"./src/**/*.ts\" \"./bin/index.js\" \"./types/index.d.ts\" --write", - "prepublish": "yarn run clean && yarn run release", + "prepublishOnly": "yarn run clean && yarn run release", "codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b" }, "dependencies": { diff --git a/src/templates/core/OpenAPI.hbs b/src/templates/core/OpenAPI.hbs index af965faf..9721fc82 100644 --- a/src/templates/core/OpenAPI.hbs +++ b/src/templates/core/OpenAPI.hbs @@ -4,11 +4,13 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; type Resolver = (options: ApiRequestOptions) => Promise; type Headers = Record; +type CredentialModes = 'include' | 'omit' | 'same-origin'; type Config = { BASE: string; VERSION: string; WITH_CREDENTIALS: boolean; + CREDENTIALS: CredentialModes; TOKEN?: string | Resolver; USERNAME?: string | Resolver; PASSWORD?: string | Resolver; @@ -20,6 +22,7 @@ export const OpenAPI: Config = { BASE: '{{{server}}}', VERSION: '{{{version}}}', WITH_CREDENTIALS: false, + CREDENTIALS: 'include', TOKEN: undefined, USERNAME: undefined, PASSWORD: undefined, diff --git a/src/templates/core/axios/sendRequest.hbs b/src/templates/core/axios/sendRequest.hbs index 60378bfa..348e37ad 100644 --- a/src/templates/core/axios/sendRequest.hbs +++ b/src/templates/core/axios/sendRequest.hbs @@ -13,6 +13,7 @@ async function sendRequest( headers, data: body || formData, method: options.method, + withCredentials: OpenAPI.WITH_CREDENTIALS, cancelToken: source.token, }; diff --git a/src/templates/core/fetch/sendRequest.hbs b/src/templates/core/fetch/sendRequest.hbs index dce73248..c48bd9f7 100644 --- a/src/templates/core/fetch/sendRequest.hbs +++ b/src/templates/core/fetch/sendRequest.hbs @@ -16,7 +16,7 @@ async function sendRequest( }; if (OpenAPI.WITH_CREDENTIALS) { - request.credentials = 'include'; + request.credentials = OpenAPI.CREDENTIALS; } onCancel(() => controller.abort()); diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index bd141972..e317c3d9 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -180,11 +180,13 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; type Resolver = (options: ApiRequestOptions) => Promise; type Headers = Record; +type CredentialModes = 'include' | 'omit' | 'same-origin'; type Config = { BASE: string; VERSION: string; WITH_CREDENTIALS: boolean; + CREDENTIALS: CredentialModes; TOKEN?: string | Resolver; USERNAME?: string | Resolver; PASSWORD?: string | Resolver; @@ -196,6 +198,7 @@ export const OpenAPI: Config = { BASE: 'http://localhost:3000/base', VERSION: '1.0', WITH_CREDENTIALS: false, + CREDENTIALS: 'include', TOKEN: undefined, USERNAME: undefined, PASSWORD: undefined, @@ -374,7 +377,7 @@ async function sendRequest( }; if (OpenAPI.WITH_CREDENTIALS) { - request.credentials = 'include'; + request.credentials = OpenAPI.CREDENTIALS; } onCancel(() => controller.abort()); @@ -2691,11 +2694,13 @@ import type { ApiRequestOptions } from './ApiRequestOptions'; type Resolver = (options: ApiRequestOptions) => Promise; type Headers = Record; +type CredentialModes = 'include' | 'omit' | 'same-origin'; type Config = { BASE: string; VERSION: string; WITH_CREDENTIALS: boolean; + CREDENTIALS: CredentialModes; TOKEN?: string | Resolver; USERNAME?: string | Resolver; PASSWORD?: string | Resolver; @@ -2707,6 +2712,7 @@ export const OpenAPI: Config = { BASE: 'http://localhost:3000/base', VERSION: '1.0', WITH_CREDENTIALS: false, + CREDENTIALS: 'include', TOKEN: undefined, USERNAME: undefined, PASSWORD: undefined, @@ -2885,7 +2891,7 @@ async function sendRequest( }; if (OpenAPI.WITH_CREDENTIALS) { - request.credentials = 'include'; + request.credentials = OpenAPI.CREDENTIALS; } onCancel(() => controller.abort());