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

How Can i User Swagger docs for devise sessions controller

vishaltps opened this issue · comments

I used rails swagger gem for documenting my rails api. it is working fine for all controller . but it is not working for devise::sessionsController.

Here is my code ,
I added 2 controller as base in my api
swagger_docs.rb
def self.base_api_controller [ActionController::API,ActionController::Base] end

In sessions_controller.rb

` include Swagger::Docs::Methods
swagger_controller :sessions, "Login"

swagger_api :create do
summary "Generate Access Token"
param :form, 'user[email]', :string, :required, "Email of user"
param :form, 'user[password]', :string ,:required, "Password of user"
response :unauthorized
response :not_acceptable
response :not_acceptable
response :not_found
end`

There is no any error. so my code is not effecting in sessions controller . what is the solution ? Thank you in advance .

commented

Found Solution Yet?

Not yet

I managed to fix this issue and successfully generated swagger docs for devise controllers. (Actually, I used devise_token_auth but the solution is the same)

# Overriden devise controller
class Devise::RegistrationsController < DeviseTokenAuth::RegistrationsController

  include Swagger::Docs::Methods

  swagger_controller :registrations, 'Registration Management'

  swagger_api :create do
    summary 'Sign Up'
    param :query, :title, :string, :required, 'Band Title'
    param :query, :page, :integer, :optional, 'Pagination page number'
    param :query, :per_page, :integer, :optional, 'Number of items per page'
  end

  def create
    super
  end

end
# initializers/swagger_docs.rb
Swagger::Docs::Config.register_apis({
                                      '1.0' => {
                                        controller_base_path: '',
                                        api_file_path: 'public/apidocs',
                                        base_api_controllers: [ActionController::Base, Devise::RegistrationsController],
                                        base_path: Rails.application.config.domain,
                                        clean_directory: true
                                      }
                                    })

Hi sergeymell How did you manage to implement swagger with devise? I couldn't, the message tells me that I am not authorized.

Thanks for your answer