使用OAS设计API及转换为Spring代码
1. OAS的components部分
1.1 定义模型
我们先来看示例电商应用中 components 部分的代码片段:
components:
schemas:
Cart:
description: Shopping Cart of the user
type: object
properties:
customerId:
description: Id of the customer who possesses the cart
type: string
items:
description: Collection of items in cart.
type: array
items:
$ref: '#/components/schemas/Item'
这里定义了一个名为 Cart 的模型,它是对象类型,包含两个字段: customerId (字符串类型)和 items (数组类型)。
1.2 对象数据类型
在OAS中,可以将任何模型或字段定义为对象类型。标记为对象类型后,下一个属性是 properties ,它包含对象的所有字段。例如
超级会员免费看
订阅专栏 解锁全文
559

被折叠的 条评论
为什么被折叠?



