Skip to content

Instantly share code, notes, and snippets.

@alekseyl
Created November 8, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alekseyl/4c675901924cbd41b16a63eb222c0b56 to your computer and use it in GitHub Desktop.
Save alekseyl/4c675901924cbd41b16a63eb222c0b56 to your computer and use it in GitHub Desktop.
swagger doc example for my note from sitepoint.com/do-the-right-thing-and-document-your-rails-api-with-swagger/
class Api::V1::UsersController < ApplicationController
.....
# 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
def create
@user = User.new(user_params)
if @user.save
render json: @user, status: :created
else
render json: @user.errors, status: :unprocessable_entity
end
end
.....
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment