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

New function add_definition_array/2 in cowboy_swagger #118

Merged
merged 4 commits into from
Dec 16, 2019

Conversation

brucify
Copy link
Contributor

@brucify brucify commented Dec 12, 2019

Currently, add_definition/2 hardcodes the the type <<"object">>. It's annoying when I have response as a list of objects such as [{"apple": 1, "banana": 2}, {"apple": 3, "banana": 4}, ...] (Swagger Data Types: Arrays)

Currently I have to write this:

DefinitionName = <<"my_basket">>,
DefinitionProperties =
  #{ apple => #{ type => "string"}
   , banana => #{ type => "string"}
   },
ok = cowboy_swagger:add_definition(DefinitionName, DefinitionProperties),
[...]
, responses =>
    #{ <<"200">> =>
      #{ description => "Gets echo var from the server 200 OK"
       , schema =>
           #{ type => <<"array">>
            , items =>  cowboy_swagger:schema(<<"my_basket">>)
            }

With add_definition_array/2 I can just simply do this:

DefinitionName = <<"my_basket">>,
DefinitionProperties =
  #{ apple => #{ type => "string"}
   , banana => #{ type => "string"}
   },
ok = cowboy_swagger:add_definition_array(DefinitionName, DefinitionProperties),
...
, responses =>
    #{ <<"200">> =>
      #{ description => "Gets echo var from the server 200 OK"
       , schema => cowboy_swagger:schema(<<"my_basket">>)
       }
     }

Copy link
Member

@elbrujohalcon elbrujohalcon left a comment

Choose a reason for hiding this comment

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

This looks really good.
Any chance you can add a test like this one for this?

, items => #{ type => binary()
, properties => property_obj()
}
}}.
-export_type([parameter_definition_name/0, property_obj/0]).
Copy link
Member

Choose a reason for hiding this comment

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

Should we also export the new type? I think we should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@elbrujohalcon elbrujohalcon merged commit 5c4cd20 into inaka:master Dec 16, 2019
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