我想在请求体中有多个参数,如下所示,但Swagger编辑器说“不允许有多个体参数”。如何在一个POST体中同时拥有对象和原语类型?
我期待criteria
对象和两个原语字段(offset
、limit
),如下所示:
{
"criteria": {
"key": "CBC",
"code":
},
"offset": 5,
"limit" : 5
}
OpenAPI定义:
"paths": {
"/user": {
"post": {
"tags": [
"user Service"
],
"summary": "Returns a list of user",
"operationId": "searchUsers",
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "criteria",
"required": true,
"schema": {
"$ref": "#/definitions/Criteria"
}
},
{
"name": "offset",
"type": "integer",
"description": "The offset for pagination.",
"format": "int32",
"default": 0,
"minimum": 0,
"required": false,
"in": "body"
},
{
"name": "limit",
"type": "integer",
"description": "The maximum number user",
"format": "int32",
"minimum": 1,
"maximum": 30,
"default": 30,
"required": false,
"in": "body"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/user"
}
},
definitions:
"Criteria": {
"type": "object",
"required": [
"key"
],
"properties": {
"key": {
"type": "string",
"description": "search key.",
"pattern": "[A-Za-z0-9-]+",
"minLength": 1,
"maxLength": 30
},
"code": {
"type": "string",
"description": "emp code filter on.",
"pattern": "^[A-Za-z0-9]+",
"minLength": 0,
"maxLength": 9
}
}
},
如何同时保持对象类型和基元类型?
1条答案
按热度按时间6yoyoihd1#
你就快到了
这一部分介绍了如何在OpenAPI 2.0中定义请求主体:
也就是说,它被定义为一个
in: body
参数,但是schema
必须描述 * 整个请求主体对象 *,而不是单个字段。正确的版本是: