Skip to content

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.

  1. Define Your Custom Serializer

    ts
    import type { StandardOpenAPICustomJsonSerializer } from '@orpc/openapi-client/standard'
    
    export class  {
      constructor(
        public readonly : string,
        public readonly : string,
        public readonly : string,
        public readonly : number,
      ) {}
    
      () {
        return {
          : this.,
          : this.,
          : this.,
          : this.,
        }
      }
    }
    
    export const : StandardOpenAPICustomJsonSerializer = {
      :  =>  instanceof ,
      :  => .toJSON(),
    }
  2. Use Your Custom Serializer

    ts
    const  = new (, {
      : [],
    })
    
    const  = new ({
      : [],
    })

    INFO

    It is recommended to add custom serializers to the OpenAPIGenerator for consistent serialization in the OpenAPI document.

Released under the MIT License.