OpenAPI 3.1 合约驱动开发与客户端生成指南规范片段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 结合生成工具可提升跨端协作效率与一致性。

发表评论 取消回复