From 32236e418823856ae5ab6a6614f51d40d4f6065c Mon Sep 17 00:00:00 2001 From: Lubos <lmenus@lmen.us> Date: Fri, 22 Mar 2024 12:58:24 +0000 Subject: [PATCH 1/2] fix(api): make useOptions true default --- README.md | 21 ++++++++++++++++++++- src/index.ts | 8 +++++++- src/types/config.ts | 2 +- test/sample.cjs | 1 - 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5729a3039..c965c25e4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ - [Linting](#linting) - [Enums](#enums) - [Config API](#config-api) +- [Migrating](#migrating) - [Contributing](#contributing) ## About @@ -160,7 +161,7 @@ $ openapi-ts --help -o, --output <value> Output directory (required) -c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch") --name <value> Custom client class name - --useOptions <value> Use options instead of arguments (default: false) + --useOptions <value> Use options instead of arguments (default: true) --base <value> Manually set base in OpenAPI config instead of inferring from server value --enums Generate JavaScript objects from enum definitions (default: false) --exportCore <value> Write core files to disk (default: true) @@ -179,6 +180,24 @@ $ openapi-ts --help -h, --help display help for command ``` +## Migrating + +While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. + +### v0.27.37 + +### `useOptions: true` + +By default, generated clients will use a single object argument to pass values to API calls. This is a significant change from the previous default of unspecified array of arguments. If migrating your application in one go isn't feasible, we recommend deprecating your old client and generating a new client. + +```ts +import { DefaultService } from 'client' // <-- old client with array arguments + +import { DefaultService } from 'client_v2' // <-- new client with options argument +``` + +This way, you can gradually switch over to the new syntax as you update parts of your code. Once you've removed all instances of `client` imports, you can safely delete the old `client` folder and find and replace all `client_v2` calls to `client`. + ## Contributing Please refer to the [contributing guide](CONTRIBUTING.md) for how to install the project for development purposes. diff --git a/src/index.ts b/src/index.ts index ea03e0ea4..1aa80a201 100644 --- a/src/index.ts +++ b/src/index.ts @@ -94,7 +94,7 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => request, serviceResponse = 'body', useDateType = false, - useOptions = false, + useOptions = true, write = true, } = userConfig; @@ -110,6 +110,12 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => throw new Error('🚫 output must be within the current working directory'); } + if (!useOptions) { + console.warn( + '⚠️ Deprecation warning: useOptions set to false. This setting will be removed in future versions. Please migrate useOptions to true https://github.com/hey-api/openapi-ts#v0.27.37' + ); + } + const client = userConfig.client || inferClient(dependencies); const output = path.resolve(process.cwd(), userConfig.output); diff --git a/src/types/config.ts b/src/types/config.ts index d07ec5cdb..0c8611af9 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -86,7 +86,7 @@ export interface UserConfig { useDateType?: boolean; /** * Use options or arguments functions - * @default false + * @default true */ useOptions?: boolean; /** diff --git a/test/sample.cjs b/test/sample.cjs index 53812d940..e92c682f7 100644 --- a/test/sample.cjs +++ b/test/sample.cjs @@ -7,7 +7,6 @@ const main = async () => { enums: true, input: './test/spec/v3.json', output: './test/generated/v3/', - useOptions: true, }; const { createClient } = await import(path.resolve(process.cwd(), 'dist/index.js')); From de8c7f628afcc0e6fc697180c8c483106b24014d Mon Sep 17 00:00:00 2001 From: Lubos <lmenus@lmen.us> Date: Fri, 22 Mar 2024 12:59:33 +0000 Subject: [PATCH 2/2] 0.27.38 --- README.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/index.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c965c25e4..4574b138c 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ $ openapi-ts --help While we try to avoid breaking changes, sometimes it's unavoidable in order to offer you the latest features. -### v0.27.37 +### v0.27.38 ### `useOptions: true` diff --git a/package-lock.json b/package-lock.json index 5678c7122..9ec15820e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hey-api/openapi-ts", - "version": "0.27.37", + "version": "0.27.38", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@hey-api/openapi-ts", - "version": "0.27.37", + "version": "0.27.38", "license": "MIT", "dependencies": { "@apidevtools/json-schema-ref-parser": "11.5.4", diff --git a/package.json b/package.json index 8a86ac0eb..a2827eacd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hey-api/openapi-ts", - "version": "0.27.37", + "version": "0.27.38", "type": "module", "description": "Turn your OpenAPI specification into a beautiful TypeScript client", "homepage": "https://github.com/hey-api/openapi-ts/", diff --git a/src/index.ts b/src/index.ts index 1aa80a201..5ac8ff610 100644 --- a/src/index.ts +++ b/src/index.ts @@ -112,7 +112,7 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) => if (!useOptions) { console.warn( - '⚠️ Deprecation warning: useOptions set to false. This setting will be removed in future versions. Please migrate useOptions to true https://github.com/hey-api/openapi-ts#v0.27.37' + '⚠️ Deprecation warning: useOptions set to false. This setting will be removed in future versions. Please migrate useOptions to true https://github.com/hey-api/openapi-ts#v0.27.38' ); }