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

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

CQBinh opened this issue · comments

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

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.

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?

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.

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

Yes, i have and currently using as well.

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.

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