Inferring Schema Types

Inferring OAS Schema Types

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


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

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:

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:

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