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

Add tests and fix parameter exploding issue #1

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

hamir-suspect
Copy link
Collaborator

This fixes the parameters exploding issue. Now parameters defined as:

parameter(
            :some,
            :query,
            %Schema{
              type: :object,
              oneOf: [
                %Schema{
                  type: :object,
                  properties: %{foo: %Schema{type: :string}, bar: %Schema{type: :string}},
                  required: [:foo]
                },
                %Schema{
                  type: :object,
                  properties: %{foo: %Schema{type: :string}, baz: %Schema{type: :string}},
                  required: [:baz]
                }
              ]
            },
            "Some query parameter ",
            explode: true,
            style: :form,
            required: true
          )

will be properly casted into the :some parameter.
How this works:
the parameters that we fetch for a location can be flat (?foo=x&bar=y) before casting we search for any parameters that should be exploded, if we find any we gather all the properties it can hold.
We add those to the struct (as if it was a deep struct param ?some[foo]=x&some[bar]=y and remove them from the query params. in the end query params struct before casting looks like %{"some" => %{"foo" => "x", "bar" => "y"}} instead of what we started with: %{"foo" => "x", "bar" => "y"}.

The ideal way would be to fix how the location schema is composed but that seems to be quite tricky with current implementation.

@hamir-suspect hamir-suspect merged commit c133e7f into master Nov 23, 2023
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