richhollis / swagger-docs

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

uninitialized constant Swagger #177

Closed AstmDesign closed 5 years ago

AstmDesign commented 6 years ago

Guys, I'm using swagger-docs as documentation for my api's and actually it's really amazing Gem, it's working with me well on the development environment but when I was deploying my app on AWS staging environment I found swagger giving me the error:

ERROR -- : uninitialized constant Swagger (NameError)
 /config/initializers/swagger-docs.rb:2:in 

This is my initializer file content

# config/initializers/swagger-docs.rb
Swagger::Docs::Config.register_apis({
  "1.0" => {
    # location where our api doc files will be generated, as of now we will store files under public directory
    :api_file_path => "public/",
    # base path url of our application
    # while using production mode, point it to production url
    :base_path => "http://mydomain.com",
    # setting this option true tells swagger to clean all files generated in api_file_path directory before any files are generated
    :clean_directory => true,
    # the extension used for the API
    :api_extension_type => :json,
    # As we are using Rails-API, our ApplicationController inherits ActionController::API instead of ActionController::Base
    # Hence, we need to add ActionController::API instead of default ActionController::Base
    :base_api_controller => ActionController::API,
    # parent_controller needs to be specified if API controllers are inheriting some other controller than ApplicationController
    # :parent_controller => ApplicationController,
    :attributes => {
      :info => {
        "description" => "This documentation created by using swagger ",
      }
    }
  }
})

#  If you need to change the url
class Swagger::Docs::Config
  def self.transform_path(path, api_version)
    "http://www.mydomain.com/#{path}"
  end
end
AstmDesign commented 6 years ago

This is my server versions information

ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
gem -v
2.5.2
bundle -v
Bundler version 1.16.0
rails -v
Rails 4.2.5.1
AstmDesign commented 5 years ago

Actually it's working well with me on Rails5, maybe this issue because it was old rails version