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

handle arrays of refs in parameter schemas #205

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

Conversation

fenollp
Copy link

@fenollp fenollp commented Oct 8, 2018

A parameter such as

      entries(:body, Schema.array(:BlueprintEntry), "a blueprint's entries", required: false)

generates this Swagger2 parameter:

           {
             "schema": {
               "type": "array",
               "items": {
                 "$ref": "#/definitions/BlueprintEntry"
               }
             },
             "required": false,
             "name": "entries",
             "in": "body",
             "description": "a blueprint's entries"
           }

which is not handled by the validation part of this lib:

    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in String.split/3
            (elixir) lib/string.ex:407: String.split(nil, "/", [])
            (phoenix_swagger) lib/phoenix_swagger/validator.ex:111: anonymous fn/3 in PhoenixSwagger.Validator.collect_schema_attrs/1
            (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
            (phoenix_swagger) lib/phoenix_swagger/validator.ex:109: anonymous fn/4 in PhoenixSwagger.Validator.collect_schema_attrs/1
            (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/enum.ex:1318: anonymous fn/3 in Enum.map/2
            (stdlib) maps.erl:257: :maps.fold_1/3

This patch is my attempt at lowering the validator's assumptions on schemas/types in parameters, however it fails a couple tests... Ideas?

end)
# collect request primitive parameters which do not refer to `definitions`
# these are mostly parameters from query string
properties = Enum.reduce(parameters, properties, fn(parameter, acc) ->
if parameter["type"] != nil do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can narrow it down to this line causing the test failures

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.

2 participants