OpenAPI JSON Serializer
This serializer processes JSON payloads for the OpenAPIHandler and supports native data types.
Extending Native Data Types
Customize serialization by creating your own StandardOpenAPICustomJsonSerializer
and adding it to the customJsonSerializers
option.
Define Your Custom Serializer
tsimport type { StandardOpenAPICustomJsonSerializer } from '@orpc/openapi-client/standard' export class
User{ constructor( public readonlyid: string, public readonlyname: string, public readonlyemail: string, public readonlyage: number, ) {}toJSON() { return {id: this.id,name: this.name,email: this.email,age: this.age, } } } export constuserSerializer: StandardOpenAPICustomJsonSerializer = {condition:data=>datainstanceofUser,serialize:data=>data.toJSON(), }Use Your Custom Serializer
tsconst
handler= newOpenAPIHandler(router, {customJsonSerializers: [userSerializer], }) constgenerator= newOpenAPIGenerator({customJsonSerializers: [userSerializer], })INFO
It is recommended to add custom serializers to the
OpenAPIGenerator
for consistent serialization in the OpenAPI document.