Skip to content

Commit

Permalink
Enable Access to API PART v3 swagger
Browse files Browse the repository at this point in the history
Url is not accessible unless you type it in your browser for now.
This is intended as we can share our url to specific people and continue
our review.
This will also allow syntax checking on the siade_staging_data
repository.

This commit can be reverted once the v3 will be the main swagger on the
siade repository. This has been specified in the dedicated issue on
linear.
  • Loading branch information
Un3x committed Dec 3, 2024
1 parent 8a2e9de commit 8035f9a
Show file tree
Hide file tree
Showing 10 changed files with 7,418 additions and 183 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api_particulier/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def redoc
render 'shared/pages/redoc'
end

def redoc_v3
render 'shared/pages/redoc_v3'
end

def mentions
render 'shared/pages/mentions'
end
Expand Down
10 changes: 7 additions & 3 deletions app/services/abstract_open_api_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ def open_api_without_deprecated_paths_definition_content
backend.merge('paths' => paths).to_yaml
end

# rubocop:disable Security/Open
def open_api_definition_content
open_api_remote_url_definition_content(remote_url)
end

# rubocop:disable Security/Open
def open_api_remote_url_definition_content(url)
if load_local?
local_path.read
else
Rails.cache.fetch(remote_url, expires_in: 1.hour) do
URI.open(remote_url).read
Rails.cache.fetch(url, expires_in: 1.hour) do
URI.open(url).read
end
end
rescue StandardError, OpenURI::HTTPError => e
Expand Down
14 changes: 14 additions & 0 deletions app/services/api_particulier/open_api_definition.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
class APIParticulier::OpenAPIDefinition < AbstractOpenAPIDefinition
def open_api_v3_definition_content
open_api_remote_url_definition_content(remote_url_v3)
end

protected

def local_path
Rails.root.join('config/api-particulier-openapi.yml')
end

def remote_url_v3
if Rails.env.sandbox?
'https://sandbox.particulier.api.gouv.fr/api/open-api-v3.yml'
elsif Rails.env.staging? || Rails.env.development?
'https://staging.particulier.api.gouv.fr/api/open-api-v3.yml'
else
'https://particulier.api.gouv.fr/api/open-api-v3.yml'
end
end

def remote_url
if Rails.env.sandbox?
'https://sandbox.particulier.api.gouv.fr/api/open-api.yml'
Expand Down
42 changes: 42 additions & 0 deletions app/views/shared/pages/redoc_v3.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="fr-container">
<div class="">
<h1>
<%= t('.title') %>
</h1>

<p>
<%= t('.description', api_name: api_name).html_safe %>
</p>
</div>
</div>

<div class="fr-mt-5w" id="redoc_container">
</div>

<script>
function initRedoc() {
var uri = '<%= api_particulier_openapi_v3_definition_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: 3 additions & 0 deletions bin/download_latest_open_api_definitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
wget "https://particulier.api.gouv.fr/api/open-api.yml" \
-O config/api-particulier-openapi.yml

wget "https://particulier.api.gouv.fr/api/open-api-v3.yml" \
-O config/api-particulier-openapi-v3.yml

wget "https://entreprise.api.gouv.fr/v3/openapi-entreprise.yaml" \
-O config/api-entreprise-v3-openapi.yml
235 changes: 79 additions & 156 deletions config/api-entreprise-v3-openapi.yml

Large diffs are not rendered by default.

Loading

0 comments on commit 8035f9a

Please sign in to comment.