-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to permit validation when schema and data are empty (#417)
This PR add option to permit validation when schema and data are empty in OpenAPI2::Link ## Background In our project, there are scenarios where the API returns an empty response body with status code 200. However, the current OpenAPI 2 schema validation does not allow an empty schema for the response body, causing validation errors in these cases. Specifically, in cases such as the schema and controller example below, I expect the Committee::Middleware::ResponseValidation check to pass successfully. ```yaml "/pets/cat": { "get": { "description": "Returns pets which are cats", "operationId": "find pets which are cats", "responses": { "200": { "description": "empty schema" } } } } ``` ```ruby class CatController # pets/cat get "/" do status 200 present nil end end ``` ## Changes To address this issue, I have added an option to allow an empty schema for the response body in OpenAPI 2. This change enables the validation to pass when both the schema and response body are nil, accommodating the specific use case in our project. 1. If allow_blank_structures is set to true, the validation will pass if the schema is empty and the data is nil. 2. I have also modified the error message for the case where data is present and the schema does not exist.
- Loading branch information
Showing
7 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters