require that responses object has 'default' or a response code (fixes #2833) #3093
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
falsein a conditional.We decided in #2799 that a numeric response code was not required as long as
defaultwas 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 } ] } ]