title: Swagger - Specify Optional Object Property or Multiple Responses
body: <p>I have an API that either returns the following response on success:</p>
  
  <pre><code>{
      "result": "success",
      "filename": "my-filename.txt"
  }
  </code></pre>
  
  <p>or something like below upon failure:</p>
  
  <pre><code>{
      "result": "error",
      "message": "You must specify the xxx parameter."
  }
  </code></pre>
  
  <p>The filename property is only specified if the request was a success, but a message is provided if there was an error. This means the message and the filename properties are "optional" but the result property is required.</p>
  
  <p>I tried defining this response object in a definition as shown below:</p>
  
  <pre><code>"my_response_object": {
      "type": "object",
      "properties": {
          "result": {
              "type": "string",
              "description": "value of 'success' or 'error', indicated whether was successful",
              "required": true
          },
          "message": {
              "type": "string",
              "description": "an error message if there was an issue",
              "required": false
          },
          "filename": {
              "type": "string",
              "description": "the filename to return if the request was successful",
              "required": false
          }
      }
  }
  </code></pre>
  
  <p>But it appears that swagger does not like the "required" attribute and will show the following error message:</p>
  
  <p><img src="https://i.stack.imgur.com/CpqbB.png" alt="enter image description here"></p>
  
  <p>When I look at an example from swagger, they have the following layout where there are two different response definitions instead of one.</p>
  
  <pre><code>"responses": {
      "200": {
          "description": "Profile information for a user",
          "schema": {
              "$ref": "#/definitions/Profile"
          }
      },
      "default": {
          "description": "Unexpected error",
          "schema": {
              "$ref": "#/definitions/Error"
          }
      }
  }
  </code></pre>
  
  <p>I could do this, but it appears that one cannot have multiple responses for the 200 error code. Does this mean that one has to use "default" for all error responses, and one can only have a single structure for all erroneous responses, or is there a way to specify that certain attributes are optional in definitions?</p>