From 646f3fd7bf7943bbe3aaff6d67a96bf0093bdf97 Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 02 Apr 2025 05:14:11 +0000 Subject: [PATCH] Merge pull request #1899 from hey-api/fix/client-fetch-to-next fix: set next field to never and recommend next.js client --- pnpm-lock.yaml | 72 ++++++++++++++++++++++++++++++++++++------------------------------------ .changeset/gentle-bobcats-sniff.md | 5 +++++ docs/openapi-ts/clients/next-js.md | 30 +++++++++++++++--------------- packages/client-fetch/src/types.ts | 7 +++++++ examples/openapi-ts-next/src/client/client.gen.ts | 6 +++++- examples/openapi-ts-next/src/client/sdk.gen.ts | 67 +++++++++++++++++++++++++++++++++++++++---------------------------- examples/openapi-ts-next/src/client/types.gen.ts | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts | 7 +++++++ packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts | 7 +++++++ 9 file(s) changed, 281 insertion(s)(+), 108 deletion(s)(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11943,7 +11943,7 @@ dependencies: '@ampproject/remapping': 2.3.0 '@angular-devkit/architect': 0.1902.0(chokidar@4.0.3) - '@angular-devkit/build-webpack': 0.1902.0(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.24.2)))(webpack@5.98.0(esbuild@0.25.0)) + '@angular-devkit/build-webpack': 0.1902.0(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.0)))(webpack@5.98.0(esbuild@0.25.0)) '@angular-devkit/core': 19.2.0(chokidar@4.0.3) '@angular/build': 19.2.0(@angular/compiler-cli@19.2.0(@angular/compiler@19.2.0(@angular/core@19.2.0(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3))(@angular/compiler@19.2.0(@angular/core@19.2.0(rxjs@7.8.1)(zone.js@0.15.0)))(@types/node@22.10.5)(chokidar@4.0.3)(jiti@2.4.2)(karma@6.4.4)(less@4.2.2)(postcss@8.5.2)(tailwindcss@3.4.9(ts-node@10.9.2(@types/node@22.10.5)(typescript@5.5.3)))(terser@5.39.0)(typescript@5.5.3)(yaml@2.7.0) '@angular/compiler-cli': 19.2.0(@angular/compiler@19.2.0(@angular/core@19.2.0(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3) @@ -11993,9 +11993,9 @@ tree-kill: 1.2.2 tslib: 2.8.1 typescript: 5.5.3 - webpack: 5.98.0(esbuild@0.25.0) - webpack-dev-middleware: 7.4.2(webpack@5.98.0(esbuild@0.24.2)) - webpack-dev-server: 5.2.0(webpack@5.98.0(esbuild@0.24.2)) + webpack: 5.98.0(esbuild@0.24.2) + webpack-dev-middleware: 7.4.2(webpack@5.98.0(esbuild@0.25.0)) + webpack-dev-server: 5.2.0(webpack@5.98.0(esbuild@0.25.0)) webpack-merge: 6.0.1 webpack-subresource-integrity: 5.1.0(webpack@5.98.0(esbuild@0.25.0)) optionalDependencies: @@ -12025,12 +12025,12 @@ - webpack-cli - yaml - '@angular-devkit/build-webpack@0.1902.0(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.24.2)))(webpack@5.98.0(esbuild@0.25.0))': + '@angular-devkit/build-webpack@0.1902.0(chokidar@4.0.3)(webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.0)))(webpack@5.98.0(esbuild@0.25.0))': dependencies: '@angular-devkit/architect': 0.1902.0(chokidar@4.0.3) rxjs: 7.8.1 - webpack: 5.98.0(esbuild@0.25.0) - webpack-dev-server: 5.2.0(webpack@5.98.0(esbuild@0.24.2)) + webpack: 5.98.0(esbuild@0.24.2) + webpack-dev-server: 5.2.0(webpack@5.98.0(esbuild@0.25.0)) transitivePeerDependencies: - chokidar @@ -14146,7 +14146,7 @@ dependencies: '@angular/compiler-cli': 19.2.0(@angular/compiler@19.2.0(@angular/core@19.2.0(rxjs@7.8.1)(zone.js@0.15.0)))(typescript@5.5.3) typescript: 5.5.3 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) '@nodelib/fs.scandir@2.1.5': dependencies: @@ -17408,7 +17408,7 @@ '@babel/core': 7.26.9 find-cache-dir: 4.0.0 schema-utils: 4.3.0 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) babel-plugin-polyfill-corejs2@0.4.12(@babel/core@7.26.9): dependencies: @@ -17957,7 +17957,7 @@ normalize-path: 3.0.0 schema-utils: 4.3.0 serialize-javascript: 6.0.2 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) core-js-compat@3.41.0: dependencies: @@ -18029,7 +18029,7 @@ postcss-value-parser: 4.2.0 semver: 7.7.1 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) css-select@5.1.0: dependencies: @@ -18673,8 +18673,8 @@ '@typescript-eslint/parser': 7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3) eslint: 9.17.0(jiti@2.4.2) eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.8.5(eslint-plugin-import@2.31.0)(eslint@9.17.0(jiti@2.4.2)) - eslint-plugin-import: 2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-typescript@3.8.5)(eslint@9.17.0(jiti@2.4.2)) + eslint-import-resolver-typescript: 3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)) + eslint-plugin-import: 2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-typescript@3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)) eslint-plugin-jsx-a11y: 6.10.2(eslint@9.17.0(jiti@2.4.2)) eslint-plugin-react: 7.37.4(eslint@9.17.0(jiti@2.4.2)) eslint-plugin-react-hooks: 5.2.0(eslint@9.17.0(jiti@2.4.2)) @@ -18697,7 +18697,7 @@ transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.8.5(eslint-plugin-import@2.31.0)(eslint@9.17.0(jiti@2.4.2)): + eslint-import-resolver-typescript@3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)): dependencies: '@nolyfill/is-core-module': 1.0.39 debug: 4.4.0(supports-color@9.4.0) @@ -18708,22 +18708,22 @@ stable-hash: 0.0.4 tinyglobby: 0.2.12 optionalDependencies: - eslint-plugin-import: 2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-typescript@3.8.5)(eslint@9.17.0(jiti@2.4.2)) + eslint-plugin-import: 2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-typescript@3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)) transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.8.5)(eslint@9.17.0(jiti@2.4.2)): + eslint-module-utils@2.12.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3) eslint: 9.17.0(jiti@2.4.2) eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.8.5(eslint-plugin-import@2.31.0)(eslint@9.17.0(jiti@2.4.2)) + eslint-import-resolver-typescript: 3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)) transitivePeerDependencies: - supports-color - eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-typescript@3.8.5)(eslint@9.17.0(jiti@2.4.2)): + eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-typescript@3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.8 @@ -18734,7 +18734,7 @@ doctrine: 2.1.0 eslint: 9.17.0(jiti@2.4.2) eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.8.5)(eslint@9.17.0(jiti@2.4.2)) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.8.5(eslint-plugin-import@2.31.0(@typescript-eslint/parser@7.15.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.5.3))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)))(eslint@9.17.0(jiti@2.4.2)) hasown: 2.0.2 is-core-module: 2.16.1 is-glob: 4.0.3 @@ -20364,7 +20364,7 @@ dependencies: less: 4.2.2 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) less@4.2.2: dependencies: @@ -20389,7 +20389,7 @@ dependencies: webpack-sources: 3.2.3 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) light-my-request@6.6.0: dependencies: @@ -20719,7 +20719,7 @@ dependencies: schema-utils: 4.3.0 tapable: 2.2.1 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) minimalistic-assert@1.0.1: {} @@ -22156,7 +22156,7 @@ postcss: 8.5.2 semver: 7.7.1 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) transitivePeerDependencies: - typescript @@ -22899,7 +22899,7 @@ neo-async: 2.6.2 optionalDependencies: sass: 1.85.0 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) sass@1.85.0: dependencies: @@ -23239,7 +23239,7 @@ dependencies: iconv-lite: 0.6.3 source-map-js: 1.2.1 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) source-map-support@0.5.21: dependencies: @@ -23620,16 +23620,16 @@ term-size@2.2.1: {} - terser-webpack-plugin@5.3.14(esbuild@0.25.0)(webpack@5.98.0(esbuild@0.24.2)): + terser-webpack-plugin@5.3.14(esbuild@0.24.2)(webpack@5.98.0(esbuild@0.25.0)): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 schema-utils: 4.3.0 serialize-javascript: 6.0.2 terser: 5.39.0 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) optionalDependencies: - esbuild: 0.25.0 + esbuild: 0.24.2 terser@5.39.0: dependencies: @@ -24782,7 +24782,7 @@ webidl-conversions@7.0.0: {} - webpack-dev-middleware@7.4.2(webpack@5.98.0(esbuild@0.24.2)): + webpack-dev-middleware@7.4.2(webpack@5.98.0(esbuild@0.25.0)): dependencies: colorette: 2.0.20 memfs: 4.17.0 @@ -24791,9 +24791,9 @@ range-parser: 1.2.1 schema-utils: 4.3.0 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) - webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.24.2)): + webpack-dev-server@5.2.0(webpack@5.98.0(esbuild@0.25.0)): dependencies: '@types/bonjour': 3.5.13 '@types/connect-history-api-fallback': 1.5.4 @@ -24820,10 +24820,10 @@ serve-index: 1.9.1 sockjs: 0.3.24 spdy: 4.0.2 - webpack-dev-middleware: 7.4.2(webpack@5.98.0(esbuild@0.24.2)) + webpack-dev-middleware: 7.4.2(webpack@5.98.0(esbuild@0.25.0)) ws: 8.18.1 optionalDependencies: - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) transitivePeerDependencies: - bufferutil - debug @@ -24841,11 +24841,11 @@ webpack-subresource-integrity@5.1.0(webpack@5.98.0(esbuild@0.25.0)): dependencies: typed-assert: 1.0.9 - webpack: 5.98.0(esbuild@0.25.0) + webpack: 5.98.0(esbuild@0.24.2) webpack-virtual-modules@0.6.2: {} - webpack@5.98.0(esbuild@0.25.0): + webpack@5.98.0(esbuild@0.24.2): dependencies: '@types/eslint-scope': 3.7.7 '@types/estree': 1.0.6 @@ -24867,7 +24867,7 @@ neo-async: 2.6.2 schema-utils: 4.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.14(esbuild@0.25.0)(webpack@5.98.0(esbuild@0.24.2)) + terser-webpack-plugin: 5.3.14(esbuild@0.24.2)(webpack@5.98.0(esbuild@0.25.0)) watchpack: 2.4.2 webpack-sources: 3.2.3 transitivePeerDependencies: diff --git a/.changeset/gentle-bobcats-sniff.md b/.changeset/gentle-bobcats-sniff.md new file mode 100644 --- /dev/null +++ b/.changeset/gentle-bobcats-sniff.md @@ -0,0 +1,5 @@ +--- +'@hey-api/client-fetch': minor +--- + +fix: set next field to never and recommend switching to the Next.js client diff --git a/docs/openapi-ts/clients/next-js.md b/docs/openapi-ts/clients/next-js.md --- a/docs/openapi-ts/clients/next-js.md +++ b/docs/openapi-ts/clients/next-js.md @@ -68,20 +68,6 @@ When we installed the client above, it created a [`client.gen.ts`](/openapi-ts/output#client) file. You will most likely want to configure the exported `client` instance. There are two ways to do that. -### `setConfig()` - -This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own Fetch implementation. - -```js -import { client } from 'client/client.gen'; - -client.setConfig({ - baseUrl: 'https://example.com', -}); -``` - -The disadvantage of this approach is that your code may call the `client` instance before it's configured for the first time. Depending on your use case, you might need to use the second approach. - ### Runtime API Since `client.gen.ts` is a generated file, we can't directly modify it. Instead, we can tell our configuration to use a custom file implementing the Runtime API. We do that by specifying the `runtimeConfigPath` option. @@ -114,7 +100,21 @@ ::: -With this approach, `client.gen.ts` will call `createClientConfig()` before initializing the `client` instance. If needed, you can still use `setConfig()` to update the client configuration later. +With this approach, `client.gen.ts` will call `createClientConfig()` before initializing the `client` instance. This is the recommended approach because it guarantees the client will be initialized in both server and client environment. If needed, you can still use `setConfig()` to update the client configuration later. + +### `setConfig()` + +This is the simpler approach. You can call the `setConfig()` method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to `setConfig()`, and even your own Fetch implementation. + +```js +import { client } from 'client/client.gen'; + +client.setConfig({ + baseUrl: 'https://example.com', +}); +``` + +The disadvantage of this approach is that your code may call the `client` instance before it's configured for the first time. Depending on your use case, this might be an acceptable trade-off. However, our Next.js users usually want to use the first approach. ### `createClient()` diff --git a/packages/client-fetch/src/types.ts b/packages/client-fetch/src/types.ts --- a/packages/client-fetch/src/types.ts +++ b/packages/client-fetch/src/types.ts @@ -21,6 +21,13 @@ */ fetch?: (request: Request) => ReturnType; /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** * Return the response data parsed in a specified format. By default, `auto` * will infer the appropriate method from the `Content-Type` response header. * You can override this behavior with any of the {@link Body} methods. diff --git a/examples/openapi-ts-next/src/client/client.gen.ts b/examples/openapi-ts-next/src/client/client.gen.ts --- a/examples/openapi-ts-next/src/client/client.gen.ts +++ b/examples/openapi-ts-next/src/client/client.gen.ts @@ -24,5 +24,9 @@ ) => Config & T>; export const client = createClient( - createClientConfig(createConfig()), + createClientConfig( + createConfig({ + baseUrl: 'https://petstore3.swagger.io/api/v3', + }), + ), ); diff --git a/examples/openapi-ts-next/src/client/sdk.gen.ts b/examples/openapi-ts-next/src/client/sdk.gen.ts --- a/examples/openapi-ts-next/src/client/sdk.gen.ts +++ b/examples/openapi-ts-next/src/client/sdk.gen.ts @@ -37,6 +37,7 @@ UpdatePetData, UpdatePetResponse, UpdatePetWithFormData, + UpdatePetWithFormResponse, UpdateUserData, UploadFileData, UploadFileResponse, @@ -60,8 +61,8 @@ }; /** - * Add a new pet to the store - * Add a new pet to the store + * Add a new pet to the store. + * Add a new pet to the store. */ export const addPet = ( options: Options, @@ -84,8 +85,8 @@ ); /** - * Update an existing pet - * Update an existing pet by Id + * Update an existing pet. + * Update an existing pet by Id. */ export const updatePet = ( options: Options, @@ -110,8 +111,8 @@ }); /** - * Finds Pets by status - * Multiple status values can be provided with comma separated strings + * Finds Pets by status. + * Multiple status values can be provided with comma separated strings. */ export const findPetsByStatus = ( options?: Options, @@ -132,7 +133,7 @@ }); /** - * Finds Pets by tags + * Finds Pets by tags. * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. */ export const findPetsByTags = ( @@ -154,7 +155,8 @@ }); /** - * Deletes a pet + * Deletes a pet. + * Delete a pet. */ export const deletePet = ( options: Options, @@ -171,8 +173,8 @@ }); /** - * Find pet by ID - * Returns a single pet + * Find pet by ID. + * Returns a single pet. */ export const getPetById = ( options: Options, @@ -197,12 +199,17 @@ }); /** - * Updates a pet in the store with form data + * Updates a pet in the store with form data. + * Updates a pet resource based on the form data. */ export const updatePetWithForm = ( options: Options, ) => - (options.client ?? _heyApiClient).post({ + (options.client ?? _heyApiClient).post< + UpdatePetWithFormResponse, + unknown, + ThrowOnError + >({ security: [ { scheme: 'bearer', @@ -214,7 +221,8 @@ }); /** - * uploads an image + * Uploads an image. + * Upload image of the pet. */ export const uploadFile = ( options: Options, @@ -239,8 +247,8 @@ }); /** - * Returns pet inventories by status - * Returns a map of status codes to quantities + * Returns pet inventories by status. + * Returns a map of status codes to quantities. */ export const getInventory = ( options?: Options, @@ -261,8 +269,8 @@ }); /** - * Place an order for a pet - * Place a new order in the store + * Place an order for a pet. + * Place a new order in the store. */ export const placeOrder = ( options?: Options, @@ -281,8 +289,8 @@ }); /** - * Delete purchase order by ID - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * Delete purchase order by identifier. + * For valid response try integer IDs with value < 1000. Anything above 1000 or non-integers will generate API errors. */ export const deleteOrder = ( options: Options, @@ -293,7 +301,7 @@ }); /** - * Find purchase order by ID + * Find purchase order by ID. * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions. */ export const getOrderById = ( @@ -309,7 +317,7 @@ }); /** - * Create user + * Create user. * This can only be done by the logged in user. */ export const createUser = ( @@ -329,8 +337,8 @@ }); /** - * Creates list of users with given input array - * Creates list of users with given input array + * Creates list of users with given input array. + * Creates list of users with given input array. */ export const createUsersWithListInput = ( options?: Options, @@ -349,7 +357,8 @@ }); /** - * Logs user into the system + * Logs user into the system. + * Log into the system. */ export const loginUser = ( options?: Options, @@ -364,7 +373,8 @@ }); /** - * Logs out current logged in user session + * Logs out current logged in user session. + * Log user out of the system. */ export const logoutUser = ( options?: Options, @@ -375,7 +385,7 @@ }); /** - * Delete user + * Delete user resource. * This can only be done by the logged in user. */ export const deleteUser = ( @@ -387,7 +397,8 @@ }); /** - * Get user by user name + * Get user by user name. + * Get user detail based on username. */ export const getUserByName = ( options: Options, @@ -402,7 +413,7 @@ }); /** - * Update user + * Update user resource. * This can only be done by the logged in user. */ export const updateUser = ( diff --git a/examples/openapi-ts-next/src/client/types.gen.ts b/examples/openapi-ts-next/src/client/types.gen.ts --- a/examples/openapi-ts-next/src/client/types.gen.ts +++ b/examples/openapi-ts-next/src/client/types.gen.ts @@ -12,19 +12,6 @@ status?: 'placed' | 'approved' | 'delivered'; }; -export type Customer = { - address?: Array
; - id?: number; - username?: string; -}; - -export type Address = { - city?: string; - state?: string; - street?: string; - zip?: string; -}; - export type Category = { id?: number; name?: string; @@ -88,7 +75,15 @@ /** * Invalid input */ - 405: unknown; + 400: unknown; + /** + * Validation exception + */ + 422: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type AddPetResponses = { @@ -122,7 +117,11 @@ /** * Validation exception */ - 405: unknown; + 422: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type UpdatePetResponses = { @@ -151,6 +150,10 @@ * Invalid status value */ 400: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type FindPetsByStatusResponses = { @@ -180,6 +183,10 @@ * Invalid tag value */ 400: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type FindPetsByTagsResponses = { @@ -212,6 +219,17 @@ * Invalid pet value */ 400: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type DeletePetResponses = { + /** + * Pet deleted + */ + 200: unknown; }; export type GetPetByIdData = { @@ -235,6 +253,10 @@ * Pet not found */ 404: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type GetPetByIdResponses = { @@ -271,8 +293,22 @@ /** * Invalid input */ - 405: unknown; + 400: unknown; + /** + * Unexpected error + */ + default: unknown; }; + +export type UpdatePetWithFormResponses = { + /** + * successful operation + */ + 200: Pet; +}; + +export type UpdatePetWithFormResponse = + UpdatePetWithFormResponses[keyof UpdatePetWithFormResponses]; export type UploadFileData = { body?: Blob | File; @@ -291,6 +327,21 @@ url: '/pet/{petId}/uploadImage'; }; +export type UploadFileErrors = { + /** + * No file uploaded + */ + 400: unknown; + /** + * Pet not found + */ + 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + export type UploadFileResponses = { /** * successful operation @@ -305,6 +356,13 @@ path?: never; query?: never; url: '/store/inventory'; +}; + +export type GetInventoryErrors = { + /** + * Unexpected error + */ + default: unknown; }; export type GetInventoryResponses = { @@ -330,7 +388,15 @@ /** * Invalid input */ - 405: unknown; + 400: unknown; + /** + * Validation exception + */ + 422: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type PlaceOrderResponses = { @@ -363,6 +429,17 @@ * Order not found */ 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type DeleteOrderResponses = { + /** + * order deleted + */ + 200: unknown; }; export type GetOrderByIdData = { @@ -386,6 +463,10 @@ * Order not found */ 404: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type GetOrderByIdResponses = { @@ -408,11 +489,18 @@ url: '/user'; }; +export type CreateUserErrors = { + /** + * Unexpected error + */ + default: unknown; +}; + export type CreateUserResponses = { /** * successful operation */ - default: User; + 200: User; }; export type CreateUserResponse = CreateUserResponses[keyof CreateUserResponses]; @@ -424,15 +512,18 @@ url: '/user/createWithList'; }; +export type CreateUsersWithListInputErrors = { + /** + * Unexpected error + */ + default: unknown; +}; + export type CreateUsersWithListInputResponses = { /** * Successful operation */ 200: User; - /** - * successful operation - */ - default: unknown; }; export type CreateUsersWithListInputResponse = @@ -459,6 +550,10 @@ * Invalid username/password supplied */ 400: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type LoginUserResponses = { @@ -477,11 +572,18 @@ url: '/user/logout'; }; +export type LogoutUserErrors = { + /** + * Unexpected error + */ + default: unknown; +}; + export type LogoutUserResponses = { /** * successful operation */ - default: unknown; + 200: unknown; }; export type DeleteUserData = { @@ -505,13 +607,24 @@ * User not found */ 404: unknown; + /** + * Unexpected error + */ + default: unknown; +}; + +export type DeleteUserResponses = { + /** + * User deleted + */ + 200: unknown; }; export type GetUserByNameData = { body?: never; path: { /** - * The name that needs to be fetched. Use user1 for testing. + * The name that needs to be fetched. Use user1 for testing */ username: string; }; @@ -528,6 +641,10 @@ * User not found */ 404: unknown; + /** + * Unexpected error + */ + default: unknown; }; export type GetUserByNameResponses = { @@ -547,7 +664,7 @@ body?: User; path: { /** - * name that needs to be updated + * name that need to be deleted */ username: string; }; @@ -555,13 +672,28 @@ url: '/user/{username}'; }; -export type UpdateUserResponses = { +export type UpdateUserErrors = { /** - * successful operation + * bad request + */ + 400: unknown; + /** + * user not found + */ + 404: unknown; + /** + * Unexpected error */ default: unknown; }; +export type UpdateUserResponses = { + /** + * successful operation + */ + 200: unknown; +}; + export type ClientOptions = { - baseUrl: `${string}://${string}/v3` | (string & {}); + baseUrl: 'https://petstore3.swagger.io/api/v3' | (string & {}); }; diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts b/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts --- a/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts @@ -139,6 +139,13 @@ */ fetch?: (request: Request) => ReturnType; /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** * Return the response data parsed in a specified format. By default, `auto` * will infer the appropriate method from the `Content-Type` response header. * You can override this behavior with any of the {@link Body} methods. diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts b/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts --- a/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts @@ -139,6 +139,13 @@ */ fetch?: (request: Request) => ReturnType; /** + * Please don't use the Fetch client for Next.js applications. The `next` + * options won't have any effect. + * + * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. + */ + next?: never; + /** * Return the response data parsed in a specified format. By default, `auto` * will infer the appropriate method from the `Content-Type` response header. * You can override this behavior with any of the {@link Body} methods. -- tangled.sh