Skip to content

require that responses object has 'default' or a response code (fixes #2833) #3093

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

Conversation

karenetheridge
Copy link
Member

@karenetheridge karenetheridge commented Dec 11, 2022

ref. https://spec.openapis.org/oas/v3.1.0#responses-object

I realized that there is a way of saying "the patternProperties keyword must match something", by using a false in a conditional.

We decided in #2799 that a numeric response code was not required as long as default was present instead.

I tested it with the following test cases (using the format used by https://github.com/json-schema-org/JSON-Schema-Test-Suite).

[
    {
        "description": "openapi v3.1 test stuff",
        "schema": {
          "$defs": {
            "specification-extensions": {
              "patternProperties": {
                "^x-": true
              }
            }
          },
          "type": "object",
          "properties": {
            "default": true
          },
          "patternProperties": {
            "^[1-5](?:[0-9]{2}|XX)$": true
          },
          "minProperties": 1,
          "$ref": "#/$defs/specification-extensions",
          "unevaluatedProperties": false,
          "$comment": "either default, or at least one response code property must exist",
          "if": {
            "patternProperties": {
              "^[1-5](?:[0-9]{2}|XX)$": false
            }
          },
          "then" : {
            "required": [ "default" ]
          }
        },
        "tests": [
            {
                "description": "one number property",
                "data": { "400": true },
                "valid": true
            },
            {
                "description": "one number property and x-",
                "data": { "400": true, "x-blah": 1 },
                "valid": true
            },
            {
                "description": "default property",
                "data": { "default": true },
                "valid": true
            },
            {
                "description": "default property and x-",
                "data": { "default": true, "x-blah": 1 },
                "valid": true
            },
            {
                "description": "one number property and x-, extra fields not permitted",
                "data": { "400": true, "bloop": 1 },
                "valid": false
            },
            {
                "description": "one number property and x-, extra fields not permitted",
                "data": { "400": true, "x-blah": 1, "bloop": 1 },
                "valid": false
            },
            {
                "description": "default property, extra fields not permitted",
                "data": { "default": true, "bloop": 1 },
                "valid": false
            },
            {
                "description": "default property and x-",
                "data": { "default": true, "x-blah": 1, "bloop": 1 },
                "valid": false
            },
            {
                "description": "no properties",
                "data": {},
                "valid": false
            },
            {
                "description": "no required properties, with x-",
                "data": { "x-blah": 1 },
                "valid": false
            },
            {
                "description": "no required properties, extra properties not permitted-",
                "data": { "bloop": 1 },
                "valid": false
            }
        ]
    }
]

@karenetheridge karenetheridge force-pushed the ether/require-response-code-in-response-obj branch from 1434d3c to 2ea3ba6 Compare December 11, 2022 00:43
@darrelmiller
Copy link
Member

@OAI/tsc Can we get another approval and merge?

Copy link
Member

@MikeRalphson MikeRalphson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@MikeRalphson MikeRalphson merged commit e7971e5 into OAI:main Mar 5, 2023
@karenetheridge karenetheridge deleted the ether/require-response-code-in-response-obj branch March 5, 2023 22:23
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

Successfully merging this pull request may close these issues.

4 participants