Skip to content

is_array is applied to all possible responses.  #572

Closed
@toshe

Description

@toshe

There is a problem when defining the responses as an array in the newest version of grape-swagger.
If you define an endpoint as an array then all the possible responses (success & failure) will be generated as references to an array in the swagger doc. However, a single error entity is not an array.
Currently there is no way to know if all the possible responses are an array or just one.

 desc 'Get many belly rubs!',
               {
                   is_array: true,
                   nickname: 'getBellyRubs',
                   success: Entities::BellyRubsEntity, 
                   failure: [[401, 'BadKittenError', SomeErrorEntity],
                             [404, 'NoTreatsError', SomeErrorEntity],
                             [429, 'TooManyScratchesError', SomeErrorEntity]
                   ]
          }

here's the generated code:

"produces":[
   "application/json"
],
"responses":{
   "200":{
      "description":"Get many belly rubs!",
      "schema":{
         "type":"array",
         "items":{
            "$ref":"#/definitions/bellyrub"
         }
      }
   },
   "401":{
      "description":"BadKittenError",
      "schema":{
         "type":"array",
         "items":{
            "$ref":"#/definitions/error"
         }
      }
   },
   "404":{
      "description":"NoTreatsError",
      "schema":{
         "type":"array",
         "items":{
            "$ref":"#/definitions/error"
         }
      }
   },
   "429":{
      "description":"TooManyScratchesError",
      "schema":{
         "type":"array",
         "items":{
            "$ref":"#/definitions/error"
         }
      }
   }
}

The 200 response is correctly rendered as an array but the 401, 404 and 429 Error responses that use a different entity are also rendered as array where in fact they should be a single reference.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions