oRPC OpenAPI Specification
Generate OpenAPI specifications for oRPC with ease.
Works with
---
name: oRPC OpenAPI Specification
description: Generate OpenAPI specifications for oRPC with ease.
license: MIT
---
# OpenAPI Specification
Generate OpenAPI 3.1.1 specs from your [Router](/docs/router) or [Contract](/docs/contract-first/define-contract).
## Installation
```sh
npm install @orpc/openapi@latest
```
## Generating Specifications
Integrates with [Zod](https://zod.dev/), [Valibot](https://valibot.dev), and [ArkType](https://arktype.io/).
```ts
import { OpenAPIGenerator } from '@orpc/openapi'
import { ZodToJsonSchemaConverter } from '@orpc/zod' // zod v3
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4' // zod v4
import { experimental_ValibotToJsonSchemaConverter as ValibotToJsonSchemaConverter } from '@orpc/valibot'
import { experimental_ArkTypeToJsonSchemaConverter as ArkTypeToJsonSchemaConverter } from '@orpc/arktype'
const openAPIGenerator = new OpenAPIGenerator({
schemaConverters: [
new ZodToJsonSchemaConverter(),
new ValibotToJsonSchemaConverter(),
new ArkTypeToJsonSchemaConverter(),
],
})
const spec = await openAPIGenerator.generate(router, {
info: { title: 'My App', version: '0.0.0' },
servers: [{ url: 'https://api.example.com/v1' }],
})
```
## Common Schemas
```ts
const UserSchema = z.object({
id: z.string(),
name: z.string(),
email: z.email(),
})
const spec = await generator.generate(router, {
commonSchemas: {
User: { schema: UserSchema },
InputPet: { strategy: 'input', schema: PetSchema },
OutputPet: { strategy: 'output', schema: PetSchema },
UndefinedError: { error: 'UndefinedError' }
},
})
```
## Filtering Procedures
```ts
const spec = await generator.generate(router, {
filter: ({ contract, path }) => !contract['~orpc'].route.tags?.includes('internal'),
})
```
## Operation Metadata
```ts
const ping = os
.route({
operationId: 'ping',
summary: 'the summary',
description: 'the description',
deprecated: false,
tags: ['tag'],
successDescription: 'the success description',
spec: {
operationId: 'customOperationId',
tags: ['tag'],
summary: 'the summary',
requestBody: {
required: true,
content: { 'application/json': {} }
},
responses: {
200: {
description: 'customSuccessDescription',
content: { 'application/json': {} },
}
},
}
})
.handler(() => {})
// Tag an entire router
const router = os.tag('planets').router({})
```
## Customizing Operation Objects
```ts
import { oo } from '@orpc/openapi'
const procedure = os
.route({
spec: spec => ({
...spec,
security: [{ 'api-key': [] }],
}),
})
.handler(() => 'Hello, World!')
// With errors
const base = os.errors({
UNAUTHORIZED: oo.spec({ data: z.any() }, { security: [{ 'api-key': [] }] })
})
// With middleware
const requireAuth = oo.spec(
os.middleware(async ({ next, errors }) => {
throw new ORPCError('UNAUTHORIZED')
}),
{ security: [{ 'api-key': [] }] }
)
```
## `@orpc/zod`
### Zod v4
Zod v4 includes native `File` schema:
```ts
const InputSchema = z.object({
file: z.file(),
image: z.file().mime(['image/png', 'image/jpeg']),
})
```
Use `JSON_SCHEMA_REGISTRY` for customization:
```ts
import { JSON_SCHEMA_REGISTRY } from '@orpc/zod/zod4'
JSON_SCHEMA_REGISTRY.add(InputSchema, {
description: 'User schema',
examples: [{ name: 'John' }],
})
```
### Zod v3
```ts
import { oz } from '@orpc/zod'
const InputSchema = z.object({
file: oz.file(),
image: oz.file().type('image/*'),
blob: oz.blob()
})
const InputSchemaWithMeta = oz.openapi(
z.object({ name: z.string() }),
{ examples: [{ name: 'Earth' }] }
)
```More API Design skills
lark-event
larksuite/cli
Lark/Feishu real-time event listening / subscribing / consuming: stream events as NDJSON via `lark-cli event consume <EventKey>` (covers IM messages/reactions/chat changes, Approval status changes, Task updates, VC meeting started/joined/ended, Minutes generated, Whiteboard updated, etc.). Use for Lark bots, real-time message processing, long-running subscribers, streaming webhook/push handlers. Supports `--max-events` / `--timeout` bounded runs and a stderr ready-marker contract — designed for AI agents running as subprocesses.
lark-contact
larksuite/cli
飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名,以及按关键词搜索当前用户可见的机器人 / 智能体(agent)。当用户提到一个名字要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生 OpenAPI。
lark-openapi-explorer
larksuite/cli
飞书/Lark 原生 OpenAPI 探索:从官方文档库中挖掘未经 CLI 封装的原生 OpenAPI 接口。当用户的需求无法被现有 lark-* skill 或 lark-cli 已注册命令满足,需要查找并调用原生飞书 OpenAPI 时使用。

