Skip to content

Commit

Permalink
Merge pull request #120 from hey-api/fix/use-options-api
Browse files Browse the repository at this point in the history
fix(api): make useOptions true default
  • Loading branch information
mrlubos authored Mar 22, 2024
2 parents 088060e + de8c7f6 commit 60f4d4b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Linting](#linting)
- [Enums](#enums)
- [Config API](#config-api)
- [Migrating](#migrating)
- [Contributing](#contributing)

## About
Expand Down Expand Up @@ -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)
Expand All @@ -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.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const getConfig = async (userConfig: UserConfig, dependencies: Dependencies) =>
request,
serviceResponse = 'body',
useDateType = false,
useOptions = false,
useOptions = true,
write = true,
} = userConfig;

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface UserConfig {
useDateType?: boolean;
/**
* Use options or arguments functions
* @default false
* @default true
*/
useOptions?: boolean;
/**
Expand Down
1 change: 0 additions & 1 deletion test/sample.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 60f4d4b

Please sign in to comment.