Skip to content

Commit

Permalink
feat: change the default parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Jan 14, 2025
1 parent f5e5fca commit b5f150a
Show file tree
Hide file tree
Showing 60 changed files with 9,850 additions and 7,400 deletions.
9 changes: 9 additions & 0 deletions .changeset/shaggy-otters-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@example/openapi-ts-fastify': minor
'@hey-api/client-axios': minor
'@hey-api/client-fetch': minor
'@hey-api/openapi-ts': minor
'@hey-api/docs': minor
---

feat: change the default parser
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,6 @@ Clients are responsible for sending the actual HTTP requests. The `client` value

You can learn more on the [Clients](https://heyapi.dev/openapi-ts/clients) page.

### Parser

If you're NOT using a legacy client, we encourage you to try out the experimental parser. Soon, it will become the default parser, but until it's been tested it's an opt-in feature. To try it out, set the `experimentalParser` flag in your configuration to `true`.

#### config

```js
export default {
client: '@hey-api/client-fetch',
experimentalParser: true,
input: 'path/to/openapi.json',
output: 'src/client',
};
```

#### cli

```sh
npx @hey-api/openapi-ts \
-c @hey-api/client-fetch \
-e \
-i path/to/openapi.json \
-o src/client
```

The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as [Filters](https://heyapi.dev/openapi-ts/configuration#filters) and more are being added.

The legacy parser will be used with the [legacy clients](https://heyapi.dev/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates.

## Plugins

Plugins are responsible for generating artifacts from your input. By default, Hey API will generate TypeScript interfaces and SDK from your OpenAPI specification. You can add, remove, or customize any of the plugins. In fact, we highly encourage you to do so!
Expand Down
8 changes: 0 additions & 8 deletions docs/openapi-ts/clients/axios.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ const response = await getFoo({

## Auth

::: warning
To use this feature, you must opt in to the [experimental parser](/openapi-ts/configuration#parser).
:::

The SDKs include auth mechanisms for every endpoint. You will want to configure the `auth` field to pass the right token for each request. The `auth` field can be a string or a function returning a string representing the token. The returned value will be attached only to requests that require auth.

```js
Expand All @@ -179,10 +175,6 @@ client.instance.interceptors.request.use((config) => {

## Build URL

::: warning
To use this feature, you must opt in to the [experimental parser](/openapi-ts/configuration#parser).
:::

If you need to access the compiled URL, you can use the `buildUrl()` method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.

```ts
Expand Down
8 changes: 0 additions & 8 deletions docs/openapi-ts/clients/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ const response = await getFoo({

## Auth

::: warning
To use this feature, you must opt in to the [experimental parser](/openapi-ts/configuration#parser).
:::

The SDKs include auth mechanisms for every endpoint. You will want to configure the `auth` field to pass the right token for each request. The `auth` field can be a string or a function returning a string representing the token. The returned value will be attached only to requests that require auth.

```js
Expand All @@ -218,10 +214,6 @@ client.interceptors.request.use((request, options) => {

## Build URL

::: warning
To use this feature, you must opt in to the [experimental parser](/openapi-ts/configuration#parser).
:::

If you need to access the compiled URL, you can use the `buildUrl()` method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint.

```ts
Expand Down
35 changes: 0 additions & 35 deletions docs/openapi-ts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,6 @@ Plugins are responsible for generating artifacts from your input. By default, He

You can learn more on the [Output](/openapi-ts/output) page.

## Parser

If you're NOT using a legacy client, we encourage you to try out the experimental parser. Soon, it will become the default parser, but until it's been tested it's an opt-in feature. To try it out, set the `experimentalParser` flag in your configuration to `true`.

::: code-group

```js [config]
export default {
client: '@hey-api/client-fetch',
experimentalParser: true, // [!code ++]
input: 'path/to/openapi.json',
output: 'src/client',
};
```

```sh [cli]
npx @hey-api/openapi-ts \
-c @hey-api/client-fetch \
-e \ # [!code ++]
-i path/to/openapi.json \
-o src/client
```

:::

The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as [Filters](#filters) and more are being added.

The legacy parser will be used with the [legacy clients](/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates.

## Formatting

To format your output folder contents, set `output.format` to a valid formatter.
Expand Down Expand Up @@ -222,18 +193,13 @@ You can also prevent your output from being linted by adding your output path to

## Filters

::: warning
To use this feature, you must opt in to the [experimental parser](#parser).
:::

If you work with large specifications and want to generate output from their subset, you can use regular expressions to select the relevant definitions. Set `input.include` to match resource references to be included or `input.exclude` to match resource references to be excluded. When both regular expressions match the same definition, `input.exclude` takes precedence over `input.include`.

::: code-group

```js [include]
export default {
client: '@hey-api/client-fetch',
experimentalParser: true, // [!code ++]
input: {
// match only the schema named `foo` and `GET` operation for the `/api/v1/foo` path // [!code ++]
include: '^(#/components/schemas/foo|#/paths/api/v1/foo/get)$', // [!code ++]
Expand All @@ -246,7 +212,6 @@ export default {
```js [exclude]
export default {
client: '@hey-api/client-fetch',
experimentalParser: true, // [!code ++]
input: {
// match everything except for the schema named `foo` and `GET` operation for the `/api/v1/foo` path // [!code ++]
exclude: '^(#/components/schemas/foo|#/paths/api/v1/foo/get)$', // [!code ++]
Expand Down
4 changes: 0 additions & 4 deletions docs/openapi-ts/custom-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ Re-exporting your plugin from `index.ts` may result in broken output due to nami

## Handler

::: warning
To use this feature, you must opt in to the [experimental parser](/openapi-ts/configuration#parser).
:::

Notice we defined `_handler` in our `config.ts` file. This method is responsible for generating the actual output. We recommend implementing it in `plugin.ts`.

::: code-group
Expand Down
17 changes: 17 additions & 0 deletions docs/openapi-ts/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ This config option is deprecated and will be removed in favor of [clients](./cli

This config option is deprecated and will be removed.

## v0.62.0

### Changed parser

Formerly known as the experimental parser, this is now the default parser. This change should not impact the generated output's functionality. However, there might be cases where this results in breaking changes due to different handling of certain scenarios. If you need to revert to the legacy parser, set the `experimentalParser` flag to `false`.

```js
export default {
client: '@hey-api/client-fetch',
experimentalParser: false, // [!code ++]
input: 'path/to/openapi.json',
output: 'src/client',
};
```

Note that the legacy parser is no longer supported and will be removed in the v1 release.

## v0.61.0

### Added `auth` option
Expand Down
5 changes: 0 additions & 5 deletions docs/openapi-ts/plugins/fastify.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@ Live demo

## Installation

::: warning
To use this feature, you must opt in to the [experimental parser](/openapi-ts/configuration#parser).
:::

In your [configuration](/openapi-ts/get-started), add `fastify` to your plugins and you'll be ready to generate Fastify artifacts. :tada:

```js
import { defaultPlugins } from '@hey-api/openapi-ts';

export default {
client: '@hey-api/client-fetch',
experimentalParser: true, // [!code ++]
input: 'path/to/openapi.json',
output: 'src/client',
plugins: [
Expand Down
5 changes: 0 additions & 5 deletions docs/openapi-ts/plugins/zod.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ Live demo

## Installation

::: warning
To use this feature, you must opt in to the [experimental parser](/openapi-ts/configuration#parser).
:::

In your [configuration](/openapi-ts/get-started), add `zod` to your plugins and you'll be ready to generate Zod artifacts. :tada:

```js
import { defaultPlugins } from '@hey-api/openapi-ts';

export default {
client: '@hey-api/client-fetch',
experimentalParser: true, // [!code ++]
input: 'path/to/openapi.json',
output: 'src/client',
plugins: [
Expand Down
1 change: 0 additions & 1 deletion examples/openapi-ts-fastify/openapi-ts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
client: '@hey-api/client-fetch',
experimentalParser: true,
input:
'https://gist.githubusercontent.com/seriousme/55bd4c8ba2e598e416bb5543dcd362dc/raw/cf0b86ba37bb54bf1a6bf047c0ecf2a0ce4c62e0/petstore-v3.1.json',
output: {
Expand Down
4 changes: 0 additions & 4 deletions packages/client-axios/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
export interface Config<ThrowOnError extends boolean = boolean>
extends Omit<CreateAxiosDefaults, 'auth' | 'headers'> {
/**
* **This feature works only with the [experimental parser](https://heyapi.dev/openapi-ts/configuration#parser)**
*
* Auth token or a function returning auth token. The resolved value will be
* added to the request payload as defined by its `security` array.
*/
Expand Down Expand Up @@ -85,8 +83,6 @@ export interface Config<ThrowOnError extends boolean = boolean>
*/
responseTransformer?: (data: unknown) => Promise<unknown>;
/**
* **This feature works only with the [experimental parser](https://heyapi.dev/openapi-ts/configuration#parser)**
*
* A function validating response data. This is useful if you want to ensure
* the response conforms to the desired shape, so it can be safely passed to
* the transformers and returned to the user.
Expand Down
4 changes: 0 additions & 4 deletions packages/client-fetch/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
export interface Config<ThrowOnError extends boolean = boolean>
extends Omit<RequestInit, 'body' | 'headers' | 'method'> {
/**
* **This feature works only with the [experimental parser](https://heyapi.dev/openapi-ts/configuration#parser)**
*
* Auth token or a function returning auth token. The resolved value will be
* added to the request payload as defined by its `security` array.
*/
Expand Down Expand Up @@ -90,8 +88,6 @@ export interface Config<ThrowOnError extends boolean = boolean>
*/
responseTransformer?: (data: unknown) => Promise<unknown>;
/**
* **This feature works only with the [experimental parser](https://heyapi.dev/openapi-ts/configuration#parser)**
*
* A function validating response data. This is useful if you want to ensure
* the response conforms to the desired shape, so it can be safely passed to
* the transformers and returned to the user.
Expand Down
29 changes: 0 additions & 29 deletions packages/openapi-ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,6 @@ Clients are responsible for sending the actual HTTP requests. The `client` value

You can learn more on the [Clients](https://heyapi.dev/openapi-ts/clients) page.

### Parser

If you're NOT using a legacy client, we encourage you to try out the experimental parser. Soon, it will become the default parser, but until it's been tested it's an opt-in feature. To try it out, set the `experimentalParser` flag in your configuration to `true`.

#### config

```js
export default {
client: '@hey-api/client-fetch',
experimentalParser: true,
input: 'path/to/openapi.json',
output: 'src/client',
};
```

#### cli

```sh
npx @hey-api/openapi-ts \
-c @hey-api/client-fetch \
-e \
-i path/to/openapi.json \
-o src/client
```

The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as [Filters](https://heyapi.dev/openapi-ts/configuration#filters) and more are being added.

The legacy parser will be used with the [legacy clients](https://heyapi.dev/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates.

## Plugins

Plugins are responsible for generating artifacts from your input. By default, Hey API will generate TypeScript interfaces and SDK from your OpenAPI specification. You can add, remove, or customize any of the plugins. In fact, we highly encourage you to do so!
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ const initConfigs = async (userConfig: UserConfig): Promise<Config[]> => {
base,
configFile = '',
dryRun = false,
experimentalParser = false,
experimentalParser = true,
exportCore = true,
name,
request,
Expand Down
8 changes: 2 additions & 6 deletions packages/openapi-ts/src/plugins/@hey-api/sdk/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export interface Config extends Plugin.Name<'@hey-api/sdk'> {
*/
asClass?: boolean;
/**
* **This feature works only with the [experimental parser](https://heyapi.dev/openapi-ts/configuration#parser)**
*
* Should the generated functions contain auth mechanisms? You may want to
* disable this option if you're handling auth yourself or defining it
* globally on the client and want to reduce the size of generated code.
Expand All @@ -26,15 +24,15 @@ export interface Config extends Plugin.Name<'@hey-api/sdk'> {
*/
auth?: boolean;
/**
* @deprecated
*
* **This feature works only with the legacy parser**
*
* Filter endpoints to be included in the generated SDK. The provided
* string should be a regular expression where matched results will be
* included in the output. The input pattern this string will be tested
* against is `{method} {path}`. For example, you can match
* `POST /api/v1/foo` with `^POST /api/v1/foo$`.
*
* @deprecated
*/
filter?: string;
/**
Expand Down Expand Up @@ -96,8 +94,6 @@ export interface Config extends Plugin.Name<'@hey-api/sdk'> {
*/
transformer?: '@hey-api/transformers' | boolean;
/**
* **This feature works only with the [experimental parser](https://heyapi.dev/openapi-ts/configuration#parser)**
*
* Validate response data against schema before returning. This is useful
* if you want to ensure the response conforms to a desired shape. However,
* validation adds runtime overhead, so it's not recommended to use unless
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { Plugin } from '../../types';

export interface Config extends Plugin.Name<'@hey-api/transformers'> {
/**
* **This feature works only with the [experimental parser](https://heyapi.dev/openapi-ts/configuration#parser)**
*
* Convert long integers into BigInt values?
*
* @default true
Expand Down
Loading

0 comments on commit b5f150a

Please sign in to comment.