oRPC Response Validation Plugin

Validate server responses against the contract schema.

SKILL.md

GitHub

Response Validation Plugin

Validates server responses against your contract schema, ensuring data matches the expected types.

Best suited for Contract-First Development. Minified Contract is not supported.

Setup

import { RPCLink } from '@orpc/client/fetch'
import { ResponseValidationPlugin } from '@orpc/contract/plugins'

const link = new RPCLink({
  url: 'http://localhost:3000/rpc',
  plugins: [
    new ResponseValidationPlugin(contract),
  ],
})

const client: ContractRouterClient<typeof contract> = createORPCClient(link)

Limitations

Schemas that transform data into different types than the expected schema types are not supported.

// Unsupported:
const unsupported = z.number().transform(value => value.toString())

The server transforms number to string, but the client receives a string that no longer matches the schema, causing validation to fail.

Advanced Usage

Also useful for Expanding Type Support for OpenAPI Link.