Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails-api 1.0: 1 processed / 4 skipped issue #171

Open
liuziyuan opened this issue Oct 13, 2017 · 1 comment
Open

rails-api 1.0: 1 processed / 4 skipped issue #171

liuziyuan opened this issue Oct 13, 2017 · 1 comment

Comments

@liuziyuan
Copy link

liuziyuan commented Oct 13, 2017

Hi all
I used rails-api 5.1.2 ,let me show my code

swagger_doc.rb
`Swagger::Docs::Config.base_api_controller = ActionController::API

Swagger::Docs::Config.register_apis({
"1.0" => {
# the extension used for the API
:api_extension_type => :json,
# the output location where your .json files are written to
:api_file_path => "public",
# the URL base path to your API
:base_path => "http://localhost:3000",
# if you want to delete all .json files at each generation
:clean_directory => false,
# Ability to setup base controller for each api version. Api::V1::SomeController for example.
:parent_controller => ApplicationController,
# add custom attributes to api-docs
:attributes => {
:info => {
"title" => "Swagger Sample App",
"description" => "This is a sample description.",
"termsOfServiceUrl" => "http://xxx",
"contact" => "xxx",
"license" => "Apache 2.0",
"licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html"
}
}
}
})
`

UserController.rb
`class Api::V1::UsersController < ApplicationController
include Swagger::Docs::ImpotentMethods

swagger_controller :users, "User Management"

swagger_api :index do
summary "Fetches all User items"
response :unauthorized
response :not_acceptable, "The request you made is not acceptable"
response :requested_range_not_satisfiable
end

swagger_api :show do
summary "Fetches a single User item"
param :path, :id, :integer, :required, "User Id"
response :ok, "Success", :User
response :unauthorized
response :not_acceptable
response :not_found
end

get model list /api/v1/users/index

def index
@user = User.all
render :json => {users: @user} , :status => 200
end

get model by id /api/v1/users/show?id=1

def show
@user = User.find(params[:id])
render :json => {user: @user}, :status => 200
end

create model

def create
@user = User.new(user_params)

if @user.save
  render '200'
else
  render '400'
end

end

update model by id

def update
end

delete model by id

def delete
end

private
def user_params
params.require(:user).permit(:name,:password,:address)
end

end

`

and the last , run command : SD_LOG_LEVEL=1 rake swagger:docs
then generator a the doc file what has not action structure on apis .

{ "apiVersion": "1.0", "swaggerVersion": "1.2", "basePath": "http://localhost:3000", "apis": [ { "path": "/api/v1/users.{format}", "description": "User Management" } ], "authorizations": null, "info": { "title": "Swagger Sample App", "description": "This is a sample description.", "termsOfServiceUrl": "http://xxx", "contact": "xxx", "license": "Apache 2.0", "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html" } }

@fercreek
Copy link

fercreek commented Oct 19, 2017

#147 (comment)
@liuziyuan I solved the issue in this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants