Skip to content
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

Makes header params optional and handle empty files gracefully #236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

muhammadnawzad
Copy link

Hello good people, I hope all is well.

This PR introduces two minor changes to the rspec-openapi gem:

  1. 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 the optional_headers field, and any headers not present in that list are considered required (record.optional_headers.exclude?(key))

  2. 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.

Raised Error mentioned in 2:

Failure/Error: base.replace(RSpec::OpenAPI::KeyTransformer.symbolize(base))

NoMethodError:
  undefined method `replace' for nil

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.

1 participant