open-api-spex / open_api_spex

Open API Specifications for Elixir Plug applications
Mozilla Public License 2.0
681 stars 177 forks source link

How can I do it when a parameter (in: query) is composed ? #581

Open matheuscamarques opened 7 months ago

matheuscamarques commented 7 months ago

How can I do it when a parameter (in: query) is composed

example

%ObjectParams{
  page: %{
         limit: integer,
         before: string,
         after: string
  }
  filter: %{
         status_not: string
  }
}
hamir-suspect commented 6 months ago

Hey, I'm not a maintainer but I have had an issue that might be useful to your use case as well, it depends on how you want your query params to look like:

1.?page[limit]=1&page[before]=token&filter[status_not]=done solution is something like:

parameter(
            :page,
            :query,
            %Schema{
              type: :object,
                  properties: %{
                      limit: %Schema{type: :integer, default: 20},
                      before: %Schema{type: :string}},
                      after: %Schema{type: :string}}
            },
            "Page params",
            required: true
          ),
parameter(
    :filter,
    :query,
    %Schema{
....
  1. ?limit=10&before=token&status_not=done in this case you want to specify that your parameter is explode: true like this:
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
          )

The 2nd approach currently does not work but there is a pending PR