richhollis / swagger-docs

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

1.0: 0 processed / 1 skipped #168

Open flaviolpgjr opened 7 years ago

flaviolpgjr commented 7 years ago

Hi, can anyone help me please, already tried in all possible ways, but this is returning the same error: 1.0: 0 processed / 4 skipped, when running :

SD_LOG_LEVEL=1 rake swagger:docs

swagger-docs.rb:

# config/initializers/swagger-docs.rb
Swagger::Docs::Config.base_api_controller = ActionController::API
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://localhost:3000",
    # setting this option true tells swagger to clean all files generated in api_file_path directory before any files are generated
    :clean_directory => true,
    # 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,
    :attributes => {
      :info => {
        "title" => "Swagger Demo",
        "description" => "How Swagger works",
        "contact" => "parthmodi54@yahoo.com",
        "license" => "Apache 2.0",
        "licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html"
      }
    }
  }
})

users_controller.rb

class Api::V1::UsersController < ApplicationController
  before_action :set_api_v1_user, only: [:show, :update, :destroy]

  swagger_controller :users, "User Management"

   # POST /users
  swagger_api :create do
    summary "To create user"
    notes "Implementation notes, such as required params, example queries for apis are written here."
    param :form, "user[name]", :string, :required, "Name of user"
    param :form, "user[age]", :integer, :optional, "Age of user"
    param_list :form, "user[status]", :string, :required, "Status of user, can be active or inactive"
    response :success
    response :unprocessable_entity
    response :500, "Internal Error"
  end

  # POST /api/v1/users
  def create
    @api_v1_user = Api::V1::User.new(api_v1_user_params)

    if @api_v1_user.save
      render json: @api_v1_user, status: :created, location: @api_v1_user
    else
      render json: @api_v1_user.errors, status: :unprocessable_entity
    end
  end
end
zhandao commented 7 years ago

try :base_api_controller => ActionController

flaviolpgjr commented 7 years ago

Thank you very much, I have decided to add in config/routes.rb

namespace :api do
    namespace :v1 do
      resources :users
    end
  end
fercreek commented 7 years ago

https://github.com/richhollis/swagger-docs/issues/147#issuecomment-337801122

I solved the issue in this way

flaviolpgjr commented 7 years ago

Thank you Friends

msdundar commented 7 years ago

same issue here! I'm using Rails 5 API, and workarounds are not working.

fercreek commented 7 years ago

@msdundar did you try with my solution?

msdundar commented 7 years ago

@fercreek yes it has fixed the issue! thanks.

fercreek commented 7 years ago

@msdundar great! I'm glad for you. @richhollis can you check if this is the best solution for this issue?