richhollis / swagger-docs

Generates swagger-ui json files for Rails APIs with a simple DSL.
MIT License
750 stars 150 forks source link

Param as type "array" in swagger_api #180

Open toshitapandey opened 5 years ago

toshitapandey commented 5 years ago

I am trying to send a param with type array, but the params that I am getting in the controller is always of type string.

Swagger_api definition:
swagger_api :invite do
          summary 'Invite employees to organization'
          param :form, 'organization[emails]', :array, :optional, 'Employee emails (should be array)'
          param :header, 'auth-token', :string, :required, 'Authentication token'
          response :unauthorized
          response :not_acceptable, 'The request you made is not acceptable'
end
Generated swagger doc:

image

Params that I am getting in the controller:
=> <ActionController::Parameters {"organization"=>{"emails"=>"['user1@gmail.com', 'user2@gmail.com']"}, "controller"=>"api/v1/organizations", "action"=>"invite"} permitted: false>

Is array even supported? Or do I need to change something here?

vamsipavanmahesh commented 3 years ago

@toshitapandey did you end up solving this?

toshitapandey commented 3 years ago

@vamsipavanmahesh - no, I ended up changing my API format and had the frontend send it in the way that swagger sends it.

vamsipavanmahesh commented 3 years ago

we ended up changing from array to comma-separated string. Found this pattern in many sites, including JIRA @toshitapandey