Skip to content

v4.0.0

Choose a tag to compare

@github-actions github-actions released this 07 Aug 20:19
· 18 commits to main since this release

Migration

Nuxt 4 Is Required

The module no longer supports Nuxt 3.

openapi-typescript v7 Is Required

The peer dependency used to accept ^5 || ^6 || ^7 and now accepts ^7 alone. Upgrade the package alongside the module and regenerate your schema types.

The experimental Namespace Is Gone

Its four flags moved out and two of them changed their default:

Before Now Default
experimental.enablePrefixedProxy: true server.proxyMode: 'passthrough' Unchanged
experimental.disableClientPayloadCache: true payloadCache: false Unchanged
experimental.enableAutoKeyInjection: true Removed Always on
experimental.enableSchemaFileWatcher Removed Always on in dev

Every useMyApiData call now gets its own async data state, keyed by its position in your source, the way Nuxt keys useFetch and useAsyncData – with no switch either way, as Nuxt has none. Two components asking for the same resource therefore no longer share a data ref, and no longer collide when their transform, pick or default options differ. They do still share the underlying request. Pass the same explicit key to put two call sites back on one instance.

The schema file watcher no longer has a switch. Nuxt's own builder watcher cannot stand in for it – it covers each layer's app and server directories only, and a path registered through nuxt.options.watch restarts the dev server rather than regenerating the types.

refresh() Sends the Request Again

The request cache sits below Nuxt's async data, so Nuxt could not reach into it: refresh(), clear() and a key change driven by a reactive option were answered with the response already cached for that request. Each of them now sends a new request. Expect more traffic where a page refreshes on an interval, and reach for getCachedData to decide when a call site may keep what it has.

cache Only Means the Browser Cache Now

cache used to accept a boolean alongside the RequestInit.cache values, and the boolean drove the payload cache. Payload caching now has its own option:

 const { data } = await useMyApiData('posts', {
-  cache: false,
+  payloadCache: false
 })

cache: true and cache: false are compile errors, so they surface on upgrade. One change is silent, though: a string value used to turn payload caching off as a side effect. cache: 'no-store' now only sets the browser cache mode, and the payload cache stays on unless you add payloadCache: false.

The Wrapped Proxy Reports 502 for an Unreachable API

An API that cannot be reached used to yield 503 Service Unavailable from the default proxy and 502 Bad Gateway from the passthrough one. Both report 502 now.

The Passthrough Proxy No Longer Forwards authorization

With server.proxyMode set to 'passthrough', a browser request's authorization header used to travel on to your API. It no longer does: the header carries the caller's credentials for your app, not your app's credentials for the upstream service.

A cookie still travels, but only for endpoints that set cookies: true. Note that the passthrough proxy forwards the request as it stands and does not add the endpoint's token, headers or query – only the default /api/__api_party/{endpointId} handler does. If you relied on the old behavior to pass a bearer token through, attach it in a request hook.

Endpoint Types Resolve Through the Client

Service<Path, Method> used to compute request, response and responses with its own type logic, which disagreed with what the composables returned. Both now resolve through the same helpers, so the type you extract is the type you get back.

Three consequences, all at type level:

  • A method the path doesn't declare is now a compile error. PetStore<'/pet', 'get'> fails where the schema declares only post and put; likewise PetStoreApiMethods<'/pet'> narrows from every HTTP verb to 'post' | 'put'.
  • An operation that declares no path or query parameters reports never, where the old logic answered undefined, and one that declares no request body reports undefined, where the old logic answered unknown.
  • A status code that carries no response body reports undefined in responses, in place of Record<string, never>. So does response for an operation whose success carries no body – PetStore<'/pet/{petId}', 'delete'>['response'] is now never.

See OpenAPI Type Helpers for what each property now reports.

schema No Longer Accepts a Function

An endpoint's schema takes a file path, a URL or the parsed schema object. Resolve a schema you have to build yourself in the api-party:extend hook instead, which runs at module initialization and can await:

export default defineNuxtConfig({
  hooks: {
    'api-party:extend': async (options) => {
      options.endpoints!.myApi!.schema = await buildSchema()
    },
  },
})

Passing a function was deprecated in v2.1.0 and now throws.

Removed Deprecated Type Helpers

Response, RequestBody and RequestQuery are gone from #nuxt-api-party/{endpointId}. They were keyed by operation ID; the endpoint interface is keyed by path and method, which is what the composables take:

-import type { Response } from '#nuxt-api-party/petStore'
+import type { PetStore } from '#nuxt-api-party'
 
-type Pet = Response<'getPetById'>
+type Pet = PetStore<'/pet/{petId}', 'get'>['response']

RequestBody<'addPet'> becomes PetStore<'/pet', 'post'>['request'], and RequestQuery<'findPetsByStatus'> becomes PetStore<'/pet/findByStatus', 'get'>['query'].


   🚨 Breaking Changes

   🐞 Bug Fixes

   🏎 Performance

    View changes on GitHub