OpenAPI Type Helpers
For each endpoint with a schema, Nuxt API Party generates a type carrying everything one operation declares. It is named after the endpoint ID and takes a path and a method:
import type { PetStore } from '#nuxt-api-party'
type GetUser = PetStore<'/user/{username}', 'get'>
// Extract any part of the operation
type PathParams = GetUser['path'] // { username: string }
type QueryParams = GetUser['query'] // Query parameters
type RequestBody = GetUser['request'] // Request body type
type Response = GetUser['response'] // Success response
type ErrorResponse = GetUser['responses'][404] // Specific status codeBoth parameters are required, and both are checked against the schema. A path the schema does not declare is a compile error, and so is a method the path does not allow – PetStore<'/pet', 'get'> does not compile, because the Petstore declares only post and put there.
Core Type Properties
Each property is read off the operation in your schema:
| Property | Description | Example |
|---|---|---|
path | Path parameters | { petId: number } |
query | Query parameters | { status?: 'available' | 'pending' | 'sold' } |
request | Request body, for whichever media type the operation declares | { name: string, photoUrls: string[] } |
response | Body of the successful response, for whichever 2xx status it declares | { id?: number, name: string } |
responses | Every status code the operation declares, mapped to the body it returns | { 200: Pet, 400: undefined, 404: undefined } |
fullPath | Complete path string | '/pet/{petId}' |
method | HTTP method | 'get' |
operation | Full OpenAPI operation | Complete operation object |
Where an operation declares nothing at all for a property, the type says so rather than inventing an empty object: path and query are never, request is undefined, and response is undefined for an operation whose success carries no body.
request and response match the composables: a value annotated with PetStore<Path, Method>['response'] is exactly what $petStore hands back for that call.
Examples
A request body the schema marks optional comes back widened with undefined, matching what the composables accept:
type PlaceOrderBody = PetStore<'/store/order', 'post'>['request']
// ^? Order | URLSearchParams | undefinedError Handling Types
Extract the body a particular status code carries:
// All responses the operation declares
type AllPetResponses = PetStore<'/pet/{petId}', 'get'>['responses']
// ^? { 200: Pet; 400: undefined; 404: undefined }
// A single status code
type PetNotFound = PetStore<'/pet/{petId}', 'get'>['responses'][404]
// ^? undefinedOnly the codes the operation itself declares are available, so PetStore<'/pet', 'post'>['responses'] offers 200 and 405 and nothing else. A status declared without a response body – which is every error in the Petstore schema – resolves to undefined.
This is the body a status maps to. To type the error a failed request actually throws, see Error Handling.
Schema Discovery
Two further types enumerate what the schema declares, for code that walks the API rather than calling one path:
import type { PetStoreApiMethods, PetStoreApiPaths } from '#nuxt-api-party'
// Get all available paths
type AllPaths = PetStoreApiPaths
// ^? '/pet' | '/pet/{petId}' | '/pet/findByStatus' | /* ... */
// Get all available methods for a specific path
type PetMethods = PetStoreApiMethods<'/pet'>
// ^? 'post' | 'put'Schema Model Types
Models are also reachable on their own, without going through an operation:
import type { PetStoreModel } from '#nuxt-api-party'
// Extract schema models directly
type Pet = PetStoreModel<'Pet'>
// ^? { id?: number; name: string; category?: Category; photoUrls: string[]; tags?: Tag[]; status?: 'available' | 'pending' | 'sold' }
type Category = PetStoreModel<'Category'>
// ^? { id?: number; name?: string }
type User = PetStoreModel<'User'>
// ^? { id?: number; username?: string; firstName?: string; lastName?: string; email?: string; password?: string; phone?: string; userStatus?: number }Reach for this where a type belongs to your domain rather than to one operation – a shared component, a form, a helper that calls several.