richhollis / swagger-docs

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

Does it work with rails-api? (Clone from #75) #122

Closed CQBinh closed 8 years ago

CQBinh commented 9 years ago

Hi, i meet the same issue with issue #75 I have follow his solluton, here is my config:

Swagger::Docs::Config.base_api_controller = ActionController::API 
# Sollution from github docs: https://github.com/richhollis/swagger-docs#inheriting-from-a-custom-api-controller
# class Swagger::Docs::Config
#   def self.base_api_controller
#     ActionController::API  
#   end
# end

Swagger::Docs::Config.register_apis({
  "1.0" => {
    :controller_base_path => "",
    :api_file_path => "public"
  }
})

And i still get 1.0: 0 processed / 4 skipped when run rake task. My controller:

class UsersController < ApplicationController
  # include Swagger::Docs::ImpotentMethods
  #   Swagger::Docs::Generator::set_real_methods

  swagger_controller :users, "Users"

  swagger_api :index do
    summary "Fetches all users"
    response :unauthorized
    response :not_acceptable
  end

  def index
    render :json => {result:"Success"}, :status => 200
  end

end
kartikv11 commented 9 years ago

Swagger checks for and scans for controller files in your rails app, hence it even scans - ApplicationController, ActionController, AccessController, ... etc as many controllers might be present and hence marks them as skipped when you run the rake task with command- _$rake swagger:docs_

Hence, this i presume is working as expected. I guess this issue can be closed hence.

CQBinh commented 9 years ago

Thanks, but the main issue that i want to focus is: there is no Controller get processed. And I don't know how to fix it :( Could you tell me?

kartikv11 commented 9 years ago

Swagger works on a Controller method or an API you are framing up or there must be something wrong with your swagger configs. I would recommend you to go through the Swagger documentation again of how the Swagger fetches the Controller functions and it's corresponding swagger config.

CQBinh commented 9 years ago

Did you config swagger-docs for rails-api before? I don't know what wrong with me code (above).

kartikv11 commented 9 years ago

Yes, i have and currently using as well.

CQBinh commented 9 years ago

So, could you write a mini demo, so I can compare and figure out what wrong in my code. I'm really appriciate your help. Thanks again.

richhollis commented 8 years ago

In addition to the obeservations above, swagger-docs was not built to specifically support rails-api.