跳到主要内容

Request Body 对象

定义请求体。

固定字段

字段名类型描述
descriptionstring对请求体的简要描述,可以包含使用示例,CommonMark syntax可以被用来呈现富文本格式.
contentMap[string, Media Type 对象]必选. 请求体的内容。请求体的属性 key 是一个媒体类型或者媒体类型范围,值是对应媒体类型的示例数据。对于能匹配多个 key 的请求,定义更明确的请求会更优先被匹配。比如text/plain会覆盖text/*的定义。
requiredboolean指定请求体是不是应该被包含在请求中,默认值是false

这个对象可能会被规范扩展扩展。

Request Body 示例

一个引用了模型定义的请求体。

{
"description": "user to add to the system",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User Example",
"externalValue": "http://foo.bar/examples/user-example.json"
}
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"user": {
"summary": "User example in XML",
"externalValue": "http://foo.bar/examples/user-example.xml"
}
}
},
"text/plain": {
"examples": {
"user": {
"summary": "User example in Plain text",
"externalValue": "http://foo.bar/examples/user-example.txt"
}
}
},
"*/*": {
"examples": {
"user": {
"summary": "User example in other format",
"externalValue": "http://foo.bar/examples/user-example.whatever"
}
}
}
}
}
description: user to add to the system
content:
'application/json':
schema:
$ref: '#/components/schemas/User'
examples:
user:
summary: User Example
externalValue: 'http://foo.bar/examples/user-example.json'
'application/xml':
schema:
$ref: '#/components/schemas/User'
examples:
user:
summary: User Example in XML
externalValue: 'http://foo.bar/examples/user-example.xml'
'text/plain':
examples:
user:
summary: User example in text plain format
externalValue: 'http://foo.bar/examples/user-example.txt'
'*/*':
examples:
user:
summary: User example in other format
externalValue: 'http://foo.bar/examples/user-example.whatever'

请求体是一个字符串的数组:

{
"description": "user to add to the system",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
description: user to add to the system
required: true
content:
text/plain:
schema:
type: array
items:
type: string