为什么Swagger UI POST使用Content-Type表单数据:undefined?

时间:2018-04-15 16:52:18

标签: swagger-ui

我正在尝试使用Swagger UI发布表单数据,但请求是随Content-Type: undefined发送的:

enter image description here

如何配置它以便它可以工作? 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"
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

问题在于:

"consumes": []

consumes关键字指定请求中的Content-Type标头。由于您要发布表单数据,因此应该是:

"consumes": ["application/x-www-form-urlencoded"]

提示:您可以将规范粘贴到http://editor.swagger.io以检查语法错误。