如何在SwaggerUI中使用查询字符串传递对象数组?当我将PostMan用于查询http://localhost:50353/contacts/filter?filters[0].PropertyName=name&filters[0].Operator=Equal&filters[0].Value=18时,它可以正常工作,但是当我使用SwaggerUI时,它将绑定空模型并传递如下查询字符串:{?Filters = filters%5B0%5D.PropertyName% 3Dname%26filters%5B0%5D.Operator%3DEqual%26filters%5B0%5D.Value%3D18&Filters =}
[HttpGet]
[Route("/contacts/filter")]
[ValidateModelState]
[SwaggerOperation("PostContactFilter")]
[SwaggerResponse(statusCode: 200, type: typeof(List<Contact>), description: "Successful contact request")]
[SwaggerResponse(statusCode: 204, type: typeof(Contact), description: "No content")]
public virtual IActionResult GetContacts([FromQuery]FiltersModel filtersModel)
{
var result = _logic.GetContacts(filtersModel);
if (result is null || result.Count == 0)
return NoContent();
else
return Ok(result);
}
json:
"/contacts/filter": {
"get": {
"tags": [
"Contacts"
],
"summary": "gets contacts",
"description": "Return contact",
"operationId": "GetContacts",
"consumes": [],
"produces": [
"text/plain",
"application/json",
"text/json"
],
"parameters": [
{
"name": "Filters",
"in": "query",
"required": false,
"type": "array",
"items": {},
"collectionFormat": "multi",
"uniqueItems": false
},
{
"name": "Offset",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "Limit",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "api-version",
"in": "header",
"description": "The requested API version",
"required": false,
"type": "string",
"default": "1.0"
}
],
"responses": {
"200": {
"description": "Successful contact request",
"schema": {
"uniqueItems": false,
"type": "array",
"items": {
"$ref": "#/definitions/blabla.Contact"
}
}
},
"204": {
"description": "No content",
"schema": {
"$ref": "#/definitions/blabla.Contact"
}
}
},
"deprecated": false
}