Skip to content

Commit

Permalink
Add developers documentation
Browse files Browse the repository at this point in the history
Use redoc to make OpenAPI file available on the site
  • Loading branch information
skelz0r committed Sep 23, 2024
1 parent 8d4c5c4 commit 76efa01
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/open_api_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class OpenAPIController < ApplicationController
include Authentication

allow_unauthenticated_access

layout 'application'

def show; end
end
29 changes: 29 additions & 0 deletions app/views/open_api/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div id="redoc_container">
</div>

<script>
function initRedoc() {
var uri = '<%= open_api_v1_path %>';

Redoc.init(
uri,
{
jsonSampleExpandLevel: 'all',
expandResponses: '200',
expandSingleSchemaField: true,
schemaExpansionLevel: 'all'
},
document.getElementById('redoc_container')
)
}

var redocScript = document.createElement("script");

redocScript.src = "https://cdn.jsdelivr.net/npm/redoc@latest/bundles/redoc.standalone.js";

redocScript.onload = function () {
initRedoc();
};

document.documentElement.firstChild.appendChild(redocScript);
</script>
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions features/developpeurs/documentation.feature
Original file line number Diff line number Diff line change
@@ -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"

4 changes: 4 additions & 0 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76efa01

Please sign in to comment.