phoenix_swagger icon indicating copy to clipboard operation
phoenix_swagger copied to clipboard

parse_swagger_schema: valid swagger doesn't parse

Open mbana opened this issue 7 years ago • 2 comments

attempting to parse this valid file fails:

https://github.com/OpenBankingUK/payment-initiation-api-spec/blob/master/dist/v1.1/payment-initiation-swagger.json

PhoenixSwagger.Validator.parse_swagger_schema("schemas/v1.1-payment-initiation-swagger.json")
...
12:37:01.864 [info]  Application swagger_validation_ex exited: exited in: SwaggerValidationExApplication.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in String.split/3
            (elixir) lib/string.ex:383: String.split(nil, "/", [])
            (phoenix_swagger) lib/phoenix_swagger/validator.ex:112: anonymous fn/3 in PhoenixSwagger.Validator.collect_schema_attrs/1
            (elixir) lib/enum.ex:1899: 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:1294: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/enum.ex:1298: anonymous fn/3 in Enum.map/2
            (stdlib) lists.erl:1263: :lists.foldl/3
            (elixir) lib/enum.ex:1915: Enum.map/2

looks like it failing around here: https://github.com/OpenBankingUK/payment-initiation-api-spec/blob/master/dist/v1.1/payment-initiation-swagger.json#L97 because $ref is not defined...

          {
            "name": "body",
            "in": "body",
            "description": "Setup a single immediate payment",
            "required": true,
            "schema": {
....

that is the schema is defined inline not using a reference.

This is a valid swagger file.

mbana avatar Sep 17 '18 11:09 mbana

Yes it looks like the code assumes all parameter schemas are not defined inline.

A PR to support this case would be welcome 👍

mbuhot avatar Sep 18 '18 01:09 mbuhot

I don't have much time on my hands at the moment. Are you likely to add this yourself in the near future, if not, I will just expose this library via REST to just do validation: https://github.com/apigee-127/sway.

mbana avatar Sep 18 '18 09:09 mbana