···13import { defineConfig } from '@hey-api/openapi-ts';
1415export default defineConfig({
16- input: 'https://get.heyapi.dev/hey-api/backend',
17 output: 'src/client',
18});
19```
···21```js [openapi-ts.config.cjs]
22/** @type {import('@hey-api/openapi-ts').UserConfig} */
23module.exports = {
24- input: 'https://get.heyapi.dev/hey-api/backend',
25 output: 'src/client',
26};
27```
···29```js [openapi-ts.config.mjs]
30/** @type {import('@hey-api/openapi-ts').UserConfig} */
31export default {
32- input: 'https://get.heyapi.dev/hey-api/backend',
33 output: 'src/client',
34};
35```
···6566## Input
6768-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.
006970You can learn more on the [Input](/openapi-ts/configuration/input) page.
71···7980```js [url]
81export default {
82- input: 'https://get.heyapi.dev/hey-api/backend', // [!code ++]
00000083};
84```
85···87```js [object]
88export default {
89 input: { // [!code ++]
90- path: 'https://get.heyapi.dev/hey-api/backend', // [!code ++]
91 // ...other options // [!code ++]
92 }, // [!code ++]
93};
···120121```js [path]
122export default {
123- input: 'https://get.heyapi.dev/hey-api/backend',
124 output: 'src/client', // [!code ++]
125};
126```
···128<!-- prettier-ignore-start -->
129```js [object]
130export default {
131- input: 'https://get.heyapi.dev/hey-api/backend',
132 output: { // [!code ++]
133 path: 'src/client', // [!code ++]
134 // ...other options // [!code ++]
···13import { defineConfig } from '@hey-api/openapi-ts';
1415export default defineConfig({
16+ input: 'hey-api/backend', // sign up at app.heyapi.dev
17 output: 'src/client',
18});
19```
···21```js [openapi-ts.config.cjs]
22/** @type {import('@hey-api/openapi-ts').UserConfig} */
23module.exports = {
24+ input: 'hey-api/backend', // sign up at app.heyapi.dev
25 output: 'src/client',
26};
27```
···29```js [openapi-ts.config.mjs]
30/** @type {import('@hey-api/openapi-ts').UserConfig} */
31export default {
32+ input: 'hey-api/backend', // sign up at app.heyapi.dev
33 output: 'src/client',
34};
35```
···6566## Input
6768+You must provide an input so we can load your OpenAPI specification.
69+70+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.
7172You can learn more on the [Input](/openapi-ts/configuration/input) page.
73···8182```js [url]
83export default {
84+ input: 'https://get.heyapi.dev/hey-api/backend', // sign up at app.heyapi.dev // [!code ++]
85+};
86+```
87+88+```js [registry]
89+export default {
90+ input: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++]
91};
92```
93···95```js [object]
96export default {
97 input: { // [!code ++]
98+ path: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++]
99 // ...other options // [!code ++]
100 }, // [!code ++]
101};
···128129```js [path]
130export default {
131+ input: 'hey-api/backend', // sign up at app.heyapi.dev
132 output: 'src/client', // [!code ++]
133};
134```
···136<!-- prettier-ignore-start -->
137```js [object]
138export default {
139+ input: 'hey-api/backend', // sign up at app.heyapi.dev
140 output: { // [!code ++]
141 path: 'src/client', // [!code ++]
142 // ...other options // [!code ++]
+49-47
docs/openapi-ts/configuration/input.md
···56# Input
78-You must set the input so we can load your OpenAPI specification.
910## Input
1112-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.
1314::: code-group
15···2122```js [url]
23export default {
24- input: 'https://get.heyapi.dev/hey-api/backend', // [!code ++]
00000025};
26```
27···29```js [object]
30export default {
31 input: { // [!code ++]
32- path: 'https://get.heyapi.dev/hey-api/backend', // [!code ++]
33 // ...other options // [!code ++]
34 }, // [!code ++]
35};
···52If 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.
53:::
5455-### ReadMe API Registry
56-57-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.
58-59-::: code-group
60-61-```js [simple format]
62-export default {
63- input: 'readme:abc123def456', // [!code ++]
64-};
65-```
6667-```js [full format]
68-export default {
69- input: 'readme:@organization/project#abc123def456', // [!code ++]
70-};
71-```
7273-```js [object format]
074export default {
75 input: {
76- path: 'readme:abc123def456', // [!code ++]
77- // ...other options
000078 },
79};
80```
08182-:::
8384-The ReadMe input formats are:
8586-- `readme:uuid` - Simple format using only the UUID
87-- `readme:@organization/project#uuid` - Full format including organization and project names
8889-Both formats will fetch the OpenAPI specification from `https://dash.readme.com/api/v1/api-registry/{uuid}`.
9091-### Hey API Platform options
00009293-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.
9495```js
96export default {
97 input: {
98- path: 'https://get.heyapi.dev/',
99 branch: 'main', // [!code ++]
100- project: 'backend', // [!code ++]
101 },
102};
103```
104105-### Request options
106107-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.
0108109-<!-- prettier-ignore-start -->
110-```js
0111export default {
112- input: {
113- path: 'https://secret.com/protected-spec',
114- fetch: { // [!code ++]
115- headers: { // [!code ++]
116- Authorization: 'Bearer xxx', // [!code ++]
117- }, // [!code ++]
118- }, // [!code ++]
119- },
120};
121```
122-<!-- prettier-ignore-end -->
0000000123124## Watch Mode
125···134```js [config]
135export default {
136 input: {
137- path: 'https://get.heyapi.dev/hey-api/backend',
138 watch: true, // [!code ++]
139 },
140};
···142143```sh [cli]
144npx @hey-api/openapi-ts \
145- -i https://get.heyapi.dev/hey-api/backend \
146 -o src/client \
147 -w # [!code ++]
148```
···56# Input
78+You must provide an input so we can load your OpenAPI specification.
910## Input
1112+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.
1314::: code-group
15···2122```js [url]
23export default {
24+ input: 'https://get.heyapi.dev/hey-api/backend', // sign up at app.heyapi.dev // [!code ++]
25+};
26+```
27+28+```js [registry]
29+export default {
30+ input: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++]
31};
32```
33···35```js [object]
36export default {
37 input: { // [!code ++]
38+ path: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++]
39 // ...other options // [!code ++]
40 }, // [!code ++]
41};
···58If 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.
59:::
6061+### Request options
00000000006263+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.
00006465+<!-- prettier-ignore-start -->
66+```js
67export default {
68 input: {
69+ path: 'https://secret.com/protected-spec',
70+ fetch: { // [!code ++]
71+ headers: { // [!code ++]
72+ Authorization: 'Bearer xxx', // [!code ++]
73+ }, // [!code ++]
74+ }, // [!code ++]
75 },
76};
77```
78+<!-- prettier-ignore-end -->
7980+## API Registry
8182+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.
8384+### Hey API
08586+You can learn more about [Hey API Platform](https://app.heyapi.dev) on the [Integrations](/openapi-ts/integrations) page.
8788+```js [uuid]
89+export default {
90+ input: 'hey-api/backend', // sign up at app.heyapi.dev // [!code ++]
91+};
92+```
9394+The `input` object lets you provide additional options to construct the correct URL.
9596```js
97export default {
98 input: {
99+ path: 'hey-api/backend', // sign up at app.heyapi.dev
100 branch: 'main', // [!code ++]
0101 },
102};
103```
104105+We also provide shorthands for other registries:
106107+::: details ReadMe
108+Prefix your input with `readme:` to use the ReadMe API Registry.
109110+::: code-group
111+112+```js [uuid]
113export default {
114+ input: 'readme:nysezql0wwo236', // [!code ++]
0000000115};
116```
117+118+```js [long]
119+export default {
120+ input: 'readme:@developers/v2.0#nysezql0wwo236', // [!code ++]
121+};
122+```
123+124+:::
125126## Watch Mode
127···136```js [config]
137export default {
138 input: {
139+ path: 'hey-api/backend', // sign up at app.heyapi.dev
140 watch: true, // [!code ++]
141 },
142};
···144145```sh [cli]
146npx @hey-api/openapi-ts \
147+ -i hey-api/backend \
148 -o src/client \
149 -w # [!code ++]
150```
···32The fastest way to use `@hey-api/openapi-ts` is via npx
3334```sh
35-npx @hey-api/openapi-ts \
36- -i https://get.heyapi.dev/hey-api/backend \
37- -o src/client
38```
3940Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](/openapi-ts/output) page.
···99import { createClient } from '@hey-api/openapi-ts';
100101createClient({
102- input: 'https://get.heyapi.dev/hey-api/backend',
103 output: 'src/client',
104});
105```
···32The fastest way to use `@hey-api/openapi-ts` is via npx
3334```sh
35+npx @hey-api/openapi-ts -i hey-api/backend -o src/client
0036```
3738Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](/openapi-ts/output) page.
···97import { createClient } from '@hey-api/openapi-ts';
9899createClient({
100+ input: 'hey-api/backend', // sign up at app.heyapi.dev
101 output: 'src/client',
102});
103```
···144The fastest way to use `@hey-api/openapi-ts` is via npx
145146```sh
147-npx @hey-api/openapi-ts \
148- -i https://get.heyapi.dev/hey-api/backend \
149- -o src/client
150```
151152Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/openapi-ts/output) page.
···213import { createClient } from '@hey-api/openapi-ts';
214215createClient({
216- input: 'https://get.heyapi.dev/hey-api/backend',
217 output: 'src/client',
218});
219```
···228import { defineConfig } from '@hey-api/openapi-ts';
229230export default defineConfig({
231- input: 'https://get.heyapi.dev/hey-api/backend',
232 output: 'src/client',
233});
234```
···238```js
239/** @type {import('@hey-api/openapi-ts').UserConfig} */
240module.exports = {
241- input: 'https://get.heyapi.dev/hey-api/backend',
242 output: 'src/client',
243};
244```
···248```js
249/** @type {import('@hey-api/openapi-ts').UserConfig} */
250export default {
251- input: 'https://get.heyapi.dev/hey-api/backend',
252 output: 'src/client',
253};
254```
···144The fastest way to use `@hey-api/openapi-ts` is via npx
145146```sh
147+npx @hey-api/openapi-ts -i hey-api/backend -o src/client
00148```
149150Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/openapi-ts/output) page.
···211import { createClient } from '@hey-api/openapi-ts';
212213createClient({
214+ input: 'hey-api/backend', // sign up at app.heyapi.dev
215 output: 'src/client',
216});
217```
···226import { defineConfig } from '@hey-api/openapi-ts';
227228export default defineConfig({
229+ input: 'hey-api/backend', // sign up at app.heyapi.dev
230 output: 'src/client',
231});
232```
···236```js
237/** @type {import('@hey-api/openapi-ts').UserConfig} */
238module.exports = {
239+ input: 'hey-api/backend', // sign up at app.heyapi.dev
240 output: 'src/client',
241};
242```
···246```js
247/** @type {import('@hey-api/openapi-ts').UserConfig} */
248export default {
249+ input: 'hey-api/backend', // sign up at app.heyapi.dev
250 output: 'src/client',
251};
252```
···14import type { WatchValues } from './types/types';
15import { isLegacyClient, legacyNameFromConfig } from './utils/config';
16import type { Templates } from './utils/handlebars';
17+import { heyApiRegistryBaseUrl } from './utils/input/heyApi';
18import type { Logger } from './utils/logger';
19import { postProcessClient } from './utils/postprocess';
2021+const isHeyApiRegistryPath = (path: string) =>
22+ path.startsWith(heyApiRegistryBaseUrl);
23// || path.startsWith('http://localhost:4000')
2425export const compileInputPath = (input: Omit<Config['input'], 'watch'>) => {
···3940 if (
41 input.path &&
42+ (typeof input.path !== 'string' || !isHeyApiRegistryPath(input.path))
43 ) {
44 result.path = input.path;
45 return result;
···135 const baseString = colors.cyan('Generating from');
136137 if (typeof inputPath.path === 'string') {
138+ const baseInput = isHeyApiRegistryPath(inputPath.path)
139 ? `${inputPath.organization ?? ''}/${inputPath.project ?? ''}`
140 : inputPath.path;
141 console.log(`⏳ ${baseString} ${baseInput}`);
142+ if (isHeyApiRegistryPath(inputPath.path)) {
143 if (inputPath.branch) {
144 console.log(
145 `${colors.gray('branch:')} ${colors.green(inputPath.branch)}`,
+5-4
packages/openapi-ts/src/types/config.d.ts
···18 */
19 dryRun?: boolean;
20 /**
21- * Path to the OpenAPI specification. This can be either:
22- * - local file
23- * - remote path
24- * - ReadMe API Registry UUID (full and simplified formats)
25 *
26 * Both JSON and YAML file formats are supported. You can also pass the parsed
27 * object directly if you're fetching the file yourself.
···30 */
31 input:
32 | `https://get.heyapi.dev/${string}/${string}`
033 | `readme:@${string}/${string}#${string}`
34 | `readme:${string}`
35 | (string & {})
···18 */
19 dryRun?: boolean;
20 /**
21+ * Path to the OpenAPI specification. This can be:
22+ * - path
23+ * - URL
24+ * - API registry shorthand
25 *
26 * Both JSON and YAML file formats are supported. You can also pass the parsed
27 * object directly if you're fetching the file yourself.
···30 */
31 input:
32 | `https://get.heyapi.dev/${string}/${string}`
33+ | `${string}/${string}`
34 | `readme:@${string}/${string}#${string}`
35 | `readme:${string}`
36 | (string & {})
+5-4
packages/openapi-ts/src/types/input.d.ts
···36 */
37 organization?: string;
38 /**
39- * Path to the OpenAPI specification. This can be either:
40- * - local file
41- * - remote path
42- * - ReadMe API Registry UUID (full and simplified formats)
43 *
44 * Both JSON and YAML file formats are supported. You can also pass the parsed
45 * object directly if you're fetching the file yourself.
46 */
47 path?:
48 | `https://get.heyapi.dev/${string}/${string}`
049 | `readme:@${string}/${string}#${string}`
50 | `readme:${string}`
51 | (string & {})
···36 */
37 organization?: string;
38 /**
39+ * Path to the OpenAPI specification. This can be:
40+ * - path
41+ * - URL
42+ * - API registry shorthand
43 *
44 * Both JSON and YAML file formats are supported. You can also pass the parsed
45 * object directly if you're fetching the file yourself.
46 */
47 path?:
48 | `https://get.heyapi.dev/${string}/${string}`
49+ | `${string}/${string}`
50 | `readme:@${string}/${string}#${string}`
51 | `readme:${string}`
52 | (string & {})