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

Enable handling exploded parameters and test for edge cases #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AjaxVM
Copy link

@AjaxVM AjaxVM commented Apr 3, 2024

Description

OpenAPI supports exploded array parameters, such as stuff[]=foo&stuff[]=bar. However, when operating in a Rails environment (or any other server environment which parses these exploded parameters into a single stuff field), parameter_validation fails to find the param properly, leading to erroneous missed required fields or just lack of validation.

This was mentioned in the same Committee issue that is linked in #122 which has a PR to close that does not account for this specific scenario.

I originally thought this was possibly something that should be solved on the Committee side, but it looks like they are simply passing through to the validation here, and a referenced monkeypatch to this works, but that is not nearly as defensive and it seems like this should be a core support here.

This PR introduces handling for this, looking first for the param with the [] as it normally would, in case we are in an environment where they are not stripped. It then checks non-header parameters that end with [] for a matching param that strips it.

Monkeypatch

class OpenAPIParser::ParameterValidator
  class << self
    private

    def convert_key(k, is_header)
      is_header ? k&.downcase : k.sub(/\[\]$/, '')
    end
  end
end

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