Setup
Configuration
Learn how to configure NuxtOpenFetch
nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-open-fetch'],
openFetch: {
clients: {}
}
})
| Key | Type | Default | Description |
|---|---|---|---|
openAPITS | OpenAPITSOptions | { rootTypes: true } | Options passed to openapi-typescript. |
addPlugin | boolean | true | If enable default plugin to create fetch clients |
| Clients | |||
clients.[client] | OpenFetchClientOptions | Client options | |
clients.[client].baseURL | string | Base URL for the request. | |
clients.[client].headers | HeadersInit | Request headers. | |
clients.[client].query | SearchParameters | Adds query search params to URL | |
clients.[client].schema | OpenAPI3Schema | Local or remote schema file (YAML or JSON) |
OpenAPI TypeScript
The openAPITS object is passed to openapi-typescript, which generates the types used by NuxtOpenFetch. It accepts its Node API options:
nuxt.config.ts
export default defineNuxtConfig({
openFetch: {
openAPITS: {
alphabetize: true,
defaultNonNullable: true
},
clients: {}
}
})
NuxtOpenFetch enables rootTypes by default, exposing schema components as top-level Schema* types. See Type helpers.
The
enum, enumValues, and makePathsEnum options are not supported. These options generate runtime values, while NuxtOpenFetch intentionally emits declaration-only types that TypeScript can erase without adding runtime code.Runtime configuration
All options, except schema, are automatically copied to the runtime config.
You can access and modify these options at runtime using
useRuntimeConfig().This is particularly useful for overriding settings with environment variables. For example:
.env
NUXT_PUBLIC_OPEN_FETCH_PETS_BASE_URL=https://petstore3.swagger.io/api/v3/