Swagger docs

This commit is contained in:
Xavier J 2016-02-18 18:02:07 +01:00
parent a643f34621
commit c3410c104b
10 changed files with 280 additions and 1 deletions

View file

@ -77,6 +77,9 @@ gem "smart_listing"
gem 'css_splitter' gem 'css_splitter'
gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8' gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8'
gem 'swagger-docs'
gem 'grape-swagger-rails'
group :test do group :test do
gem 'capybara' gem 'capybara'
gem 'factory_girl' gem 'factory_girl'

View file

@ -55,6 +55,10 @@ GEM
autoprefixer-rails (5.2.1) autoprefixer-rails (5.2.1)
execjs execjs
json json
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.10) bcrypt (3.1.10)
bindata (2.1.0) bindata (2.1.0)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
@ -85,6 +89,8 @@ GEM
ffi (~> 1.0, >= 1.0.11) ffi (~> 1.0, >= 1.0.11)
cliver (0.3.2) cliver (0.3.2)
coderay (1.1.0) coderay (1.1.0)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
coffee-rails (4.1.0) coffee-rails (4.1.0)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
@ -99,6 +105,8 @@ GEM
sprockets (>= 2.0.0) sprockets (>= 2.0.0)
database_cleaner (1.4.1) database_cleaner (1.4.1)
debug_inspector (0.0.2) debug_inspector (0.0.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (3.4.1) devise (3.4.1)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
@ -118,6 +126,7 @@ GEM
em-websocket (0.5.1) em-websocket (0.5.1)
eventmachine (>= 0.12.9) eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0) http_parser.rb (~> 0.6.0)
equalizer (0.0.11)
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.0.8) eventmachine (1.0.8)
execjs (2.5.2) execjs (2.5.2)
@ -131,6 +140,25 @@ GEM
formatador (0.2.5) formatador (0.2.5)
globalid (0.3.5) globalid (0.3.5)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
grape (0.14.0)
activesupport
builder
hashie (>= 2.1.0)
multi_json (>= 1.3.2)
multi_xml (>= 0.5.2)
rack (>= 1.3.0)
rack-accept
rack-mount
virtus (>= 1.0.0)
grape-entity (0.4.8)
activesupport
multi_json (>= 1.3.2)
grape-swagger (0.10.4)
grape (>= 0.8.0)
grape-entity (< 0.5.0)
grape-swagger-rails (0.1.0)
grape-swagger (>= 0.7.2)
railties (>= 3.2.12)
guard (2.13.0) guard (2.13.0)
formatador (>= 0.2.4) formatador (>= 0.2.4)
listen (>= 2.7, <= 4.0) listen (>= 2.7, <= 4.0)
@ -168,6 +196,7 @@ GEM
http_parser.rb (0.6.0) http_parser.rb (0.6.0)
httpclient (2.6.0.1) httpclient (2.6.0.1)
i18n (0.7.0) i18n (0.7.0)
ice_nine (0.11.2)
jbuilder (2.3.1) jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
@ -212,6 +241,7 @@ GEM
mini_portile (0.6.2) mini_portile (0.6.2)
minitest (5.7.0) minitest (5.7.0)
multi_json (1.11.2) multi_json (1.11.2)
multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
nenv (0.2.0) nenv (0.2.0)
netrc (0.10.3) netrc (0.10.3)
@ -255,6 +285,10 @@ GEM
byebug (~> 5.0) byebug (~> 5.0)
pry (~> 0.10) pry (~> 0.10)
rack (1.6.4) rack (1.6.4)
rack-accept (0.4.5)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-oauth2 (1.2.1) rack-oauth2 (1.2.1)
activesupport (>= 2.3) activesupport (>= 2.3)
attr_required (>= 0.0.5) attr_required (>= 0.0.5)
@ -384,6 +418,9 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
swagger-docs (0.2.8)
activesupport (>= 3, < 5)
rails (>= 3, < 5)
swd (1.0.0) swd (1.0.0)
activesupport (>= 3) activesupport (>= 3)
attr_required (>= 0.0.5) attr_required (>= 0.0.5)
@ -420,6 +457,11 @@ GEM
validate_url (1.0.2) validate_url (1.0.2)
activemodel (>= 3.0.0) activemodel (>= 3.0.0)
addressable addressable
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
web-console (2.2.1) web-console (2.2.1)
@ -463,6 +505,7 @@ DEPENDENCIES
draper draper
factory_girl factory_girl
font-awesome-rails font-awesome-rails
grape-swagger-rails
guard guard
guard-livereload (~> 2.4) guard-livereload (~> 2.4)
guard-rspec guard-rspec
@ -499,6 +542,7 @@ DEPENDENCIES
smart_listing smart_listing
spring spring
spring-commands-rspec spring-commands-rspec
swagger-docs
terminal-notifier terminal-notifier
terminal-notifier-guard terminal-notifier-guard
therubyracer therubyracer

View file

@ -1,5 +1,26 @@
class API::V1::DossiersController < APIController class API::V1::DossiersController < APIController
swagger_controller :dossiers, "Dossiers"
swagger_api :index do
summary "Récupérer la liste de ses dossiers."
param :path, :procedure_id, :integer, "Procédure ID"
param :query, :token, :integer, "Admin TOKEN"
response :ok, "Success", :Dossier
response :unauthorized
response :not_found
end
swagger_api :show do
summary "Récupérer le détails d'un dossier."
param :path, :procedure_id, :integer, "Procédure ID"
param :path, :id, :integer, "Dossier ID"
param :query, :token, :integer, "Admin TOKEN"
response :ok, "Success", :Dossier
response :unauthorized
response :not_found
end
def index def index
procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure = current_administrateur.procedures.find(params[:procedure_id])
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page]) dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page])

View file

@ -1,4 +1,16 @@
class API::V1::ProceduresController < APIController class API::V1::ProceduresController < APIController
swagger_controller :procedures, "Procédures"
swagger_api :show do
summary "Récupérer la liste de ses procédures."
param :path, :id, :integer, "Procédure ID"
param :query, :token, :integer, "Admin TOKEN"
response :ok, "Success", :Procedure
response :unauthorized
response :not_found
end
def show def show
@procedure = current_administrateur.procedures.find(params[:id]).decorate @procedure = current_administrateur.procedures.find(params[:id]).decorate
@ -7,5 +19,4 @@ class API::V1::ProceduresController < APIController
Rails.logger.error(e.message) Rails.logger.error(e.message)
render json: {}, status: 404 render json: {}, status: 404
end end
end end

View file

@ -0,0 +1,3 @@
GrapeSwaggerRails.options.url = 'api-docs.json'
GrapeSwaggerRails.options.app_name = 'API TéléProcédure Simplifiée'
GrapeSwaggerRails.options.app_url = TPS::Application::URL

View file

@ -0,0 +1,21 @@
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 => TPS::Application::URL,
# 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 => API::V1,
# add custom attributes to api-docs
:attributes => {
:info => {
"title" => "API TéléProcédure Simplifiée",
"description" => "",
}
}
}
})

View file

@ -25,6 +25,8 @@ Rails.application.routes.draw do
root 'root#index' root 'root#index'
mount GrapeSwaggerRails::Engine => '/docs'
namespace :france_connect do namespace :france_connect do
get 'particulier' => 'particulier#login' get 'particulier' => 'particulier#login'
get 'particulier/callback' => 'particulier#callback' get 'particulier/callback' => 'particulier#callback'

20
public/api-docs.json Normal file
View file

@ -0,0 +1,20 @@
{
"apiVersion": "1.0",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000",
"apis": [
{
"path": "/api/v1/dossiers.{format}",
"description": "Dossiers"
},
{
"path": "/api/v1/procedures.{format}",
"description": "Procédures"
}
],
"authorizations": null,
"info": {
"title": "API TéléProcédure Simplifiée",
"description": ""
}
}

102
public/api/v1/dossiers.json Normal file
View file

@ -0,0 +1,102 @@
{
"apiVersion": "1.0",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000",
"resourcePath": "dossiers",
"apis": [
{
"path": "/api/v1/procedures/{procedure_id}/dossiers",
"operations": [
{
"summary": "Récupérer la liste de ses dossiers.",
"parameters": [
{
"paramType": "path",
"name": "procedure_id",
"type": "integer",
"description": null,
"required": false
},
{
"paramType": "query",
"name": "token",
"type": "integer",
"description": null,
"required": false
}
],
"responseMessages": [
{
"code": 200,
"responseModel": "Dossier",
"message": "Success"
},
{
"code": 401,
"responseModel": null,
"message": "Unauthorized"
},
{
"code": 404,
"responseModel": null,
"message": "Not Found"
}
],
"nickname": "API::V1::Dossiers#index",
"method": "get"
}
]
},
{
"path": "/api/v1/procedures/{procedure_id}/dossiers/{id}",
"operations": [
{
"summary": "Récupérer le détails d'un dossier.",
"parameters": [
{
"paramType": "path",
"name": "procedure_id",
"type": "integer",
"description": null,
"required": false
},
{
"paramType": "path",
"name": "id",
"type": "integer",
"description": null,
"required": false
},
{
"paramType": "query",
"name": "token",
"type": "integer",
"description": null,
"required": false
}
],
"responseMessages": [
{
"code": 200,
"responseModel": "Dossier",
"message": "Success"
},
{
"code": 401,
"responseModel": null,
"message": "Unauthorized"
},
{
"code": 404,
"responseModel": null,
"message": "Not Found"
}
],
"nickname": "API::V1::Dossiers#show",
"method": "get"
}
]
}
],
"authorizations": null
}

View file

@ -0,0 +1,52 @@
{
"apiVersion": "1.0",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000",
"resourcePath": "procedures",
"apis": [
{
"path": "/api/v1/procedures/{id}",
"operations": [
{
"summary": "Récupérer la liste de ses procédures.",
"parameters": [
{
"paramType": "path",
"name": "id",
"type": "integer",
"description": null,
"required": false
},
{
"paramType": "query",
"name": "token",
"type": "integer",
"description": null,
"required": false
}
],
"responseMessages": [
{
"code": 200,
"responseModel": "Procedure",
"message": "Success"
},
{
"code": 401,
"responseModel": null,
"message": "Unauthorized"
},
{
"code": 404,
"responseModel": null,
"message": "Not Found"
}
],
"nickname": "API::V1::Procedures#show",
"method": "get"
}
]
}
],
"authorizations": null
}