diff --git a/README.md b/README.md index 5729a3039..4574b138c 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 Output directory (required) -c, --client HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch") --name Custom client class name - --useOptions Use options instead of arguments (default: false) + --useOptions Use options instead of arguments (default: true) --base Manually set base in OpenAPI config instead of inferring from server value --enums Generate JavaScript objects from enum definitions (default: false) --exportCore 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.38 + +### `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/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 ea03e0ea4..5ac8ff610 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.38' + ); + } + 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'));