Search code examples
swaggerswagger-2.0swagger-editor

Swagger file with warning


Swagger file is working as expected with 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

Issue-1) Warning should be removed

Issue-2) Attr-3 in "MainAttr-2" is boolean type attribute and it is required. But when i am selecting 'false' from the dropdown, it is treating as invalid input. It treats only 'true' as valid input. (Any Boolean attribute which is required behaving like this)

Due this warning i am unable to deliver the code.

Thanks in advance.


Solution

    1. In the beginning, change 'swagger' to "swagger". JSON requires double quotes around strings.

    2. Remove extra comma at the end of:

      "title": "Sample Service",
      
    3. Remove the required attribute from ALL property definitions (Attr-1 to Attr-8) and use the required list at the object level instead (under MainAttr-1 and MainAttr-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"
                  },
      

    Other than that your spec is fine.