richhollis / swagger-docs

Generates swagger-ui json files for Rails APIs with a simple DSL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Param as type "array" in swagger_api

toshitapandey opened this issue · comments

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?

@toshitapandey did you end up solving this?

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

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