inaka / cowboy_swagger

Swagger integration for Cowboy (built on trails)
http://inaka.net/blog/2015/08/19/cowboy-swagger/
Apache License 2.0
120 stars 58 forks source link

New function add_definition_array/2 in cowboy_swagger #118

Closed brucify closed 4 years ago

brucify commented 4 years ago

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">>)
       }
     }