Add swagger-docs gem to generate ison swagger files
This commit is contained in:
parent
cdb343a81f
commit
30438df244
7 changed files with 109 additions and 5 deletions
2
Gemfile
2
Gemfile
|
@ -74,6 +74,8 @@ gem 'mailjet'
|
|||
|
||||
gem "smart_listing"
|
||||
|
||||
gem 'swagger-docs'
|
||||
|
||||
group :test do
|
||||
gem 'capybara'
|
||||
gem 'factory_girl'
|
||||
|
|
|
@ -380,6 +380,9 @@ GEM
|
|||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
swagger-docs (0.2.8)
|
||||
activesupport (>= 3, < 5)
|
||||
rails (>= 3, < 5)
|
||||
swd (1.0.0)
|
||||
activesupport (>= 3)
|
||||
attr_required (>= 0.0.5)
|
||||
|
@ -493,6 +496,7 @@ DEPENDENCIES
|
|||
smart_listing
|
||||
spring
|
||||
spring-commands-rspec
|
||||
swagger-docs
|
||||
terminal-notifier
|
||||
terminal-notifier-guard
|
||||
therubyracer
|
||||
|
|
|
@ -2,7 +2,7 @@ class API::V1::DossiersController < APIController
|
|||
|
||||
def index
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
dossiers = procedure.dossiers.paginate(page: params[:page])
|
||||
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page])
|
||||
render json: dossiers, each_serializer: DossiersSerializer, meta: pagination(dossiers), meta_key: 'pagination', status: 200
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
render json: {}, status: 404
|
||||
|
@ -18,9 +18,9 @@ class API::V1::DossiersController < APIController
|
|||
|
||||
def pagination(dossiers)
|
||||
{
|
||||
page: dossiers.current_page,
|
||||
resultats_par_page: dossiers.per_page,
|
||||
nombre_de_page: dossiers.total_pages
|
||||
page: dossiers.current_page,
|
||||
resultats_par_page: dossiers.per_page,
|
||||
nombre_de_page: dossiers.total_pages
|
||||
}
|
||||
end
|
||||
end
|
|
@ -1,6 +1,17 @@
|
|||
class API::V1::ProceduresController < APIController
|
||||
def show
|
||||
|
||||
swagger_controller :procedures, "Procédure API"
|
||||
|
||||
swagger_api :show do
|
||||
summary "Récupérer les informations d'une procédure"
|
||||
param :path, :id, :integer, :required
|
||||
param :path, :token, :string, :required
|
||||
response :ok, "Success", :Procedure
|
||||
response :unauthorized
|
||||
response :not_found
|
||||
end
|
||||
|
||||
def show
|
||||
@procedure = current_administrateur.procedures.find(params[:id]).decorate
|
||||
|
||||
render json: @procedure
|
||||
|
|
19
app/views/docs/api-docs.json
Normal file
19
app/views/docs/api-docs.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"apiVersion": "1.0",
|
||||
"swaggerVersion": "1.2",
|
||||
"basePath": "https://tps.apientreprise.fr",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/api/v1/procedures.{format}",
|
||||
"description": "Procédure API"
|
||||
}
|
||||
],
|
||||
"authorizations": null,
|
||||
"info": {
|
||||
"title": "TPS application",
|
||||
"description": "Doc des APIs de TPS",
|
||||
"contact": "contact@tps.apientreprise.fr",
|
||||
"license": "Apache 2.0",
|
||||
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
}
|
45
app/views/docs/api/v1/procedures.json
Normal file
45
app/views/docs/api/v1/procedures.json
Normal file
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"apiVersion": "1.0",
|
||||
"swaggerVersion": "1.2",
|
||||
"basePath": "https://tps.apientreprise.fr",
|
||||
"resourcePath": "procedures",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/api/v1/procedures/{id}.json",
|
||||
"operations": [
|
||||
{
|
||||
"summary": "Récupérer les informations d'une procédure",
|
||||
"parameters": [
|
||||
{
|
||||
"paramType": "path",
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"description": null,
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
23
config/initializers/swagger_docs.rb
Normal file
23
config/initializers/swagger_docs.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
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 => "app/views/docs/",
|
||||
# the URL base path to your API
|
||||
:base_path => "https://tps.apientreprise.fr",
|
||||
# if you want to delete all .json files at each generation
|
||||
:clean_directory => false,
|
||||
# add custom attributes to api-docs
|
||||
:attributes => {
|
||||
:info => {
|
||||
"title" => "TPS application",
|
||||
"description" => "Doc des APIs de TPS",
|
||||
"contact" => "contact@tps.apientreprise.fr",
|
||||
"license" => "Apache 2.0",
|
||||
"licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in a new issue