Skip to content

JSON Schema for Responses object is incorrect in light of extensions #2833

Closed
@ahl

Description

@ahl

The 3.0.3 spec says this about the Responses object:

The Responses Object MUST contain at least one response code, and it SHOULD be the response for a successful operation call.

3.1.0 says something similar:

The Responses Object MUST contain at least one response code, and if only one response code is provided it SHOULD be the response for a successful operation call.

Here's the JSON Schema for 3.0.3:

    "Responses": {
      "type": "object",
      "properties": {
        "default": {
          "oneOf": [
            {
              "$ref": "#/definitions/Response"
            },
            {
              "$ref": "#/definitions/Reference"
            }
          ]
        }
      },
      "patternProperties": {
        "^[1-5](?:\\d{2}|XX)$": {
          "oneOf": [
            {
              "$ref": "#/definitions/Response"
            },
            {
              "$ref": "#/definitions/Reference"
            }
          ]
        },
        "^x-": {
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },

Note that the minProperties attempts to enforce the restriction noted above, but it inadvertently counts extensions. In other words, the following is valid according to the schema, but not according to the spec:

{
  "x-no-responses-at-all": "muahaha"
}

Note that 3.1 doesn't appear to try to enforce this in the schema:

    "responses": {
      "type": "object",
      "properties": {
        "default": {
          "$ref": "#/$defs/response-or-reference"
        }
      },
      "patternProperties": {
        "^[1-5](?:[0-9]{2}|XX)$": {
          "$ref": "#/$defs/response-or-reference"
        }
      },
      "$ref": "#/$defs/specification-extensions",
      "unevaluatedProperties": false
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions