Makes header & request params optional and handle empty files gracefully #236
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.
Hello good people, I hope all is well.
This PR introduces three minor changes to the
rspec-openapi
gem:Header params can now be optional and by default required:
In the previous implementation, all header params were marked as required (
required: true
). Now, header params are optional, and by default required. The logic has been updated to check theoptional_headers
field, and any headers not present in that list are considered required (record.optional_headers.exclude?(key)
)Requets body params can now be optional and by default required:
In the previous implementation, all request body params were marked as required from the
enrich_with_required_keys
method, (obj[:required] = obj[:properties]&.keys || []
). Now, request body params are optional, and by default required. The logic has been updated to check theoptional_request_params
field in the record, and any params not present in that list are considered required ((obj[:properties]&.keys - optional_request_params) || []
)Gracefully handle empty files during YAML/JSON parsing:
The previous implementation would raise errors when attempting to load an empty YAML/JSON file. The update adds a check to ensure that if the content is nil (i.e., the file is empty), an empty hash {} is returned, avoiding any errors. (Check the provided error at the bottom).
These changes improve flexibility in defining required headers and prevent errors when dealing with empty files. Please note that I have tested these on a Rails API, provided changes should be tested in other frameworks.
P.S. Automated unit test is not provided since the changes doesn't modify the intended behavior of these methods by default current tests should cover these as well.
Raised Error mentioned in 3: