Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ahl opened this issue Dec 21, 2021 · 3 comments
Closed

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

ahl opened this issue Dec 21, 2021 · 3 comments

Comments

@ahl
Copy link

ahl commented Dec 21, 2021

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
    },
@karenetheridge
Copy link
Member

related: #2799

@ahl
Copy link
Author

ahl commented Dec 8, 2022

@karenetheridge how did you address this in #2799? It seems like extension properties would satisfy your minProperties: 1, no?

@karenetheridge
Copy link
Member

Yes, there is no contains-like keyword for objects that specifies that a property matching a particular regex must be present.

Actually, I thought of a way... I have submitted it as #3093. \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants