这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .changeset/eleven-lions-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@hey-api/openapi-ts': minor
---

feat: bundle `@hey-api/client-*` plugins

### Bundle `@hey-api/client-*` plugins

In previous releases, you had to install a separate client package to generate a fully working output, e.g. `npm install @hey-api/client-fetch`. This created a few challenges: getting started was slower, upgrading was sometimes painful, and bundling too. Beginning with v0.73.0, all Hey API clients are bundled by default and don't require installing any additional dependencies. You can remove any installed client packages and re-run `@hey-api/openapi-ts`.

```sh
npm uninstall @hey-api/client-fetch
```
5 changes: 5 additions & 0 deletions .changeset/mighty-bulldogs-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: respect logs setting if initialization fails
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ test/e2e/generated

# error files
openapi-ts-error-*

# But DO NOT ignore generated snapshots!
!test/__snapshots__/test/generated
!test/__snapshots__/test/generated/**
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,38 +120,35 @@ 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 \
-c @hey-api/client-fetch
-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.

Before you can make API requests with the client you've just created, you need to install `@hey-api/client-fetch` and configure it.

## Installation

#### npm

```sh
npm install @hey-api/client-fetch && npm install @hey-api/openapi-ts -D
npm install @hey-api/openapi-ts -D
```

#### pnpm

```sh
pnpm add @hey-api/client-fetch && pnpm add @hey-api/openapi-ts -D
pnpm add @hey-api/openapi-ts -D
```

#### yarn

```sh
yarn add @hey-api/client-fetch && yarn add @hey-api/openapi-ts -D
yarn add @hey-api/openapi-ts -D
```

#### bun

```sh
bun add @hey-api/client-fetch && bun add @hey-api/openapi-ts -D
bun add @hey-api/openapi-ts -D
```

We recommend pinning an exact version so you can safely upgrade when you're ready. This package is in [initial development](https://semver.org/spec/v0.1.0.html#spec-item-5) and its API might change before v1.
Expand All @@ -178,7 +175,6 @@ import { createClient } from '@hey-api/openapi-ts';
createClient({
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: ['@hey-api/client-fetch'],
});
```

Expand All @@ -194,7 +190,6 @@ import { defineConfig } from '@hey-api/openapi-ts';
export default defineConfig({
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: ['@hey-api/client-fetch'],
});
```

Expand All @@ -205,7 +200,6 @@ export default defineConfig({
module.exports = {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: ['@hey-api/client-fetch'],
};
```

Expand All @@ -216,7 +210,6 @@ module.exports = {
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: ['@hey-api/client-fetch'],
};
```

Expand Down
4 changes: 4 additions & 0 deletions docs/.vitepress/config/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default defineConfig({
link: '/openapi-ts/output/sdk',
text: 'SDK',
},
{
link: '/openapi-ts/output/client',
text: 'Client',
},
{
link: '/openapi-ts/output/json-schema',
text: 'JSON Schema',
Expand Down
41 changes: 1 addition & 40 deletions docs/openapi-ts/clients/axios.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,6 @@ Launch demo

## Installation

Start by adding `@hey-api/client-axios` to your dependencies.

::: code-group

```sh [npm]
npm install @hey-api/client-axios
```

```sh [pnpm]
pnpm add @hey-api/client-axios
```

```sh [yarn]
yarn add @hey-api/client-axios
```

```sh [bun]
bun add @hey-api/client-axios
```

:::

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

::: code-group
Expand Down Expand Up @@ -137,7 +115,7 @@ With this approach, `client.gen.ts` will call `createClientConfig()` before init
You can also create your own client instance. You can use it to manually send requests or point it to a different domain.

```js
import { createClient } from '@hey-api/client-axios';
import { createClient } from './client/client';

const myClient = createClient({
baseURL: 'https://example.com',
Expand Down Expand Up @@ -228,22 +206,5 @@ const url = client.buildUrl<FooData>({
console.log(url); // prints '/foo/1?bar=baz'
```

## Bundling

Sometimes, you may not want to declare client packages as a dependency. This scenario is common if you're using Hey API to generate output that is repackaged and published for other consumers under your own brand. For such cases, our clients support bundling through the `client.bundle` configuration option.

```js
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: [
{
bundle: true, // [!code ++]
name: '@hey-api/client-axios',
},
],
};
```

<!--@include: ../../examples.md-->
<!--@include: ../../sponsors.md-->
47 changes: 7 additions & 40 deletions docs/openapi-ts/clients/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,6 @@ Launch demo

## Installation

Start by adding `@hey-api/client-fetch` to your dependencies.

::: code-group

```sh [npm]
npm install @hey-api/client-fetch
```

```sh [pnpm]
pnpm add @hey-api/client-fetch
```

```sh [yarn]
yarn add @hey-api/client-fetch
```

```sh [bun]
bun add @hey-api/client-fetch
```

:::

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

::: code-group
Expand All @@ -78,6 +56,12 @@ npx @hey-api/openapi-ts \

:::

::: tip

This step is optional because Fetch is the default client.

:::

## Configuration

The Fetch client is built as a thin wrapper on top of Fetch API, extending its functionality to work with Hey API. If you're already familiar with Fetch, configuring your client will feel like working directly with Fetch API.
Expand Down Expand Up @@ -137,7 +121,7 @@ With this approach, `client.gen.ts` will call `createClientConfig()` before init
You can also create your own client instance. You can use it to manually send requests or point it to a different domain.

```js
import { createClient } from '@hey-api/client-fetch';
import { createClient } from './client/client';

const myClient = createClient({
baseUrl: 'https://example.com',
Expand Down Expand Up @@ -299,22 +283,5 @@ const url = client.buildUrl<FooData>({
console.log(url); // prints '/foo/1?bar=baz'
```

## Bundling

Sometimes, you may not want to declare client packages as a dependency. This scenario is common if you're using Hey API to generate output that is repackaged and published for other consumers under your own brand. For such cases, our clients support bundling through the `client.bundle` configuration option.

```js
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: [
{
bundle: true, // [!code ++]
name: '@hey-api/client-fetch',
},
],
};
```

<!--@include: ../../examples.md-->
<!--@include: ../../sponsors.md-->
41 changes: 1 addition & 40 deletions docs/openapi-ts/clients/next-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,6 @@ Launch demo

## Installation

Start by adding `@hey-api/client-next` to your dependencies.

::: code-group

```sh [npm]
npm install @hey-api/client-next
```

```sh [pnpm]
pnpm add @hey-api/client-next
```

```sh [yarn]
yarn add @hey-api/client-next
```

```sh [bun]
bun add @hey-api/client-next
```

:::

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

::: code-group
Expand Down Expand Up @@ -131,7 +109,7 @@ The disadvantage of this approach is that your code may call the `client` instan
You can also create your own client instance. You can use it to manually send requests or point it to a different domain.

```js
import { createClient } from '@hey-api/client-next';
import { createClient } from './client/client';

const myClient = createClient({
baseUrl: 'https://example.com',
Expand Down Expand Up @@ -292,22 +270,5 @@ const url = client.buildUrl<FooData>({
console.log(url); // prints '/foo/1?bar=baz'
```

## Bundling

Sometimes, you may not want to declare client packages as a dependency. This scenario is common if you're using Hey API to generate output that is repackaged and published for other consumers under your own brand. For such cases, our clients support bundling through the `client.bundle` configuration option.

```js
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: [
{
bundle: true, // [!code ++]
name: '@hey-api/client-next',
},
],
};
```

<!--@include: ../../examples.md-->
<!--@include: ../../sponsors.md-->
39 changes: 12 additions & 27 deletions docs/openapi-ts/clients/nuxt.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ Nuxt client is currently in beta. The interface might change before it becomes s

[Nuxt](https://nuxt.com) is an open source framework that makes web development intuitive and powerful.

::: tip
You might be interested in the [Nuxt module](https://www.npmjs.com/package/@hey-api/nuxt) instead. It offers all the features mentioned in this guide in a more familiar way.
:::

<!-- <button class="buttonLink" @click="(event) => embedProject('hey-api-client-fetch-example')(event)">
Launch demo
</button> -->
Expand All @@ -33,24 +29,24 @@ Launch demo

## Installation

Start by adding `@hey-api/client-nuxt` to your dependencies.
Start by adding `@hey-api/nuxt` to your dependencies.

::: code-group

```sh [npm]
npm install @hey-api/client-nuxt
npm install @hey-api/nuxt
```

```sh [pnpm]
pnpm add @hey-api/client-nuxt
pnpm add @hey-api/nuxt
```

```sh [yarn]
yarn add @hey-api/client-nuxt
yarn add @hey-api/nuxt
```

```sh [bun]
bun add @hey-api/client-nuxt
bun add @hey-api/nuxt
```

:::
Expand All @@ -76,6 +72,12 @@ npx @hey-api/openapi-ts \

:::

::: tip

If you add `@hey-api/nuxt` to your Nuxt modules, this step is not needed.

:::

## Configuration

The Nuxt client is built as a thin wrapper on top of Nuxt, extending its functionality to work with Hey API. If you're already familiar with Nuxt, configuring your client will feel like working directly with Nuxt.
Expand Down Expand Up @@ -135,7 +137,7 @@ With this approach, `client.gen.ts` will call `createClientConfig()` before init
You can also create your own client instance. You can use it to manually send requests or point it to a different domain.

```js
import { createClient } from '@hey-api/client-nuxt';
import { createClient } from './client/client';

const myClient = createClient({
baseURL: 'https://example.com',
Expand Down Expand Up @@ -230,22 +232,5 @@ const url = client.buildUrl<FooData>({
console.log(url); // prints '/foo/1?bar=baz'
```

## Bundling

Sometimes, you may not want to declare client packages as a dependency. This scenario is common if you're using Hey API to generate output that is repackaged and published for other consumers under your own brand. For such cases, our clients support bundling through the `client.bundle` configuration option.

```js
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: [
{
bundle: true, // [!code ++]
name: '@hey-api/client-nuxt',
},
],
};
```

<!--@include: ../../examples.md-->
<!--@include: ../../sponsors.md-->
Loading
Loading