Client
Inferring Schema Types

Inferring OAS Schema Types

In feTS, you can use helpers to infer specific fragments of an OpenAPI document.

Models

To infer models from an OpenAPI document, use the OASModel type:

user-type.ts
import type { NormalizeOAS, OASModel } from 'fets'
import type oas from './openapi'
 
// This will infer User type from your OpenAPI schema
type User = OASModel<NormalizeOAS<typeof oas>, 'User'>

Request Parameters

To infer request body parameters from an OpenAPI document, utilize the OASRequestBody type:

user-request-parameters.ts
import type { NormalizeOAS, OASRequestParameters } from 'fets'
import type oas from './openapi'
 
type AddUserInput = OASRequestParams<NormalizeOAS<typeof oas>, '/user', 'POST'>

Response body

Use the OASOutput type, to infer the response body from an OpenAPI document:

user-response-body.ts
import type { NormalizeOAS, OASOutput } from 'fets'
import type oas from './openapi'
 
type UserByIdResponse = OASOutput<NormalizeOAS<typeof oas>, '/user/:id', 'POST', 200>