带有警告的 Swagger 文件

Swagger file with warning

Swagger 文件按预期工作并带有警告。

{
  '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"
          }
        }
      }
    }
  }
}

问题 1) 应删除警告

Issue-2) "MainAttr-2"中的Attr-3是boolean类型的属性,是必须的。但是当我从下拉列表中选择 'false' 时,它被视为无效输入。它仅将 'true' 视为有效输入。 (任何需要像这样表现的布尔属性)

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

提前致谢。

  1. 一开始,将'swagger'改为"swagger"。 JSON 字符串需要双引号。

  2. 删除末尾多余的逗号:

    "title": "Sample Service",
    
  3. 从所有 属性 定义(Attr-1Attr-8)中删除 required 属性并使用 required 列表改为对象级别(在 MainAttr-1MainAttr-2 下)。

            "MainAttr-1": {
              "required": [ "Attr-1" ],    <-- list the required properties in this array
              "type": "object",
              "properties": {
                "Attr-1": {
                  "description": "Attr-1",
                  "required": true,        <-- remove this 
                  "type": "string"
                },
    

除此之外你的规格没问题。