| name | oRPC Expanding OpenAPI Link Types |
| description | Extend OpenAPILink to support additional data types beyond JSON's native capabilities. |
| license | MIT |
| metadata | {"author":"Ali Torki","homepage":"https://github.com/ali-master","version":"1.0.0"} |
Expanding Type Support for OpenAPI Link
Extend OpenAPILink to support additional data types using the Response Validation Plugin.
How It Works
Extend your output and error schemas with coercion logic.
Outputs containing Blob or File outside the root level also face Bracket Notation limitations.
const contract = oc.output(z.object({
date: z.coerce.date<Date>(),
bigint: z.coerce.bigint<bigint>(),
}))
const procedure = implement(contract).handler(() => ({
date: new Date(),
bigint: 123n,
}))
The client receives:
const beforeValidation = {
date: '2025-09-01T07:24:39.000Z',
bigint: '123'
}
After validation (via Response Validation Plugin):
const afterValidation = {
date: new Date('2025-09-01T07:24:39.000Z'),
bigint: 123n
}
To support more types than OpenAPI Handler, first extend the OpenAPI JSON Serializer.
Setup
Set up the Response Validation Plugin and remove the JsonifiedClient wrapper:
import type { ContractRouterClient } from '@orpc/contract'
import { createORPCClient } from '@orpc/client'
import { OpenAPILink } from '@orpc/openapi-client/fetch'
import { ResponseValidationPlugin } from '@orpc/contract/plugins'
const link = new OpenAPILink(contract, {
url: 'http://localhost:3000/api',
plugins: [
+ new ResponseValidationPlugin(contract),
]
})
-const client: JsonifiedClient<ContractRouterClient<typeof contract>> = createORPCClient(link)
+const client: ContractRouterClient<typeof contract> = createORPCClient(link)