-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: give this api some chance with some swag
- Loading branch information
1 parent
8d949f6
commit e98b205
Showing
6 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
class Api::PokemonsController < ApplicationController | ||
|
||
swagger_controller :pokemons, "Pokemons" | ||
|
||
swagger_api :index do | ||
summary "To list pokemons" | ||
response :success | ||
response 500, "Internal Error" | ||
end | ||
def index | ||
render json: Pokemon.preload(:pokemon_types, :types).all, include: ['types'] | ||
end | ||
|
||
swagger_api :show do | ||
summary "To view the detail of a pokemon" | ||
param :id, :integer, :required, "ID of the pokemon" | ||
response :success | ||
response :not_found | ||
response 500, "Internal Error" | ||
end | ||
def show | ||
render json: Pokemon.find(params[:id]), include: ['types'] | ||
begin | ||
pokemon = Pokemon.find(params[:id]) | ||
|
||
render json: pokemon, include: ['types'] | ||
rescue | ||
render json: :not_found, status: :not_found | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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, | ||
# parent_controller needs to be specified if API controllers are inheriting some other controller than ApplicationController | ||
# :parent_controller => ApplicationController, | ||
:attributes => { | ||
:info => { | ||
"title" => "Regate API Doc", | ||
"description" => "Give this API some SWAG", | ||
"contact" => "[email protected]", | ||
"license" => "WTFPL", | ||
"licenseUrl" => "http://www.wtfpl.net/txt/copying/" | ||
} | ||
} | ||
} | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"apiVersion": "1.0", | ||
"swaggerVersion": "1.2", | ||
"basePath": "http://localhost:3000", | ||
"apis": [ | ||
{ | ||
"path": "/api/pokemons.{format}", | ||
"description": "Pokemons" | ||
} | ||
], | ||
"authorizations": null, | ||
"info": { | ||
"title": "Regate API Doc", | ||
"description": "Give this API some SWAG", | ||
"contact": "[email protected]", | ||
"license": "WTFPL", | ||
"licenseUrl": "http://www.wtfpl.net/txt/copying/" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"apiVersion": "1.0", | ||
"swaggerVersion": "1.2", | ||
"basePath": "http://localhost:3000", | ||
"resourcePath": "pokemons", | ||
"apis": [ | ||
{ | ||
"path": "/api/pokemons", | ||
"operations": [ | ||
{ | ||
"summary": "To list pokemons", | ||
"responseMessages": [ | ||
{ | ||
"code": 200, | ||
"responseModel": null, | ||
"message": "Ok" | ||
}, | ||
{ | ||
"code": 500, | ||
"responseModel": null, | ||
"message": "Internal Error" | ||
} | ||
], | ||
"nickname": "Api::Pokemons#index", | ||
"method": "get" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "/api/pokemons/{id}", | ||
"operations": [ | ||
{ | ||
"summary": "To view the detail of a pokemon", | ||
"responseMessages": [ | ||
{ | ||
"code": 200, | ||
"responseModel": null, | ||
"message": "Ok" | ||
}, | ||
{ | ||
"code": 404, | ||
"responseModel": null, | ||
"message": "Not Found" | ||
}, | ||
{ | ||
"code": 500, | ||
"responseModel": null, | ||
"message": "Internal Error" | ||
} | ||
], | ||
"parameters": [ | ||
{ | ||
"paramType": "id", | ||
"name": "integer", | ||
"type": "required", | ||
"description": null, | ||
"required": false | ||
} | ||
], | ||
"nickname": "Api::Pokemons#show", | ||
"method": "get" | ||
} | ||
] | ||
} | ||
], | ||
"authorizations": null | ||
} |