···4949We use [`@apidevtools/json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser) to resolve file locations. Please note that accessing a HTTPS URL on localhost has a known [workaround](https://github.com/hey-api/openapi-ts/issues/276).
5050:::
51515252+## Filters
5353+5454+::: warning
5555+Filters work only with the [experimental parser](#parser) which is currently an opt-in feature.
5656+:::
5757+5858+If you work with large specifications and want to generate output from their subset, set `input.include` to a valid regular expression string.
5959+6060+```js
6161+export default {
6262+ client: '@hey-api/client-fetch',
6363+ experimentalParser: true, // [!code ++]
6464+ input: {
6565+ include: '^(#/components/schemas/foo|#/paths/api/v1/foo/get)$', // [!code ++]
6666+ path: 'path/to/openapi.json',
6767+ },
6868+ output: 'src/client',
6969+};
7070+```
7171+7272+The configuration above will process only the schema named `foo` and `GET` operation for the `/api/v1/foo` path.
7373+5274## Output
53755476Output is the next thing to define. It can be either a string pointing to the destination folder or a configuration object containing the destination folder path and optional settings (these are described below).
···179201Plugins are responsible for generating artifacts from your input. By default, Hey API will generate TypeScript interfaces, JSON Schemas, and services from your OpenAPI specification. You can add, remove, or customize any of the plugins. In fact, we highly encourage you to do so!
180202181203You can learn more on the [Output](/openapi-ts/output) page.
204204+205205+## Parser
206206+207207+If you're using OpenAPI 3.0 or newer, we encourage you to try out the experimental parser. In the future 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`.
208208+209209+::: code-group
210210+211211+```js [config]
212212+export default {
213213+ client: '@hey-api/client-fetch',
214214+ experimentalParser: true, // [!code ++]
215215+ input: 'path/to/openapi.json',
216216+ output: 'src/client',
217217+};
218218+```
219219+220220+```sh [cli]
221221+npx @hey-api/openapi-ts -i path/to/openapi.json -o src/client -c @hey-api/client-fetch -e
222222+```
223223+224224+:::
225225+226226+The experimental parser produces a cleaner output while being faster than the legacy parser. It also supports features such as [Filters](#filters) and more will be added in the future.
227227+228228+The legacy parser will remain enabled for the [legacy clients](/openapi-ts/clients/legacy) regardless of the `experimentalParser` flag value. However, it's unlikely to receive any further updates.
182229183230## Config API
184231
+32
docs/openapi-ts/migrating.md
···50505151This config option is deprecated and will be removed.
52525353+## v0.55.0
5454+5555+This release adds the ability to filter your OpenAPI specification before it's processed. This feature will be useful if you are working with a large specification and are interested in generating output only from a small subset.
5656+5757+This feature is available only in the experimental parser. In the future, this will become the default parser. To opt-in to the experimental parser, set the `experimentalParser` flag in your configuration to `true`.
5858+5959+### Deprecated `include` in `@hey-api/types`
6060+6161+This config option is deprecated and will be removed when the experimental parser becomes the default.
6262+6363+### Deprecated `filter` in `@hey-api/services`
6464+6565+This config option is deprecated and will be removed when the experimental parser becomes the default.
6666+6767+### Added `input.include` option
6868+6969+This config option can be used to replace the deprecated options. It accepts a regular expression string matching against references within the bundled specification.
7070+7171+```js
7272+export default {
7373+ client: '@hey-api/client-fetch',
7474+ experimentalParser: true,
7575+ input: {
7676+ include: '^(#/components/schemas/foo|#/paths/api/v1/foo/get)$', // [!code ++]
7777+ path: 'path/to/openapi.json',
7878+ },
7979+ output: 'src/client',
8080+};
8181+```
8282+8383+The configuration above will process only the schema named `foo` and `GET` operation for the `/api/v1/foo` path.
8484+5385## v0.54.0
54865587This release makes plugins first-class citizens. In order to achieve that, the following breaking changes were introduced.
-2
docs/openapi-ts/output.md
···88Learn about files generated with `@hey-api/openapi-ts`.
991010::: tip
1111-1211Your actual output depends on your Hey API configuration. It may contain a different number of files and their contents might differ.
1313-1412:::
15131614## Overview
···2020 * results will be included in the output. The input pattern this
2121 * string will be tested against is `{method} {path}`. For example,
2222 * you can match `POST /api/v1/foo` with `^POST /api/v1/foo$`.
2323+ *
2424+ * This option does not work with the experimental parser.
2525+ *
2626+ * @deprecated
2327 */
2428 filter?: string;
2529 /**
···77 */
88 enums?: 'javascript' | 'typescript' | 'typescript+namespace' | false;
99 /**
1010- * Include only types matching regular expression
1010+ * Include only types matching regular expression.
1111+ *
1212+ * This option does not work with the experimental parser.
1313+ *
1414+ * @deprecated
1115 */
1216 include?: string;
1317 /**
+33-5
packages/openapi-ts/src/types/config.ts
···11import type { ClientPlugins, UserPlugins } from '../plugins/';
22-import type { ArrayOfObjectsToObjectMap, ExtractArrayOfObjects } from './utils';
22+import type {
33+ ArrayOfObjectsToObjectMap,
44+ ExtractArrayOfObjects,
55+ ExtractWithDiscriminator,
66+} from './utils';
3748export const CLIENTS = [
59 '@hey-api/client-axios',
···6771 */
6872 exportCore?: boolean;
6973 /**
7070- * The relative location of the OpenAPI spec
7474+ * Path to the OpenAPI specification. This can be either local or remote path.
7575+ * Both JSON and YAML file formats are supported. You can also pass the parsed
7676+ * object directly if you're fetching the file yourself.
7777+ *
7878+ * Alternatively, you can define a configuration object with more options.
7179 */
7272- input: string | Record<string, unknown>;
8080+ input:
8181+ | string
8282+ | Record<string, unknown>
8383+ | {
8484+ /**
8585+ * Process only parts matching the regular expression. You can select both
8686+ * operations and components by reference within the bundled input.
8787+ *
8888+ * @example
8989+ * operation: '^#/paths/api/v1/foo/get$'
9090+ * schema: '^#/components/schemas/Foo$'
9191+ */
9292+ include?: string;
9393+ /**
9494+ * Path to the OpenAPI specification. This can be either local or remote path.
9595+ * Both JSON and YAML file formats are supported. You can also pass the parsed
9696+ * object directly if you're fetching the file yourself.
9797+ */
9898+ path: string | Record<string, unknown>;
9999+ };
73100 /**
74101 * Custom client class name. Please note this option is deprecated and
75102 * will be removed in favor of clients.
···123150124151export type Config = Omit<
125152 Required<ClientConfig>,
126126- 'base' | 'client' | 'name' | 'output' | 'plugins' | 'request'
153153+ 'base' | 'client' | 'input' | 'name' | 'output' | 'plugins' | 'request'
127154> &
128155 Pick<ClientConfig, 'base' | 'name' | 'request'> & {
129156 client: Extract<Required<ClientConfig>['client'], object>;
130130- output: Extract<Required<ClientConfig>['output'], object>;
157157+ input: ExtractWithDiscriminator<ClientConfig['input'], { path: unknown }>;
158158+ output: Extract<ClientConfig['output'], object>;
131159 pluginOrder: ReadonlyArray<ClientPlugins['name']>;
132160 plugins: ArrayOfObjectsToObjectMap<
133161 ExtractArrayOfObjects<ReadonlyArray<ClientPlugins>, { name: string }>,
+5-3
packages/openapi-ts/src/types/utils.ts
···11import type { TypeScriptFile } from '../generate/files';
2233-type ExtractFromArray<T, Discriminator> = T extends Discriminator ? T : never;
33+export type ExtractWithDiscriminator<T, Discriminator> = T extends Discriminator
44+ ? T
55+ : never;
4657/**
68 * Accepts an array of elements union and attempts to extract only objects.
···911 */
1012export type ExtractArrayOfObjects<T, Discriminator> =
1113 T extends Array<infer U>
1212- ? Array<ExtractFromArray<U, Discriminator>>
1414+ ? Array<ExtractWithDiscriminator<U, Discriminator>>
1315 : T extends ReadonlyArray<infer U>
1414- ? ReadonlyArray<ExtractFromArray<U, Discriminator>>
1616+ ? ReadonlyArray<ExtractWithDiscriminator<U, Discriminator>>
1517 : never;
16181719export type Files = Record<string, TypeScriptFile>;
···11-import { existsSync } from 'node:fs';
22-import path from 'node:path';
33-44-import $RefParser from '@apidevtools/json-schema-ref-parser';
55-66-import type { OpenApi } from '../openApi';
77-88-/**
99- * Load and parse te open api spec. If the file extension is ".yml" or ".yaml"
1010- * we will try to parse the file as a YAML spec, otherwise we will fall back
1111- * on parsing the file as JSON.
1212- * @param location: Path or url
1313- */
1414-export const getOpenApiSpec = async (location: string) => {
1515- const absolutePathOrUrl = existsSync(location)
1616- ? path.resolve(location)
1717- : location;
1818- const schema = (await $RefParser.bundle(
1919- absolutePathOrUrl,
2020- absolutePathOrUrl,
2121- {},
2222- )) as OpenApi;
2323- return schema;
2424-};
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+export type Foo = {
44+ foo?: "foo'bar" | 'foo"bar';
55+};
66+77+export type Bar = "foo'bar" | 'foo"bar';
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+export type Foo = {
44+ foo?: "foo'bar" | 'foo"bar';
55+};
66+77+export type Bar = "foo'bar" | 'foo"bar';