From 76efa01c65c2b570a78143f58806cb129e4f6ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Mon, 23 Sep 2024 11:10:39 +0200 Subject: [PATCH] Add developers documentation Use redoc to make OpenAPI file available on the site --- app/controllers/open_api_controller.rb | 9 +++++++ app/views/open_api/show.html.erb | 29 +++++++++++++++++++++ config/routes.rb | 3 ++- features/developpeurs/documentation.feature | 9 +++++++ features/step_definitions/web_steps.rb | 4 +++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/controllers/open_api_controller.rb create mode 100644 app/views/open_api/show.html.erb create mode 100644 features/developpeurs/documentation.feature diff --git a/app/controllers/open_api_controller.rb b/app/controllers/open_api_controller.rb new file mode 100644 index 000000000..79708706b --- /dev/null +++ b/app/controllers/open_api_controller.rb @@ -0,0 +1,9 @@ +class OpenAPIController < ApplicationController + include Authentication + + allow_unauthenticated_access + + layout 'application' + + def show; end +end diff --git a/app/views/open_api/show.html.erb b/app/views/open_api/show.html.erb new file mode 100644 index 000000000..25f789b3b --- /dev/null +++ b/app/views/open_api/show.html.erb @@ -0,0 +1,29 @@ +
+
+ + diff --git a/config/routes.rb b/config/routes.rb index f7a446b16..4f94606f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,7 +86,8 @@ skip_controllers :applications, :authorized_applications end - get '/api-docs/v1.yaml', to: ->(env) { [200, { 'Content-Type' => 'application/yaml' }, [File.read(Rails.root.join('config/openapi/v1.yaml'))]] } + get '/api-docs/v1.yaml', to: ->(env) { [200, { 'Content-Type' => 'application/yaml', 'Content-Disposition' => 'inline;filename="datapass-v1.yaml"' }, [File.read(Rails.root.join('config/openapi/v1.yaml'))]] }, as: :open_api_v1 + get '/developpeurs/documentation', to: 'open_api#show' namespace :api do resources :frontal, only: :index diff --git a/features/developpeurs/documentation.feature b/features/developpeurs/documentation.feature new file mode 100644 index 000000000..4cf8a8bee --- /dev/null +++ b/features/developpeurs/documentation.feature @@ -0,0 +1,9 @@ +# language: fr + +Fonctionnalité: Développeurs: consultation de la documentation + @javascript + + Scénario: Je peux voir la documentation OpenAPI de manière jolie + Quand je me rends sur le chemin "/developpeurs/documentation" + Alors la page contient "API DataPass" + diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index da2287ece..88cd47d92 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -2,6 +2,10 @@ visit root_path end +Quand("je me rends sur le chemin {string}") do |string| + visit string +end + Quand('print the page') do log page.body end