带有警告的Swagger文件

时间:2016-12-07 15:36:55

标签: swagger swagger-2.0 swagger-editor

Swagger文件与warnig一样正常工作。

{
  'swagger': "2.0",
  "info": {
    "version": "3.0",
    "title": "Sample Service",
  },
  "schemes": [ "http" ],
  "host": "sampleservice.azurewebsites.net",
  "paths": {
    "/": {
      "post": {
        "summary": "Sample service",
        "description": "sample service",
        "parameters": [
          {
            "name": "Input",
            "in": "body",
            "description": "valid input",

            "schema": {
              "type": "object",
              "properties": {
                "MainAttr-1": {
                  "required": [ "Attr-1" ],
                  "type": "object",
                  "properties": {
                    "Attr-1": {
                      "description": "Attr-1",
                      "required": true,
                      "type": "string"
                    },
                    "Attr-2": {
                      "description": "Attr-2",
                      "required": false,
                      "type": "string"
                    },
                    "Attr-3": {
                      "description": "Attr-3",
                      "required": false,
                      "type": "boolean"
                    },
                    "Attr-4": {
                      "description": "Attr-4",
                      "required": false,
                      "type": "boolean"
                    },
                    "Attr-5": {
                      "description": "Attr-5",
                      "required": false,
                      "type": "string"
                    }
                  }
                },
                "MainAttr-2": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [ "Attr-1", "Attr-3", "Attr-5", "Attr-8" ],
                    "properties": {
                      "Attr-1": {
                        "description": "Attr-1",
                        "required": true,
                        "type": "string"
                      },
                      "Attr-2": {
                        "description": "Attr-2",
                        "required": false,
                        "type": "string"
                      },
                      "Attr-3": {
                        "description": "Attr-3",
                        "required": true,
                        "type": "boolean"
                      },
                      "Attr-4": {
                        "description": "Attr-4",
                        "required": false,
                        "type": "boolean"
                      },
                      "Attr-5": {
                        "description": "Attr-5",
                        "required": true,
                        "type": "string"
                      },

                      "Attr-6": {
                        "description": "Attr-6",
                        "required": false,
                        "type": "string"
                      },
                      "Attr-7": {
                        "description": "Attr-7",
                        "required": false,
                        "type": "string"
                      },
                      "Attr-8": {
                        "description": "Attr-8",
                        "required": true,
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "success"
          }
        }
      }
    }
  }
}

enter image description here

问题-1)应删除警告

问题-2)“MainAttr-2”中的Attr-3是布尔类型属性,它是必需的。但是当我从下拉列表中选择“假”时,它被视为无效输入。它仅将'true'视为有效输入。 (任何布尔属性都需要这样做)

由于此警告,我无法提供代码。

提前致谢。

1 个答案:

答案 0 :(得分:1)

  1. 首先,将'swagger'更改为"swagger"。 JSON需要围绕字符串使用双引号。

  2. 删除额外的逗号:

    "title": "Sample Service",
    
  3. 从所有属性定义(requiredAttr-1)中删除Attr-8属性,然后在对象级别使用required列表(在{{1下) }和MainAttr-1)。

    MainAttr-2
  4. 除此之外你的规格还不错。