Created
November 8, 2017 15:22
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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