Connector Configuration
This page describes the connector configuration supported by the current Nuxt module flow.
Where to configure it
Configure connectors in nuxt.config.ts under the openapi key.
export default defineNuxtConfig({
modules: ['nuxt-openapi-hyperfetch'],
openapi: {
input: './swagger.yaml',
output: './openapi',
generators: ['useAsyncData', 'connectors'],
connectors: {
strategy: 'hybrid',
},
},
})Supported shape
type ConnectorsConfig = {
enabled?: boolean
strategy?: 'manual' | 'hybrid'
resources?: Record<
string,
{
operations?: Partial<
Record<
'getAll' | 'get' | 'create' | 'update' | 'delete',
{ operationId?: string; path?: string }
>
>
}
>
}For each configured operation:
operationIdorpathis required- defining both is invalid
- defining neither is invalid
When connectors are considered requested
Connector generation is considered requested when any of these is true:
createUseAsyncDataConnectors === truegeneratorsincludes'connectors'connectorshas meaningful config such asenabled,strategy, or non-emptyresources
When connectors are requested, the module internally ensures useAsyncData generation is present as well.
Strategy behavior
hybrid
hybrid is the default behavior.
It works like this:
- start from inferred resources discovered from the spec
- apply explicit overrides for matching resources
- add custom resources that exist only in config
- keep inferred operations that were not overridden
manual
manual generates only the resources explicitly declared by the user.
That means:
- no inferred resources are added automatically
- partial CRUD definitions are allowed
- you choose exactly which resource names and operations are emitted
Operation resolution rules
During config resolution:
operationIdandpathcannot be used together for the same operation.- One of them must be present.
operationIdmust exist in the indexed OpenAPI operations.pathmust exist and must contain a compatible method for the requested connector operation.- When a path has multiple compatible matches, the resolver prefers the endpoint whose detected intent matches the requested operation.
Method compatibility is:
getAll->GETget->GETcreate->POSTupdate->PUTorPATCHdelete->DELETE
For ambiguous matches, resolver preferences are:
getAll: prefer endpoints detected aslistget: prefer endpoints detected asdetailupdate: preferPUToverPATCH
Example: hybrid
export default defineNuxtConfig({
modules: ['nuxt-openapi-hyperfetch'],
openapi: {
input: './swagger.yaml',
output: './openapi',
generators: ['useAsyncData', 'connectors'],
connectors: {
strategy: 'hybrid',
resources: {
pets: {
operations: {
getAll: { operationId: 'findPetsByStatus' },
get: { operationId: 'getPetById' },
create: { operationId: 'addPet' },
update: { operationId: 'updatePet' },
delete: { operationId: 'deletePet' },
},
},
featuredPets: {
operations: {
getAll: { operationId: 'findPetsByTags' },
get: { path: '/pet/{petId}' },
},
},
},
},
},
})In hybrid mode:
petsoverrides the inferred mapping for that resourcefeaturedPetsis added as an extra configured resource- non-overridden inferred operations remain available
Example: manual
export default defineNuxtConfig({
modules: ['nuxt-openapi-hyperfetch'],
openapi: {
input: './swagger.yaml',
output: './openapi',
connectors: {
strategy: 'manual',
resources: {
pets: {
operations: {
getAll: { operationId: 'findPetsByStatus' },
get: { path: '/pet/{petId}' },
},
},
},
},
},
})In manual mode:
- only
petsis generated - only the configured operations are defined for that resource
Backward compatibility
The legacy createUseAsyncDataConnectors flag still exists and still triggers connector generation.
Use it only as compatibility glue. New configuration should prefer generators: ['connectors'] and the connectors object.
Validation failures
Connector generation fails before file emission when config is invalid. Common failures are:
- both
operationIdandpathdefined - neither
operationIdnorpathdefined - unknown
operationId - unknown
path - path exists but does not expose a compatible HTTP method
