diff --git a/.changeset/soft-penguins-fetch.md b/.changeset/soft-penguins-fetch.md new file mode 100644 index 0000000000..fbca18be86 --- /dev/null +++ b/.changeset/soft-penguins-fetch.md @@ -0,0 +1,5 @@ +--- +'@hey-api/openapi-ts': patch +--- + +feat(input): input supports Hey API Registry shorthand diff --git a/docs/openapi-ts/clients/angular.md b/docs/openapi-ts/clients/angular.md index 6526486fef..87a2e22cec 100644 --- a/docs/openapi-ts/clients/angular.md +++ b/docs/openapi-ts/clients/angular.md @@ -49,7 +49,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/client-angular` ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['@hey-api/client-angular'], // [!code ++] }; @@ -57,7 +57,7 @@ export default { ```sh [cli] npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ + -i hey-api/backend \ -o src/client \ -c @hey-api/client-angular # [!code ++] ``` @@ -105,7 +105,7 @@ Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { @@ -178,7 +178,7 @@ export class FooService { ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ '@hey-api/client-angular', diff --git a/docs/openapi-ts/clients/angular/v19.md b/docs/openapi-ts/clients/angular/v19.md index b504bf34fe..b755acde40 100644 --- a/docs/openapi-ts/clients/angular/v19.md +++ b/docs/openapi-ts/clients/angular/v19.md @@ -49,7 +49,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/client-angular` ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['@hey-api/client-angular'], // [!code ++] }; @@ -57,7 +57,7 @@ export default { ```sh [cli] npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ + -i hey-api/backend \ -o src/client \ -c @hey-api/client-angular # [!code ++] ``` @@ -105,7 +105,7 @@ Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { @@ -178,7 +178,7 @@ export class FooService { ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ '@hey-api/client-angular', diff --git a/docs/openapi-ts/clients/axios.md b/docs/openapi-ts/clients/axios.md index 926d1ca6cf..b485ee1d84 100644 --- a/docs/openapi-ts/clients/axios.md +++ b/docs/openapi-ts/clients/axios.md @@ -46,7 +46,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/client-axios` to ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['@hey-api/client-axios'], // [!code ++] }; @@ -54,7 +54,7 @@ export default { ```sh [cli] npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ + -i hey-api/backend \ -o src/client \ -c @hey-api/client-axios # [!code ++] ``` @@ -87,7 +87,7 @@ Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { diff --git a/docs/openapi-ts/clients/fetch.md b/docs/openapi-ts/clients/fetch.md index b87f08dbcc..9691d3fa4f 100644 --- a/docs/openapi-ts/clients/fetch.md +++ b/docs/openapi-ts/clients/fetch.md @@ -39,7 +39,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/client-fetch` to ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['@hey-api/client-fetch'], // [!code ++] }; @@ -47,7 +47,7 @@ export default { ```sh [cli] npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ + -i hey-api/backend \ -o src/client \ -c @hey-api/client-fetch # [!code ++] ``` @@ -86,7 +86,7 @@ Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { diff --git a/docs/openapi-ts/clients/legacy.md b/docs/openapi-ts/clients/legacy.md index ef09c5b48a..db7abeefe0 100644 --- a/docs/openapi-ts/clients/legacy.md +++ b/docs/openapi-ts/clients/legacy.md @@ -19,7 +19,7 @@ Before client packages, clients were generated using `@hey-api/openapi-ts`. In f ```js [fetch] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['legacy/fetch'], // [!code ++] }; @@ -27,7 +27,7 @@ export default { ```js [axios] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['legacy/axios'], // [!code ++] }; @@ -35,7 +35,7 @@ export default { ```js [angular] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['legacy/angular'], // [!code ++] }; @@ -43,7 +43,7 @@ export default { ```js [node] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['legacy/node'], // [!code ++] }; @@ -51,7 +51,7 @@ export default { ```js [xhr] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['legacy/xhr'], // [!code ++] }; diff --git a/docs/openapi-ts/clients/next-js.md b/docs/openapi-ts/clients/next-js.md index e167e4aa54..f9013ad653 100644 --- a/docs/openapi-ts/clients/next-js.md +++ b/docs/openapi-ts/clients/next-js.md @@ -29,7 +29,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/client-next` to ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['@hey-api/client-next'], // [!code ++] }; @@ -37,7 +37,7 @@ export default { ```sh [cli] npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ + -i hey-api/backend \ -o src/client \ -c @hey-api/client-next # [!code ++] ``` @@ -56,7 +56,7 @@ Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { diff --git a/docs/openapi-ts/clients/nuxt.md b/docs/openapi-ts/clients/nuxt.md index 17fb2a9572..75280bf965 100644 --- a/docs/openapi-ts/clients/nuxt.md +++ b/docs/openapi-ts/clients/nuxt.md @@ -64,7 +64,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/client-nuxt` to ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['@hey-api/client-nuxt'], // [!code ++] }; @@ -72,7 +72,7 @@ export default { ```sh [cli] npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ + -i hey-api/backend \ -o src/client \ -c @hey-api/client-nuxt # [!code ++] ``` @@ -111,7 +111,7 @@ Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { diff --git a/docs/openapi-ts/configuration.md b/docs/openapi-ts/configuration.md index 96dd89123f..0ab3234dda 100644 --- a/docs/openapi-ts/configuration.md +++ b/docs/openapi-ts/configuration.md @@ -13,7 +13,7 @@ description: Configure @hey-api/openapi-ts. import { defineConfig } from '@hey-api/openapi-ts'; export default defineConfig({ - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }); ``` @@ -21,7 +21,7 @@ export default defineConfig({ ```js [openapi-ts.config.cjs] /** @type {import('@hey-api/openapi-ts').UserConfig} */ module.exports = { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -29,7 +29,7 @@ module.exports = { ```js [openapi-ts.config.mjs] /** @type {import('@hey-api/openapi-ts').UserConfig} */ export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -65,7 +65,9 @@ export default defineConfig([ ## Input -You must set the input so we can load your OpenAPI specification. It can be a path or URL, object containing a path or URL, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats. +You must provide an input so we can load your OpenAPI specification. + +The input can be a string path, URL, API registry shorthand, an object containing any of these, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats. You can learn more on the [Input](/openapi-ts/configuration/input) page. @@ -79,7 +81,13 @@ export default { ```js [url] export default { - input: 'https://get.heyapi.dev/hey-api/backend', // [!code ++] + input: 'https://get.heyapi.dev/hey-api/backend', // sign up at app.heyapi.dev // [!code ++] +}; +``` + +```js [registry] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++] }; ``` @@ -87,7 +95,7 @@ export default { ```js [object] export default { input: { // [!code ++] - path: 'https://get.heyapi.dev/hey-api/backend', // [!code ++] + path: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++] // ...other options // [!code ++] }, // [!code ++] }; @@ -120,7 +128,7 @@ You can learn more on the [Output](/openapi-ts/configuration/output) page. ```js [path] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', // [!code ++] }; ``` @@ -128,7 +136,7 @@ export default { ```js [object] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { // [!code ++] path: 'src/client', // [!code ++] // ...other options // [!code ++] diff --git a/docs/openapi-ts/configuration/input.md b/docs/openapi-ts/configuration/input.md index 000ad7f08b..84343b0c39 100644 --- a/docs/openapi-ts/configuration/input.md +++ b/docs/openapi-ts/configuration/input.md @@ -5,11 +5,11 @@ description: Configure @hey-api/openapi-ts. # Input -You must set the input so we can load your OpenAPI specification. +You must provide an input so we can load your OpenAPI specification. ## Input -Input can be a path or URL, object containing a path or URL, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats. +The input can be a string path, URL, API registry shorthand, an object containing any of these, or an object representing an OpenAPI specification. Hey API supports all valid OpenAPI versions and file formats. ::: code-group @@ -21,7 +21,13 @@ export default { ```js [url] export default { - input: 'https://get.heyapi.dev/hey-api/backend', // [!code ++] + input: 'https://get.heyapi.dev/hey-api/backend', // sign up at app.heyapi.dev // [!code ++] +}; +``` + +```js [registry] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++] }; ``` @@ -29,7 +35,7 @@ export default { ```js [object] export default { input: { // [!code ++] - path: 'https://get.heyapi.dev/hey-api/backend', // [!code ++] + path: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++] // ...other options // [!code ++] }, // [!code ++] }; @@ -52,74 +58,70 @@ export default { If you use an HTTPS URL with a self-signed certificate in development, you will need to set [`NODE_TLS_REJECT_UNAUTHORIZED=0`](https://github.com/hey-api/openapi-ts/issues/276#issuecomment-2043143501) in your environment. ::: -### ReadMe API Registry - -You can use ReadMe API Registry UUIDs to fetch OpenAPI specifications directly from ReadMe's platform. This is useful when API providers use ReadMe as their source of truth for API documentation. - -::: code-group - -```js [simple format] -export default { - input: 'readme:abc123def456', // [!code ++] -}; -``` +### Request options -```js [full format] -export default { - input: 'readme:@organization/project#abc123def456', // [!code ++] -}; -``` +You can pass any valid Fetch API [options](https://developer.mozilla.org/docs/Web/API/RequestInit) to the request for fetching your specification. This is useful if your file is behind auth for example. -```js [object format] + +```js export default { input: { - path: 'readme:abc123def456', // [!code ++] - // ...other options + path: 'https://secret.com/protected-spec', + fetch: { // [!code ++] + headers: { // [!code ++] + Authorization: 'Bearer xxx', // [!code ++] + }, // [!code ++] + }, // [!code ++] }, }; ``` + -::: +## API Registry -The ReadMe input formats are: +You can store your specifications in an API registry to serve as a single source of truth. This helps prevent drift, improves discoverability, enables version tracking, and more. -- `readme:uuid` - Simple format using only the UUID -- `readme:@organization/project#uuid` - Full format including organization and project names +### Hey API -Both formats will fetch the OpenAPI specification from `https://dash.readme.com/api/v1/api-registry/{uuid}`. +You can learn more about [Hey API Platform](https://app.heyapi.dev) on the [Integrations](/openapi-ts/integrations) page. -### Hey API Platform options +```js [uuid] +export default { + input: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++] +}; +``` -You might want to use the [Hey API Platform](/openapi-ts/integrations) to store your specifications. If you do so, the `input` object provides options to help with constructing the correct URL. +The `input` object lets you provide additional options to construct the correct URL. ```js export default { input: { - path: 'https://get.heyapi.dev/', + path: 'hey-api/backend', // sign up at app.heyapi.dev branch: 'main', // [!code ++] - project: 'backend', // [!code ++] }, }; ``` -### Request options +We also provide shorthands for other registries: -You can pass any valid Fetch API [options](https://developer.mozilla.org/docs/Web/API/RequestInit) to the request for fetching your specification. This is useful if your file is behind auth for example. +::: details ReadMe +Prefix your input with `readme:` to use the ReadMe API Registry. - -```js +::: code-group + +```js [uuid] export default { - input: { - path: 'https://secret.com/protected-spec', - fetch: { // [!code ++] - headers: { // [!code ++] - Authorization: 'Bearer xxx', // [!code ++] - }, // [!code ++] - }, // [!code ++] - }, + input: 'readme:nysezql0wwo236', // [!code ++] }; ``` - + +```js [long] +export default { + input: 'readme:@developers/v2.0#nysezql0wwo236', // [!code ++] +}; +``` + +::: ## Watch Mode @@ -134,7 +136,7 @@ If your schema changes frequently, you may want to automatically regenerate the ```js [config] export default { input: { - path: 'https://get.heyapi.dev/hey-api/backend', + path: 'hey-api/backend', // sign up at app.heyapi.dev watch: true, // [!code ++] }, }; @@ -142,7 +144,7 @@ export default { ```sh [cli] npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ + -i hey-api/backend \ -o src/client \ -w # [!code ++] ``` diff --git a/docs/openapi-ts/configuration/output.md b/docs/openapi-ts/configuration/output.md index 1c23632cc8..660b120970 100644 --- a/docs/openapi-ts/configuration/output.md +++ b/docs/openapi-ts/configuration/output.md @@ -15,7 +15,7 @@ Output can be a path to the destination folder or an object containing the desti ```js [path] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', // [!code ++] }; ``` @@ -23,7 +23,7 @@ export default { ```js [object] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { // [!code ++] path: 'src/client', // [!code ++] // ...other options // [!code ++] @@ -42,7 +42,7 @@ To format your output folder contents, set `output.format` to a valid formatter. ```js [disabled] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { format: false, // [!code ++] path: 'src/client', @@ -52,7 +52,7 @@ export default { ```js [prettier] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { format: 'prettier', // [!code ++] path: 'src/client', @@ -62,7 +62,7 @@ export default { ```js [biome] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { format: 'biome', // [!code ++] path: 'src/client', @@ -82,7 +82,7 @@ To lint your output folder contents, set `output.lint` to a valid linter. ```js [disabled] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { lint: false, // [!code ++] path: 'src/client', @@ -92,7 +92,7 @@ export default { ```js [eslint] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { lint: 'eslint', // [!code ++] path: 'src/client', @@ -102,7 +102,7 @@ export default { ```js [biome] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { lint: 'biome', // [!code ++] path: 'src/client', @@ -112,7 +112,7 @@ export default { ```js [oxlint] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { lint: 'oxlint', // [!code ++] path: 'src/client', @@ -132,7 +132,7 @@ We use the [TSConfig file](https://www.typescriptlang.org/tsconfig/) to generate ```js [custom] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { path: 'src/client', tsConfigPath: './config/tsconfig.custom.json', // [!code ++] @@ -142,7 +142,7 @@ export default { ```js [off] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { path: 'src/client', tsConfigPath: 'off', // [!code ++] @@ -158,7 +158,7 @@ By default, you can't keep custom files in the `output.path` folder because it's ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { clean: false, // [!code ++] path: 'src/client', diff --git a/docs/openapi-ts/configuration/parser.md b/docs/openapi-ts/configuration/parser.md index dbc7a611d9..87e99e0886 100644 --- a/docs/openapi-ts/configuration/parser.md +++ b/docs/openapi-ts/configuration/parser.md @@ -16,7 +16,7 @@ You can add custom patches with `patch`. ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] patch: { // [!code ++] @@ -58,7 +58,7 @@ To validate your input, set `validate_EXPERIMENTAL` to `true`. ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] validate_EXPERIMENTAL: true, // [!code ++] @@ -80,7 +80,7 @@ Set `include` to match operations to be included or `exclude` to match operation ```js [include] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -95,7 +95,7 @@ export default { ```js [exclude] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -119,7 +119,7 @@ Set `include` to match tags to be included or `exclude` to match tags to be excl ```js [include] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -134,7 +134,7 @@ export default { ```js [exclude] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -156,7 +156,7 @@ You can filter out deprecated resources by setting `deprecated` to `false`. ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -176,7 +176,7 @@ Set `include` to match schemas to be included or `exclude` to match schemas to b ```js [include] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -191,7 +191,7 @@ export default { ```js [exclude] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -215,7 +215,7 @@ Set `include` to match parameters to be included or `exclude` to match parameter ```js [include] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -230,7 +230,7 @@ export default { ```js [exclude] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -254,7 +254,7 @@ Set `include` to match request bodies to be included or `exclude` to match reque ```js [include] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -269,7 +269,7 @@ export default { ```js [exclude] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -293,7 +293,7 @@ Set `include` to match responses to be included or `exclude` to match responses ```js [include] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -308,7 +308,7 @@ export default { ```js [exclude] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -330,7 +330,7 @@ If you only want to exclude orphaned resources, set `orphans` to `false`. This i ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -348,7 +348,7 @@ For performance reasons, we don't preserve the original order when filtering out ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] filters: { // [!code ++] @@ -377,7 +377,7 @@ You may want all enums to be reusable. This is because only root enums are typic ```js [root] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] transforms: { // [!code ++] @@ -390,7 +390,7 @@ export default { ```js [inline] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] transforms: { // [!code ++] @@ -414,7 +414,7 @@ Your schemas might contain read-only or write-only fields. Using such schemas di ```js [default] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] transforms: { // [!code ++] @@ -430,7 +430,7 @@ export default { ```js [disabled] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] transforms: { // [!code ++] @@ -458,7 +458,7 @@ You can provide custom pagination keywords using `pagination.keywords`. import { defaultPaginationKeywords } from '@hey-api/openapi-ts'; export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] pagination: { // [!code ++] @@ -471,7 +471,7 @@ export default { ```js [override] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', parser: { // [!code ++] pagination: { // [!code ++] diff --git a/docs/openapi-ts/get-started.md b/docs/openapi-ts/get-started.md index 1f39321152..6acde1d824 100644 --- a/docs/openapi-ts/get-started.md +++ b/docs/openapi-ts/get-started.md @@ -32,9 +32,7 @@ Launch demo The fastest way to use `@hey-api/openapi-ts` is via npx ```sh -npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ - -o src/client +npx @hey-api/openapi-ts -i hey-api/backend -o src/client ``` Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](/openapi-ts/output) page. @@ -99,7 +97,7 @@ You can also generate output programmatically by importing `@hey-api/openapi-ts` import { createClient } from '@hey-api/openapi-ts'; createClient({ - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }); ``` diff --git a/docs/openapi-ts/integrations.md b/docs/openapi-ts/integrations.md index ddc5b76096..4c945cbf9b 100644 --- a/docs/openapi-ts/integrations.md +++ b/docs/openapi-ts/integrations.md @@ -96,9 +96,7 @@ You can generate clients from public projects or any private projects you can ac ::: code-group ```sh [Hey API] -npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ - -o src/client +npx @hey-api/openapi-ts -i hey-api/backend -o src/client ``` ```sh [OpenAPI TypeScript] diff --git a/docs/openapi-ts/migrating.md b/docs/openapi-ts/migrating.md index b0ac30d3de..f3b983eb93 100644 --- a/docs/openapi-ts/migrating.md +++ b/docs/openapi-ts/migrating.md @@ -17,7 +17,7 @@ This release adds support for Zod 4 and Zod Mini. By default, the `zod` plugin w ```js [Zod 3] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -31,7 +31,7 @@ export default { ```js [Zod Mini] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -99,7 +99,7 @@ Clients can now validate both request and response data. As a result, passing a ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -212,7 +212,7 @@ When generating class-based SDKs, we now try to infer the ideal structure using ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -232,7 +232,7 @@ This option has been renamed to `sdk.classNameBuilder` to better represent its f ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -266,7 +266,7 @@ export default { }, }, include: '^(#/components/schemas/foo|#/paths/api/v1/foo/get)$', // [!code --] - path: 'https://get.heyapi.dev/hey-api/backend', + path: 'hey-api/backend', // sign up at app.heyapi.dev }, output: 'src/client', plugins: ['@hey-api/client-fetch'], @@ -286,7 +286,7 @@ export default { exclude: ['foo'], // [!code ++] }, }, - path: 'https://get.heyapi.dev/hey-api/backend', + path: 'hey-api/backend', // sign up at app.heyapi.dev }, output: 'src/client', plugins: ['@hey-api/client-fetch'], @@ -303,7 +303,7 @@ This release introduces functionality related to your `tsconfig.json` file. The ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { path: 'src/client', tsConfigPath: 'off', // [!code ++] @@ -319,7 +319,7 @@ Starting with v0.66.0, `@hey-api/typescript` will generate separate types for pa ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -348,7 +348,7 @@ You can use this option to configure the default base URL for the generated clie ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { @@ -368,7 +368,7 @@ Clients are now plugins generating their own `client.gen.ts` file. There's no mi ```js export default { client: '@hey-api/client-fetch', // [!code --] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: ['@hey-api/client-fetch'], // [!code ++] }; @@ -389,7 +389,7 @@ This SDK configuration option has been moved to the client plugins where applica ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { @@ -414,7 +414,7 @@ Formerly known as the experimental parser, this is now the default parser. This export default { client: '@hey-api/client-fetch', experimentalParser: false, // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -456,7 +456,7 @@ When generating SDKs, you now have to specify `transformer` in order to modify r ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -482,7 +482,7 @@ You can now configure different log levels. As part of this feature, we had to i export default { client: '@hey-api/client-fetch', debug: true, // [!code --] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev logs: { level: 'debug', // [!code ++] }, @@ -498,7 +498,7 @@ export default { export default { client: '@hey-api/client-fetch', experimentalParser: true, - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -534,7 +534,7 @@ By default, the `output.path` folder will be emptied on every run. To preserve t ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { clean: false, // [!code ++] path: 'src/client', @@ -550,7 +550,7 @@ export default { export default { client: '@hey-api/client-fetch', experimentalParser: true, - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -591,7 +591,7 @@ This is a breaking change since in the previous versions, inline enums were alwa export default { client: '@hey-api/client-fetch', experimentalParser: true, - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -633,7 +633,7 @@ export default { experimentalParser: true, input: { include: '^(#/components/schemas/foo|#/paths/api/v1/foo/get)$', // [!code ++] - path: 'https://get.heyapi.dev/hey-api/backend', + path: 'hey-api/backend', // sign up at app.heyapi.dev }, output: 'src/client', }; @@ -658,7 +658,7 @@ Previously, you could explicitly disable export of certain artifacts using the ` ```js [shorthand] export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', schemas: false, // [!code --] plugins: ['@hey-api/types', '@hey-api/services'], // [!code ++] @@ -668,7 +668,7 @@ export default { ```js [*.export] export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', schemas: { export: false, // [!code --] @@ -686,7 +686,7 @@ Each plugin definition contains a `name` field. This was conflicting with the `s ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', schemas: { name: (name) => `${name}Schema`, // [!code --] @@ -708,7 +708,7 @@ Previously, you could use a string value as a shorthand for the `services.includ ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', services: '^MySchema', // [!code --] plugins: [ @@ -728,7 +728,7 @@ Each plugin definition contains a `name` field. This was conflicting with the `s ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', services: { name: '{{name}}Service', // [!code --] @@ -750,7 +750,7 @@ Previously, you could set `types.dates` to a boolean or a string value, dependin ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', types: { dates: 'types+transform', // [!code --] @@ -772,7 +772,7 @@ Previously, you could use a string value as a shorthand for the `types.include` ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', types: '^MySchema', // [!code --] plugins: [ @@ -792,7 +792,7 @@ Each plugin definition contains a `name` field. This was conflicting with the `t ```js export default { client: '@hey-api/client-fetch', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', types: { name: 'PascalCase', // [!code --] @@ -815,7 +815,7 @@ Previously, generated schemas would have their definition names prefixed with `$ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', schemas: { name: (name) => `$${name}`, // [!code ++] @@ -833,7 +833,7 @@ Legacy clients were renamed to signal they are deprecated more clearly. To conti export default { client: 'fetch', // [!code --] client: 'legacy/fetch', // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -842,7 +842,7 @@ export default { export default { client: 'axios', // [!code --] client: 'legacy/axios', // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -851,7 +851,7 @@ export default { export default { client: 'angular', // [!code --] client: 'legacy/angular', // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -860,7 +860,7 @@ export default { export default { client: 'node', // [!code --] client: 'legacy/node', // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -869,7 +869,7 @@ export default { export default { client: 'xhr', // [!code --] client: 'legacy/xhr', // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -915,7 +915,7 @@ Client now has to be explicitly specified and `@hey-api/openapi-ts` will no long ```js export default { client: 'fetch', // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -930,7 +930,7 @@ The `services.methodNameBuilder()` function now provides a single `operation` ar import { createClient } from '@hey-api/openapi-ts'; createClient({ - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', services: { methodNameBuilder: (service, name) => name, // [!code --] @@ -965,7 +965,7 @@ If you want to preserve the old behavior, you can set the newly exposed `service ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', services: { asClass: true, // [!code ++] @@ -982,7 +982,7 @@ export default { ```js export default { client: 'axios', // [!code ++] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -996,7 +996,7 @@ This config option has been moved. You can now configure formatter using the `ou ```js export default { format: 'prettier', // [!code --] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { format: 'prettier', // [!code ++] path: 'src/client', @@ -1010,7 +1010,7 @@ This config option has been moved. You can now configure linter using the `outpu ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev lint: 'eslint', // [!code --] output: { lint: 'eslint', // [!code ++] @@ -1057,7 +1057,7 @@ This config option has been moved. You can now configure enums using the `types. ```js export default { enums: 'javascript', // [!code --] - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', types: { enums: 'javascript', // [!code ++] @@ -1074,7 +1074,7 @@ This config option has changed. You now need to specify a value (`biome` or `pre ```js{2} export default { format: 'prettier', - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', } ``` @@ -1085,7 +1085,7 @@ This config option has changed. You now need to specify a value (`biome` or `esl ```js{3} export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev lint: 'eslint', output: 'src/client', } @@ -1097,7 +1097,7 @@ This config option has been moved. You can now configure it using the `services. ```js{5} export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', services: { operationId: true, @@ -1113,7 +1113,7 @@ This config option has been removed. You can now transform service names using t ```js{5} export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', services: { name: 'myAwesome{{name}}Api', @@ -1127,7 +1127,7 @@ This config option has been removed. You can now configure service responses usi ```js{5} export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', services: { response: 'body', @@ -1141,7 +1141,7 @@ This config option has been removed. You can now configure date type using the ` ```js{5} export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', type: { dates: true, @@ -1170,7 +1170,7 @@ You can now choose to export types using the PascalCase naming convention. ```js{5} export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', types: { name: 'PascalCase', diff --git a/docs/openapi-ts/output.md b/docs/openapi-ts/output.md index b0cbc9f7f9..6acd16d8ce 100644 --- a/docs/openapi-ts/output.md +++ b/docs/openapi-ts/output.md @@ -61,7 +61,7 @@ If you're not importing artifacts from the index file, you can skip generating i ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { indexFile: false, // [!code ++] path: 'src/client', @@ -75,7 +75,7 @@ You can choose which files should be re-exported by setting the `exportFromIndex ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/output/json-schema.md b/docs/openapi-ts/output/json-schema.md index b1f6dc83cc..7abc2609f9 100644 --- a/docs/openapi-ts/output/json-schema.md +++ b/docs/openapi-ts/output/json-schema.md @@ -15,7 +15,7 @@ You can modify the contents of `schemas.gen.ts` by configuring the `@hey-api/sch ```js [json] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -29,7 +29,7 @@ export default { ```js [form] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -43,7 +43,7 @@ export default { ```js [disabled] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/output/sdk.md b/docs/openapi-ts/output/sdk.md index 6ff6c77bfb..4a6f785a3c 100644 --- a/docs/openapi-ts/output/sdk.md +++ b/docs/openapi-ts/output/sdk.md @@ -27,7 +27,7 @@ You can modify the contents of `sdk.gen.ts` by configuring the `@hey-api/sdk` pl ```js [flat] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -41,7 +41,7 @@ export default { ```js [class] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -55,7 +55,7 @@ export default { ```js [none] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ '@hey-api/typescript', @@ -152,7 +152,7 @@ For a more granular approach, add a validator plugin and set `sdk.validator` to ```js [sdk] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { @@ -165,7 +165,7 @@ export default { ```js [validator] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { @@ -188,7 +188,7 @@ You can choose to validate only requests or responses. ```js [requests] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { @@ -203,7 +203,7 @@ export default { ```js [responses] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ { diff --git a/docs/openapi-ts/output/typescript.md b/docs/openapi-ts/output/typescript.md index 84bfe0ecb7..92a87a333b 100644 --- a/docs/openapi-ts/output/typescript.md +++ b/docs/openapi-ts/output/typescript.md @@ -13,7 +13,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/typescript` to y ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -86,7 +86,7 @@ By default, `@hey-api/typescript` will emit enums only as types. You may want to ```js [disabled] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -100,7 +100,7 @@ export default { ```js [javascript] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -114,7 +114,7 @@ export default { ```js [typescript] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/angular.md b/docs/openapi-ts/plugins/angular.md index 2a204ad088..9e269f58b8 100644 --- a/docs/openapi-ts/plugins/angular.md +++ b/docs/openapi-ts/plugins/angular.md @@ -43,7 +43,7 @@ In your [configuration](/openapi-ts/get-started), add `@angular/common` to your ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -74,7 +74,7 @@ export const addPetRequest = (options) => ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -101,7 +101,7 @@ export const addPetResource = (options) => ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/angular/v19.md b/docs/openapi-ts/plugins/angular/v19.md index 4ebc13eafd..7806caf9cd 100644 --- a/docs/openapi-ts/plugins/angular/v19.md +++ b/docs/openapi-ts/plugins/angular/v19.md @@ -43,7 +43,7 @@ In your [configuration](/openapi-ts/get-started), add `@angular/common` to your ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -74,7 +74,7 @@ export const addPetRequest = (options) => ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -101,7 +101,7 @@ export const addPetResource = (options) => ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/custom.md b/docs/openapi-ts/plugins/custom.md index a63ce8397c..8cd3dc70be 100644 --- a/docs/openapi-ts/plugins/custom.md +++ b/docs/openapi-ts/plugins/custom.md @@ -155,7 +155,7 @@ Once we're satisfied with our plugin, we can register it in the [configuration]( import { defineConfig } from 'path/to/my-plugin'; export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ defineConfig({ diff --git a/docs/openapi-ts/plugins/fastify.md b/docs/openapi-ts/plugins/fastify.md index 6729683cd5..dcf04053b9 100644 --- a/docs/openapi-ts/plugins/fastify.md +++ b/docs/openapi-ts/plugins/fastify.md @@ -42,7 +42,7 @@ In your [configuration](/openapi-ts/get-started), add `fastify` to your plugins ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -82,7 +82,7 @@ fastify.register(glue, { serviceHandlers }); ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/tanstack-query.md b/docs/openapi-ts/plugins/tanstack-query.md index bea22e7019..3ac4edcb29 100644 --- a/docs/openapi-ts/plugins/tanstack-query.md +++ b/docs/openapi-ts/plugins/tanstack-query.md @@ -43,7 +43,7 @@ In your [configuration](/openapi-ts/get-started), add TanStack Query to your plu ```js [react] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -54,7 +54,7 @@ export default { ```js [vue] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -65,7 +65,7 @@ export default { ```js [angular] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -76,7 +76,7 @@ export default { ```js [svelte] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -87,7 +87,7 @@ export default { ```js [solid] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -120,7 +120,7 @@ const { data, error } = useQuery({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -153,7 +153,7 @@ queryOptions({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -179,7 +179,7 @@ Query keys contain normalized SDK function parameters and additional metadata. const queryKey = [ { _id: 'getPetById', - baseUrl: 'https://get.heyapi.dev', + baseUrl: 'https://app.heyapi.dev', path: { petId: 1, }, @@ -189,7 +189,7 @@ const queryKey = [ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -213,7 +213,7 @@ You can include operation tags in your query keys by setting `tags` to `true`. T const queryKey = [ { _id: 'getPetById', - baseUrl: 'https://get.heyapi.dev', + baseUrl: 'https://app.heyapi.dev', path: { petId: 1, }, @@ -224,7 +224,7 @@ const queryKey = [ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -256,7 +256,7 @@ const { queryKey } = getPetByIdOptions({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -284,7 +284,7 @@ const queryKey = getPetByIdQueryKey({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -320,7 +320,7 @@ const { data, error } = useInfiniteQuery({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -353,7 +353,7 @@ infiniteQueryOptions({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -380,7 +380,7 @@ const queryKey = [ { _id: 'getPetById', _infinite: true, - baseUrl: 'https://get.heyapi.dev', + baseUrl: 'https://app.heyapi.dev', path: { petId: 1, }, @@ -390,7 +390,7 @@ const queryKey = [ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -415,7 +415,7 @@ const queryKey = [ { _id: 'getPetById', _infinite: true, - baseUrl: 'https://get.heyapi.dev', + baseUrl: 'https://app.heyapi.dev', path: { petId: 1, }, @@ -426,7 +426,7 @@ const queryKey = [ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -458,7 +458,7 @@ const { queryKey } = getPetByIdInfiniteOptions({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -486,7 +486,7 @@ const queryKey = getPetByIdInfiniteQueryKey({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -525,7 +525,7 @@ addPet.mutate({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -558,7 +558,7 @@ const mutationOptions = { ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/valibot.md b/docs/openapi-ts/plugins/valibot.md index d36977f5de..c72fb570c8 100644 --- a/docs/openapi-ts/plugins/valibot.md +++ b/docs/openapi-ts/plugins/valibot.md @@ -31,7 +31,7 @@ In your [configuration](/openapi-ts/get-started), add `valibot` to your plugins ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -46,7 +46,7 @@ To add data validators to your SDKs, set `sdk.validator` to `true`. ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -88,7 +88,7 @@ const vData = v.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -127,7 +127,7 @@ const vResponse = v.union([ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -159,7 +159,7 @@ const vBar = v.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -192,7 +192,7 @@ export const vFoo = v.pipe( ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/zod.md b/docs/openapi-ts/plugins/zod.md index c6101d7d6f..a918d3af05 100644 --- a/docs/openapi-ts/plugins/zod.md +++ b/docs/openapi-ts/plugins/zod.md @@ -31,7 +31,7 @@ In your [configuration](/openapi-ts/get-started), add `zod` to your plugins and ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -46,7 +46,7 @@ To add data validators to your SDKs, set `sdk.validator` to `true`. ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -88,7 +88,7 @@ const zData = z.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -127,7 +127,7 @@ const zResponse = z.union([ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -159,7 +159,7 @@ const zBar = z.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -189,7 +189,7 @@ export const zFoo = z.string().register(z.globalRegistry, { ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -215,7 +215,7 @@ export type ResponseZodType = z.infer; ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/zod/mini.md b/docs/openapi-ts/plugins/zod/mini.md index 6147e8cbd1..d82f09a8eb 100644 --- a/docs/openapi-ts/plugins/zod/mini.md +++ b/docs/openapi-ts/plugins/zod/mini.md @@ -31,7 +31,7 @@ In your [configuration](/openapi-ts/get-started), add `zod` to your plugins and ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -49,7 +49,7 @@ To add data validators to your SDKs, set `sdk.validator` to `true`. ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -91,7 +91,7 @@ const zData = z.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -130,7 +130,7 @@ const zResponse = z.union([ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -162,7 +162,7 @@ const zBar = z.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -192,7 +192,7 @@ export const zFoo = z.string().register(z.globalRegistry, { ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -218,7 +218,7 @@ export type ResponseZodType = z.infer; ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/plugins/zod/v3.md b/docs/openapi-ts/plugins/zod/v3.md index b5e37930aa..2b723545b8 100644 --- a/docs/openapi-ts/plugins/zod/v3.md +++ b/docs/openapi-ts/plugins/zod/v3.md @@ -31,7 +31,7 @@ In your [configuration](/openapi-ts/get-started), add `zod` to your plugins and ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -49,7 +49,7 @@ To add data validators to your SDKs, set `sdk.validator` to `true`. ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -91,7 +91,7 @@ const zData = z.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -130,7 +130,7 @@ const zResponse = z.union([ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -162,7 +162,7 @@ const zBar = z.object({ ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -190,7 +190,7 @@ export const zFoo = z.string().describe('Additional metadata'); ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -216,7 +216,7 @@ export type ResponseZodType = z.infer; ```js [config] export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/docs/openapi-ts/transformers.md b/docs/openapi-ts/transformers.md index 5a892f3453..13cc40331d 100644 --- a/docs/openapi-ts/transformers.md +++ b/docs/openapi-ts/transformers.md @@ -33,7 +33,7 @@ In your [configuration](/openapi-ts/get-started), add `@hey-api/transformers` to ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -48,7 +48,7 @@ To automatically transform response data in your SDKs, set `sdk.transformer` to ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -67,7 +67,7 @@ To convert date strings into `Date` objects, use the `dates` configuration optio ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/examples/openapi-ts-openai/src/App.tsx b/examples/openapi-ts-openai/src/App.tsx index a24a7fb480..1cc0b0ec79 100644 --- a/examples/openapi-ts-openai/src/App.tsx +++ b/examples/openapi-ts-openai/src/App.tsx @@ -36,16 +36,21 @@ function App() { const [isRequiredNameError] = useState(false); const onCreateResponse = async (values: FormData) => { - const response = await sdk.responses.create({ + const stream = await sdk.responses.create({ input: values.get('input') as string, model: 'gpt-5-nano', + stream: true, }); - console.log(response.output_text); + for await (const event of stream) { + console.log(event); + } + const { data, error } = await client.createResponse({ body: { input: values.get('input') as string, model: 'gpt-5-nano', + stream: true, }, }); if (error) { diff --git a/packages/openapi-ts-tests/main/test/openapi-ts.config.ts b/packages/openapi-ts-tests/main/test/openapi-ts.config.ts index 54d7577289..359d4862ee 100644 --- a/packages/openapi-ts-tests/main/test/openapi-ts.config.ts +++ b/packages/openapi-ts-tests/main/test/openapi-ts.config.ts @@ -39,9 +39,10 @@ export default defineConfig(() => { // 'full.yaml', // 'validators-circular-ref.json', ), - // path: 'http://localhost:4000/', - // path: 'https://get.heyapi.dev/', + // path: 'hey-api/backend', + // path: 'hey-api/backend?branch=main&version=1.0.0', // path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0', + // path: 'http://localhost:4000/', // path: 'http://localhost:8000/openapi.json', // path: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json', // path: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', diff --git a/packages/openapi-ts/CHANGELOG.md b/packages/openapi-ts/CHANGELOG.md index 0988b42072..249a8b0d71 100644 --- a/packages/openapi-ts/CHANGELOG.md +++ b/packages/openapi-ts/CHANGELOG.md @@ -116,7 +116,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -130,7 +130,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -261,7 +261,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -438,7 +438,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -625,7 +625,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { path: 'src/client', tsConfigPath: 'off', @@ -717,7 +717,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins @@ -2854,7 +2854,7 @@ - Better handling of services without tags - Updated dependencies , // [!code --] - path: 'https://get.heyapi.dev/hey-api/backend', + path: 'hey-api/backend', // sign up at app.heyapi.dev }, output: 'src/client', plugins: ['@hey-api/client-fetch'], @@ -2926,7 +2926,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: { path: 'src/client', tsConfigPath: 'off', @@ -3018,7 +3018,7 @@ ```js export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', plugins: [ // ...other plugins diff --git a/packages/openapi-ts/README.md b/packages/openapi-ts/README.md index c7f6966c02..29a8427d4a 100644 --- a/packages/openapi-ts/README.md +++ b/packages/openapi-ts/README.md @@ -144,9 +144,7 @@ Help Hey API stay around for the long haul by becoming a [sponsor](https://githu The fastest way to use `@hey-api/openapi-ts` is via npx ```sh -npx @hey-api/openapi-ts \ - -i https://get.heyapi.dev/hey-api/backend \ - -o src/client +npx @hey-api/openapi-ts -i hey-api/backend -o src/client ``` Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/openapi-ts/output) page. @@ -213,7 +211,7 @@ You can also generate output programmatically by importing `@hey-api/openapi-ts` import { createClient } from '@hey-api/openapi-ts'; createClient({ - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }); ``` @@ -228,7 +226,7 @@ createClient({ import { defineConfig } from '@hey-api/openapi-ts'; export default defineConfig({ - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }); ``` @@ -238,7 +236,7 @@ export default defineConfig({ ```js /** @type {import('@hey-api/openapi-ts').UserConfig} */ module.exports = { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` @@ -248,7 +246,7 @@ module.exports = { ```js /** @type {import('@hey-api/openapi-ts').UserConfig} */ export default { - input: 'https://get.heyapi.dev/hey-api/backend', + input: 'hey-api/backend', // sign up at app.heyapi.dev output: 'src/client', }; ``` diff --git a/packages/openapi-ts/src/config/__tests__/input.test.ts b/packages/openapi-ts/src/config/__tests__/input.test.ts index 96f44d8fc2..1276be0bbe 100644 --- a/packages/openapi-ts/src/config/__tests__/input.test.ts +++ b/packages/openapi-ts/src/config/__tests__/input.test.ts @@ -96,7 +96,7 @@ describe('input config', () => { }; const result = getInput(userConfig); - expect(result.path).toBe('https://get.heyapi.dev'); + expect(result.path).toBe('https://get.heyapi.dev/myorg/myproject'); }); it('should handle object input (existing functionality)', () => { @@ -178,7 +178,9 @@ describe('input config', () => { output: 'src/client', }; - expect(() => getInput(userConfig)).toThrow('Invalid ReadMe input format'); + expect(() => getInput(userConfig)).toThrow( + 'Invalid ReadMe shorthand format', + ); }); it('should throw error for invalid ReadMe UUID', () => { @@ -187,7 +189,9 @@ describe('input config', () => { output: 'src/client', }; - expect(() => getInput(userConfig)).toThrow('Invalid ReadMe input format'); + expect(() => getInput(userConfig)).toThrow( + 'Invalid ReadMe shorthand format', + ); }); it('should throw error for invalid ReadMe format in object input', () => { @@ -198,7 +202,9 @@ describe('input config', () => { output: 'src/client', }; - expect(() => getInput(userConfig)).toThrow('Invalid ReadMe input format'); + expect(() => getInput(userConfig)).toThrow( + 'Invalid ReadMe shorthand format', + ); }); }); }); diff --git a/packages/openapi-ts/src/config/input.ts b/packages/openapi-ts/src/config/input.ts index 0b54e7802b..c7a5bec31a 100644 --- a/packages/openapi-ts/src/config/input.ts +++ b/packages/openapi-ts/src/config/input.ts @@ -1,5 +1,10 @@ import type { Config, UserConfig } from '../types/config'; -import { isReadmeInput, transformReadmeInput } from '../utils/readme'; +import type { Input } from '../types/input'; +import { + heyApiRegistryBaseUrl, + inputToHeyApiPath, +} from '../utils/input/heyApi'; +import { inputToReadmePath } from '../utils/input/readme'; const defaultWatch: Config['input']['watch'] = { enabled: false, @@ -39,12 +44,7 @@ export const getInput = (userConfig: UserConfig): Config['input'] => { }; if (typeof userConfig.input === 'string') { - // Handle ReadMe input format transformation - if (isReadmeInput(userConfig.input)) { - input.path = transformReadmeInput(userConfig.input); - } else { - input.path = userConfig.input; - } + input.path = userConfig.input; } else if ( userConfig.input && (userConfig.input.path !== undefined || @@ -53,15 +53,10 @@ export const getInput = (userConfig: UserConfig): Config['input'] => { // @ts-expect-error input = { ...input, - path: 'https://get.heyapi.dev', + path: heyApiRegistryBaseUrl, ...userConfig.input, }; - // Handle ReadMe input format transformation when path is specified - if (typeof input.path === 'string' && isReadmeInput(input.path)) { - input.path = transformReadmeInput(input.path); - } - // watch only remote files if (input.watch !== undefined) { input.watch = getWatch(input); @@ -73,6 +68,23 @@ export const getInput = (userConfig: UserConfig): Config['input'] => { }; } + if (typeof input.path === 'string') { + if (input.path.startsWith('readme:')) { + input.path = inputToReadmePath(input.path); + } else if (!input.path.startsWith('.')) { + if (input.path.startsWith(heyApiRegistryBaseUrl)) { + input.path = input.path.slice(heyApiRegistryBaseUrl.length + 1); + input.path = inputToHeyApiPath(input as Input & { path: string }); + } else { + const parts = input.path.split('/'); + const cleanParts = parts.filter(Boolean); + if (parts.length === 2 && cleanParts.length === 2) { + input.path = inputToHeyApiPath(input as Input & { path: string }); + } + } + } + } + if ( userConfig.watch !== undefined && input.watch.enabled === defaultWatch.enabled && diff --git a/packages/openapi-ts/src/createClient.ts b/packages/openapi-ts/src/createClient.ts index b5e5da2302..fc28ce4bb3 100644 --- a/packages/openapi-ts/src/createClient.ts +++ b/packages/openapi-ts/src/createClient.ts @@ -14,11 +14,12 @@ import type { Config } from './types/config'; import type { WatchValues } from './types/types'; import { isLegacyClient, legacyNameFromConfig } from './utils/config'; import type { Templates } from './utils/handlebars'; +import { heyApiRegistryBaseUrl } from './utils/input/heyApi'; import type { Logger } from './utils/logger'; import { postProcessClient } from './utils/postprocess'; -const isPlatformPath = (path: string) => - path.startsWith('https://get.heyapi.dev'); +const isHeyApiRegistryPath = (path: string) => + path.startsWith(heyApiRegistryBaseUrl); // || path.startsWith('http://localhost:4000') export const compileInputPath = (input: Omit) => { @@ -38,7 +39,7 @@ export const compileInputPath = (input: Omit) => { if ( input.path && - (typeof input.path !== 'string' || !isPlatformPath(input.path)) + (typeof input.path !== 'string' || !isHeyApiRegistryPath(input.path)) ) { result.path = input.path; return result; @@ -134,11 +135,11 @@ const logInputPath = (inputPath: ReturnType) => { const baseString = colors.cyan('Generating from'); if (typeof inputPath.path === 'string') { - const baseInput = isPlatformPath(inputPath.path) + const baseInput = isHeyApiRegistryPath(inputPath.path) ? `${inputPath.organization ?? ''}/${inputPath.project ?? ''}` : inputPath.path; console.log(`⏳ ${baseString} ${baseInput}`); - if (isPlatformPath(inputPath.path)) { + if (isHeyApiRegistryPath(inputPath.path)) { if (inputPath.branch) { console.log( `${colors.gray('branch:')} ${colors.green(inputPath.branch)}`, diff --git a/packages/openapi-ts/src/types/config.d.ts b/packages/openapi-ts/src/types/config.d.ts index badda21182..22f034e0ce 100644 --- a/packages/openapi-ts/src/types/config.d.ts +++ b/packages/openapi-ts/src/types/config.d.ts @@ -18,10 +18,10 @@ export interface UserConfig { */ dryRun?: boolean; /** - * Path to the OpenAPI specification. This can be either: - * - local file - * - remote path - * - ReadMe API Registry UUID (full and simplified formats) + * Path to the OpenAPI specification. This can be: + * - path + * - URL + * - API registry shorthand * * Both JSON and YAML file formats are supported. You can also pass the parsed * object directly if you're fetching the file yourself. @@ -30,6 +30,7 @@ export interface UserConfig { */ input: | `https://get.heyapi.dev/${string}/${string}` + | `${string}/${string}` | `readme:@${string}/${string}#${string}` | `readme:${string}` | (string & {}) diff --git a/packages/openapi-ts/src/types/input.d.ts b/packages/openapi-ts/src/types/input.d.ts index 3e68a00463..0f409aa04f 100644 --- a/packages/openapi-ts/src/types/input.d.ts +++ b/packages/openapi-ts/src/types/input.d.ts @@ -36,16 +36,17 @@ export type Input = { */ organization?: string; /** - * Path to the OpenAPI specification. This can be either: - * - local file - * - remote path - * - ReadMe API Registry UUID (full and simplified formats) + * Path to the OpenAPI specification. This can be: + * - path + * - URL + * - API registry shorthand * * Both JSON and YAML file formats are supported. You can also pass the parsed * object directly if you're fetching the file yourself. */ path?: | `https://get.heyapi.dev/${string}/${string}` + | `${string}/${string}` | `readme:@${string}/${string}#${string}` | `readme:${string}` | (string & {}) diff --git a/packages/openapi-ts/src/utils/__tests__/readme.test.ts b/packages/openapi-ts/src/utils/__tests__/readme.test.ts deleted file mode 100644 index a0dc36ab39..0000000000 --- a/packages/openapi-ts/src/utils/__tests__/readme.test.ts +++ /dev/null @@ -1,199 +0,0 @@ -import { describe, expect, it } from 'vitest'; - -import { - getReadmeApiUrl, - isReadmeInput, - parseReadmeInput, - type ReadmeInput, - transformReadmeInput, -} from '../readme'; - -describe('readme utils', () => { - describe('isReadmeInput', () => { - it('should return true for valid ReadMe formats', () => { - expect(isReadmeInput('readme:abc123')).toBe(true); - expect(isReadmeInput('readme:@org/project#uuid123')).toBe(true); - expect(isReadmeInput('readme:test-uuid-with-hyphens')).toBe(true); - }); - - it('should return false for non-ReadMe inputs', () => { - expect(isReadmeInput('https://example.com')).toBe(false); - expect(isReadmeInput('./local-file.yaml')).toBe(false); - expect(isReadmeInput('random-string')).toBe(false); - expect(isReadmeInput('')).toBe(false); - expect(isReadmeInput('readme')).toBe(false); - expect(isReadmeInput('readmeabc123')).toBe(false); - }); - - it('should handle non-string inputs', () => { - expect(isReadmeInput(123 as any)).toBe(false); - expect(isReadmeInput(null as any)).toBe(false); - expect(isReadmeInput(undefined as any)).toBe(false); - expect(isReadmeInput({} as any)).toBe(false); - }); - }); - - describe('parseReadmeInput', () => { - it('should parse simple UUID format', () => { - const result = parseReadmeInput('readme:abc123'); - expect(result).toEqual({ uuid: 'abc123' }); - }); - - it('should parse UUID with hyphens', () => { - const result = parseReadmeInput('readme:test-uuid-123'); - expect(result).toEqual({ uuid: 'test-uuid-123' }); - }); - - it('should parse full format with organization and project', () => { - const result = parseReadmeInput('readme:@myorg/myproject#uuid123'); - expect(result).toEqual({ - organization: 'myorg', - project: 'myproject', - uuid: 'uuid123', - }); - }); - - it('should parse organization and project with hyphens', () => { - const result = parseReadmeInput('readme:@my-org/my-project#test-uuid'); - expect(result).toEqual({ - organization: 'my-org', - project: 'my-project', - uuid: 'test-uuid', - }); - }); - - it('should throw error for invalid formats', () => { - expect(() => parseReadmeInput('readme:')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => parseReadmeInput('readme:@org')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => parseReadmeInput('readme:@org/project')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => parseReadmeInput('readme:@org/project#')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => parseReadmeInput('https://example.com')).toThrow( - 'Invalid ReadMe input format', - ); - }); - - it('should throw error for invalid UUID characters', () => { - expect(() => parseReadmeInput('readme:abc@123')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => parseReadmeInput('readme:abc/123')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => parseReadmeInput('readme:abc#123')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => parseReadmeInput('readme:abc 123')).toThrow( - 'Invalid ReadMe input format', - ); - }); - - it('should handle empty UUID', () => { - expect(() => parseReadmeInput('readme:@org/project#')).toThrow( - 'Invalid ReadMe input format', - ); - }); - }); - - describe('getReadmeApiUrl', () => { - it('should generate correct API URL', () => { - expect(getReadmeApiUrl('abc123')).toBe( - 'https://dash.readme.com/api/v1/api-registry/abc123', - ); - expect(getReadmeApiUrl('test-uuid-with-hyphens')).toBe( - 'https://dash.readme.com/api/v1/api-registry/test-uuid-with-hyphens', - ); - }); - }); - - describe('transformReadmeInput', () => { - it('should transform simple UUID format to API URL', () => { - const result = transformReadmeInput('readme:abc123'); - expect(result).toBe('https://dash.readme.com/api/v1/api-registry/abc123'); - }); - - it('should transform full format to API URL', () => { - const result = transformReadmeInput('readme:@myorg/myproject#uuid123'); - expect(result).toBe( - 'https://dash.readme.com/api/v1/api-registry/uuid123', - ); - }); - - it('should throw error for invalid inputs', () => { - expect(() => transformReadmeInput('invalid')).toThrow( - 'Invalid ReadMe input format', - ); - expect(() => transformReadmeInput('readme:')).toThrow( - 'Invalid ReadMe input format', - ); - }); - }); - - describe('integration scenarios', () => { - const validInputs: Array<{ expected: ReadmeInput; input: string }> = [ - { expected: { uuid: 'simple123' }, input: 'readme:simple123' }, - { - expected: { uuid: 'uuid-with-hyphens' }, - input: 'readme:uuid-with-hyphens', - }, - { expected: { uuid: 'UUID123' }, input: 'readme:UUID123' }, - { - expected: { organization: 'org', project: 'proj', uuid: 'uuid' }, - input: 'readme:@org/proj#uuid', - }, - { - expected: { - organization: 'my-org', - project: 'my-project', - uuid: 'my-uuid', - }, - input: 'readme:@my-org/my-project#my-uuid', - }, - ]; - - it.each(validInputs)( - 'should handle $input correctly', - ({ expected, input }) => { - expect(isReadmeInput(input)).toBe(true); - expect(parseReadmeInput(input)).toEqual(expected); - expect(transformReadmeInput(input)).toBe( - `https://dash.readme.com/api/v1/api-registry/${expected.uuid}`, - ); - }, - ); - - const invalidInputs = [ - 'readme:', - 'readme:@', - 'readme:@org', - 'readme:@org/', - 'readme:@org/proj', - 'readme:@org/proj#', - 'readme:uuid with spaces', - 'readme:uuid@invalid', - 'readme:uuid/invalid', - 'readme:uuid#invalid', - 'https://example.com', - './local-file.yaml', - 'random-string', - '', - ]; - - it.each(invalidInputs)('should reject invalid input: %s', (input) => { - if (isReadmeInput(input)) { - expect(() => parseReadmeInput(input)).toThrow(); - } else { - expect(() => parseReadmeInput(input)).toThrow( - 'Invalid ReadMe input format', - ); - } - }); - }); -}); diff --git a/packages/openapi-ts/src/utils/input/__tests__/readme.test.ts b/packages/openapi-ts/src/utils/input/__tests__/readme.test.ts new file mode 100644 index 0000000000..0c524737f7 --- /dev/null +++ b/packages/openapi-ts/src/utils/input/__tests__/readme.test.ts @@ -0,0 +1,165 @@ +import { describe, expect, it } from 'vitest'; + +import { + getRegistryUrl, + inputToReadmePath, + type Parsed, + parseShorthand, +} from '../readme'; + +describe('readme utils', () => { + describe('parseShorthand', () => { + it('should parse simple UUID format', () => { + const result = parseShorthand('abc123'); + expect(result).toEqual({ uuid: 'abc123' }); + }); + + it('should parse UUID with hyphens', () => { + const result = parseShorthand('test-uuid-123'); + expect(result).toEqual({ uuid: 'test-uuid-123' }); + }); + + it('should parse full format with organization and project', () => { + const result = parseShorthand('@myorg/myproject#uuid123'); + expect(result).toEqual({ + organization: 'myorg', + project: 'myproject', + uuid: 'uuid123', + }); + }); + + it('should parse organization and project with hyphens', () => { + const result = parseShorthand('@my-org/my-project#test-uuid'); + expect(result).toEqual({ + organization: 'my-org', + project: 'my-project', + uuid: 'test-uuid', + }); + }); + + it('should throw error for invalid formats', () => { + expect(() => parseShorthand('')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => parseShorthand('@org')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => parseShorthand('@org/project')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => parseShorthand('@org/project#')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => parseShorthand('https://example.com')).toThrow( + 'Invalid ReadMe shorthand format', + ); + }); + + it('should throw error for invalid UUID characters', () => { + expect(() => parseShorthand('abc@123')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => parseShorthand('abc/123')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => parseShorthand('abc#123')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => parseShorthand('abc 123')).toThrow( + 'Invalid ReadMe shorthand format', + ); + }); + + it('should handle empty UUID', () => { + expect(() => parseShorthand('@org/project#')).toThrow( + 'Invalid ReadMe shorthand format', + ); + }); + }); + + describe('getRegistryUrl', () => { + it('should generate correct URL', () => { + expect(getRegistryUrl('abc123')).toBe( + 'https://dash.readme.com/api/v1/api-registry/abc123', + ); + expect(getRegistryUrl('test-uuid-with-hyphens')).toBe( + 'https://dash.readme.com/api/v1/api-registry/test-uuid-with-hyphens', + ); + }); + }); + + describe('inputToReadmePath', () => { + it('should transform simple UUID format to API URL', () => { + const result = inputToReadmePath('readme:abc123'); + expect(result).toBe('https://dash.readme.com/api/v1/api-registry/abc123'); + }); + + it('should transform full format to API URL', () => { + const result = inputToReadmePath('readme:@myorg/myproject#uuid123'); + expect(result).toBe( + 'https://dash.readme.com/api/v1/api-registry/uuid123', + ); + }); + + it('should throw error for invalid inputs', () => { + expect(() => inputToReadmePath('invalid')).toThrow( + 'Invalid ReadMe shorthand format', + ); + expect(() => inputToReadmePath('')).toThrow( + 'Invalid ReadMe shorthand format', + ); + }); + }); + + describe('integration scenarios', () => { + const validInputs: ReadonlyArray<{ expected: Parsed; input: string }> = [ + { expected: { uuid: 'simple123' }, input: 'simple123' }, + { + expected: { uuid: 'uuid-with-hyphens' }, + input: 'uuid-with-hyphens', + }, + { expected: { uuid: 'UUID123' }, input: 'UUID123' }, + { + expected: { organization: 'org', project: 'proj', uuid: 'uuid' }, + input: '@org/proj#uuid', + }, + { + expected: { + organization: 'my-org', + project: 'my-project', + uuid: 'my-uuid', + }, + input: '@my-org/my-project#my-uuid', + }, + ]; + + it.each(validInputs)( + 'should handle $input correctly', + ({ expected, input }) => { + expect(parseShorthand(input)).toEqual(expected); + expect(inputToReadmePath(`readme:${input}`)).toBe( + `https://dash.readme.com/api/v1/api-registry/${expected.uuid}`, + ); + }, + ); + + const invalidInputs = [ + '', + '@', + '@org', + '@org/', + '@org/proj', + '@org/proj#', + 'uuid with spaces', + 'uuid@invalid', + 'uuid/invalid', + 'uuid#invalid', + 'https://example.com', + './local-file.yaml', + ]; + + it.each(invalidInputs)('should reject invalid input: %s', (input) => { + expect(() => parseShorthand(input)).toThrow(); + }); + }); +}); diff --git a/packages/openapi-ts/src/utils/input/heyApi.ts b/packages/openapi-ts/src/utils/input/heyApi.ts new file mode 100644 index 0000000000..48fc2a925e --- /dev/null +++ b/packages/openapi-ts/src/utils/input/heyApi.ts @@ -0,0 +1,95 @@ +// Regular expression to match Hey API Registry input formats: + +import type { Input } from '../../types/input'; + +// - {organization}/{project}?{queryParams} +const registryRegExp = /^([\w-]+)\/([\w-]+)(?:\?([\w=&.-]*))?$/; + +export const heyApiRegistryBaseUrl = 'https://get.heyapi.dev'; + +/** + * Generates the Hey API Registry URL for a given UUID. + * + * @param organization - Organization slug + * @param project - Project slug + * @param queryParams - Optional query parameters + * @returns The full API registry URL + */ +export const getRegistryUrl = ( + organization: string, + project: string, + queryParams?: string, +): string => + `${heyApiRegistryBaseUrl}/${organization}/${project}${queryParams ? `?${queryParams}` : ''}`; + +export interface Parsed { + organization: string; + project: string; + queryParams?: string; +} + +/** + * Parses a Hey API input string and extracts components. + * + * @param input - Hey API configuration input + * @returns Parsed Hey API input components + * @throws Error if the input format is invalid + */ +export const parseShorthand = ( + input: Omit & { + path: string; + }, +): Parsed => { + let organization = input.organization; + let project = input.project; + let queryParams: string | undefined; + + if (input.path) { + const match = input.path.match(registryRegExp); + + if (!match) { + throw new Error( + `Invalid Hey API shorthand format. Expected "organization/project?queryParams" or "organization/project", received: ${input.path}`, + ); + } + + organization = match[1]; + project = match[2]; + queryParams = match[3]; + } + + if (!organization) { + throw new Error('The Hey API organization cannot be empty.'); + } + + if (!project) { + throw new Error('The Hey API organization cannot be empty.'); + } + + const result: Parsed = { + organization, + project, + queryParams, + }; + + return result; +}; + +/** + * Transforms a Hey API shorthand string to the corresponding API URL. + * + * @param input - Hey API configuration input + * @returns The Hey API Registry URL + */ +export const inputToHeyApiPath = ( + input: Omit & { + path: string; + }, +): string => { + const parsed = parseShorthand(input); + return getRegistryUrl( + parsed.organization, + parsed.project, + parsed.queryParams, + ); +}; diff --git a/packages/openapi-ts/src/utils/input/readme.ts b/packages/openapi-ts/src/utils/input/readme.ts new file mode 100644 index 0000000000..8a9c4f009f --- /dev/null +++ b/packages/openapi-ts/src/utils/input/readme.ts @@ -0,0 +1,64 @@ +// Regular expression to match ReadMe API Registry input formats: +// - @{organization}/{project}#{uuid} +// - {uuid} +const registryRegExp = /^(@([\w-]+)\/([\w\-.]+)#)?([\w-]+)$/; + +/** + * Generates the Hey API Registry URL for a given UUID. + * + * @param uuid - The Hey API Registry UUID + * @returns The full API registry URL + */ +export const getRegistryUrl = (uuid: string): string => + `https://dash.readme.com/api/v1/api-registry/${uuid}`; + +export interface Parsed { + organization?: string; + project?: string; + uuid: string; +} + +const namespace = 'readme'; + +/** + * Parses a ReadMe input string and extracts components. + * + * @param shorthand - ReadMe format string (@org/project#uuid or uuid) + * @returns Parsed ReadMe input components + * @throws Error if the input format is invalid + */ +export const parseShorthand = (shorthand: string): Parsed => { + const match = shorthand.match(registryRegExp); + + if (!match) { + throw new Error( + `Invalid ReadMe shorthand format. Expected "${namespace}:@organization/project#uuid" or "${namespace}:uuid", received: ${namespace}:${shorthand}`, + ); + } + + const [, , organization, project, uuid] = match; + + if (!uuid) { + throw new Error('The ReadMe shorthand UUID cannot be empty.'); + } + + const result: Parsed = { + organization, + project, + uuid, + }; + + return result; +}; + +/** + * Transforms a ReadMe shorthand string to the corresponding API URL. + * + * @param input - ReadMe format string + * @returns The ReadMe API Registry URL + */ +export const inputToReadmePath = (input: string): string => { + const shorthand = input.slice(`${namespace}:`.length); + const parsed = parseShorthand(shorthand); + return getRegistryUrl(parsed.uuid); +}; diff --git a/packages/openapi-ts/src/utils/readme.ts b/packages/openapi-ts/src/utils/readme.ts deleted file mode 100644 index 583d276f61..0000000000 --- a/packages/openapi-ts/src/utils/readme.ts +++ /dev/null @@ -1,73 +0,0 @@ -// Regular expression to match ReadMe input formats: -// readme:@organization/project#uuid or readme:uuid -const readmeInputRegExp = /^readme:(?:@([\w-]+)\/([\w-]+)#)?([\w-]+)$/; - -export interface ReadmeInput { - organization?: string; - project?: string; - uuid: string; -} - -/** - * Checks if the input string is a ReadMe format - * @param input - The input string to check - * @returns true if the input matches ReadMe format patterns - */ -export const isReadmeInput = (input: string): boolean => - typeof input === 'string' && input.startsWith('readme:'); - -/** - * Parses a ReadMe input string and extracts components - * @param input - ReadMe format string (readme:@org/project#uuid or readme:uuid) - * @returns Parsed ReadMe input components - * @throws Error if the input format is invalid - */ -export const parseReadmeInput = (input: string): ReadmeInput => { - if (!isReadmeInput(input)) { - throw new Error( - `Invalid ReadMe input format. Expected "readme:@organization/project#uuid" or "readme:uuid", received: ${input}`, - ); - } - - const match = input.match(readmeInputRegExp); - - if (!match) { - throw new Error( - `Invalid ReadMe input format. Expected "readme:@organization/project#uuid" or "readme:uuid", received: ${input}`, - ); - } - - const [, organization, project, uuid] = match; - - // Validate UUID format (basic validation for alphanumeric + hyphens) - if (!uuid || !/^[\w-]+$/.test(uuid)) { - throw new Error(`Invalid UUID format: ${uuid}`); - } - - const result: ReadmeInput = { uuid }; - - if (organization && project) { - result.organization = organization; - result.project = project; - } - - return result; -}; - -/** - * Generates the ReadMe API Registry URL for a given UUID - * @param uuid - The ReadMe API Registry UUID - * @returns The full API URL - */ -export const getReadmeApiUrl = (uuid: string): string => - `https://dash.readme.com/api/v1/api-registry/${uuid}`; - -/** - * Transforms a ReadMe input string to the corresponding API URL - * @param input - ReadMe format string - * @returns The ReadMe API Registry URL - */ -export const transformReadmeInput = (input: string): string => { - const parsed = parseReadmeInput(input); - return getReadmeApiUrl(parsed.uuid); -};