规范片段
openapi: 3.1.0
info:
title: Sample API
version: 1.0.0
paths:
/items/{id}:
get:
parameters:
- name: id
in: path
required: true
schema: { type: string }
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
components:
schemas:
Item:
type: object
properties:
id: { type: string }
name: { type: string }
生成示例
openapi-generator-cli generate -i openapi.yaml -g typescript-fetch -o client
要点
- 保持响应类型与错误模型一致
- 使用语义化版本管理合约演进
总结
在合约驱动模式下,OpenAPI 结合生成工具可提升跨端协作效率与一致性。

发表评论 取消回复