我正在尝试使用Swagger UI发布表单数据,但请求是随Content-Type: undefined
发送的:
如何配置它以便它可以工作? JSON POST工作正常。
这是我的API定义:
{
"swagger": "2.0",
"info": {
"version": "V1",
"title": "Title"
},
"paths": {
"/api/getcalculation": {
"post": {
"tags": [
"ArrearsOfPay"
],
"operationId": "ApiArrearsOfPayPost",
"consumes": [],
"produces": [
"application/json"
],
"parameters": [
{
"name": "InsolvencyDate",
"in": "formData",
"required": false,
"type": "string",
"format": "date-time"
},
{
"name": "DismissalDate",
"in": "formData",
"required": false,
"type": "string",
"format": "date-time"
},
{
"name": "UnpaidPeriodFrom",
"in": "formData",
"required": false,
"type": "string",
"format": "date-time"
},
{
"name": "UnpaidPeriodTo",
"in": "formData",
"required": false,
"type": "string",
"format": "date-time"
},
{
"name": "ApClaimAmount",
"in": "formData",
"required": false,
"type": "number",
"format": "double"
},
{
"name": "PayDay",
"in": "formData",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "ShifPattern",
"in": "formData",
"required": true,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "multi"
},
{
"name": "WeeklyWage",
"in": "formData",
"required": false,
"type": "number",
"format": "double"
},
{
"name": "StatutaryMax",
"in": "formData",
"required": false,
"type": "number",
"format": "double"
},
{
"name": "NumberOfDaysWorkedInWeek",
"in": "formData",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/ArrearsOfPayCalculationResponseModel"
}
}
}
}
}
},
"definitions": {
"ArrearsOfPayCalculationResponseModel": {
"type": "object",
"properties": {
"startOfPayWeek": {
"format": "date-time",
"type": "string"
},
"maximumLiability": {
"format": "double",
"type": "number"
},
"employerLiability": {
"format": "double",
"type": "number"
},
"minimumLiability": {
"format": "double",
"type": "number"
}
}
}
}
}
答案 0 :(得分:1)
问题在于:
"consumes": []
consumes
关键字指定请求中的Content-Type
标头。由于您要发布表单数据,因此应该是:
"consumes": ["application/x-www-form-urlencoded"]
提示:您可以将规范粘贴到http://editor.swagger.io以检查语法错误。