richhollis / swagger-docs

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

klass.methods doesn't include :swagger_config #147

Open ayudemura opened 8 years ago

ayudemura commented 8 years ago

I am experiencing the identical problem as #104 (which is closed) I am hoping to get some help on config.

My swagger_docs.rb initialization is

Swagger::Docs::Config.register_apis({
  "1.0" => {
    :api_file_path => "public/api/v1/",
    :base_path => "https://app.x.net/api",
    :clean_directory => true,
    :parent_controller => ApplicationController,
    :base_api_controller => ActionController::API,
    :controller_base_path => "",
    :attributes => {
      :info => {
        "title" => "X API",
        "description" => "Documentation for X API.",
        "license" => "Apache 2.0",
        "licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html"
      }
    }
  }
})
ace commented 7 years ago

I'm having the same error. The problem is that register_apis is not using the base_api_controller param, it's using its own default (ActionController::Base). If you use this controller as your base, everything works, but using ActionController::API fails.

As a workaround, adding a line before that call, setting the base controller, solves the problem:

Swagger::Docs::Config.base_api_controller = ActionController::API.

fercreek commented 6 years ago

I have this same problem

fercreek commented 6 years ago

I found two ways to solve this:

Swagger::Docs::Config.register_apis({})

class Swagger::Docs::Config def self.base_api_controller ActionController::API end end


Or adding at the top of `routes.rb`
```rb
Swagger::Docs::Config.base_api_controller = ActionController::API
include Swagger::Docs::ImpotentMethods
msdundar commented 6 years ago

Same here! Workarounds are not working with Rails 5 using an ActionController::API.

misa-itk commented 5 years ago

Having same problem. Controllers without index action are not taken for making swagger file. @fercreek did you tried with rails 5.2 api ? @msdundar have you found the solution?