Skip to content

Commit

Permalink
feat: ajout composant swagger-ui #21
Browse files Browse the repository at this point in the history
Co-authored-by: pprevautel <[email protected]>
  • Loading branch information
ocruze and pprev94 committed May 21, 2024
1 parent 5f5a9c4 commit 4103291
Show file tree
Hide file tree
Showing 7 changed files with 1,647 additions and 71 deletions.
10 changes: 10 additions & 0 deletions _includes/components/swaggerui.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div id="{{ params.targetId }}" class="frx-swagger-ui"></div>
<script>
window.addEventListener('load', function() {
SwaggerUIBundle({
url: "{{ params.url }}",
dom_id: "{{ '#' ~ params.targetId }}",
docExpansion: "{{ (params.docExpansion|default('none')) }}"
});
});
</script>
4 changes: 4 additions & 0 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<script src="/js/mermaid.min.js"></script>
<script src="/js/mermaid.initialize.js"></script>
{% endif %}
{% if swaggerui %}
<link rel="stylesheet" href="/css/swagger-ui.css">
<script src="/js/swagger-ui.js"></script>
{% endif %}
<script src="/js/copy.js" defer></script>
<title>{{ title or metadata.title }}</title>
</head>
Expand Down
40 changes: 40 additions & 0 deletions content/fr/blog/posts/swagger-ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Intégration du Swagger UI
description: Comment intégrer le Swagger UI dans une page du site ?
date: git Last Modified
swaggerui: true
tags:
- composant
---

Chaque composant peut être inclus dans un fichier Nunjucks `.njk` ou Markdown `.md`.

## Exemple d'utilisation

```njk
{% raw %}
{% from "components/component.njk" import component with context %}
{{ component("swaggerui", {
url: "https://data-qua.priv.geopf.fr/api/v3/api-docs",
targetId: "swagger-ui-demo"
}) }}
{% endraw %}
```

Le format complet de l'objet en paramètre est le suivant :

```json
{
"url": "string",
"targetId": "string",
"docExpansion": "full|list|none*"
}
```

## Rendu

{% from "components/component.njk" import component with context %}
{{ component("swaggerui", {
url: "https://data-qua.priv.geopf.fr/api/v3/api-docs",
targetId: "swagger-ui-demo"
}) }}
2 changes: 2 additions & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = function (eleventyConfig) {
"./node_modules/@gouvfr/dsfr/dist/dsfr.nomodule.min.js": "/js/dsfr.nomodule.min.js",
"./node_modules/@gouvfr/dsfr/dist/artwork": "/artwork",
"./node_modules/mermaid/dist/mermaid.min.js": "/js/mermaid.min.js",
"./node_modules/swagger-ui/dist/swagger-ui.css": "/css/swagger-ui.css",
"./node_modules/swagger-ui/dist/swagger-ui-bundle.js": "/js/swagger-ui.js",
});

// Run Eleventy when these files change:
Expand Down
1,653 changes: 1,583 additions & 70 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
},
"dependencies": {
"@codegouvfr/eleventy-plugin-calendar": "^3.0.4",
"@codegouvfr/eleventy-plugin-i18n": "^0.1.3"
"@codegouvfr/eleventy-plugin-i18n": "^0.1.3",
"swagger-ui": "^5.17.10"
},
"lint-staged": {
"*.{js,json,md}": [
Expand Down
6 changes: 6 additions & 0 deletions public/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,9 @@ pre[class*="language"] {
right: 0.5em;
top: 0.5em;
}

.frx-swagger-ui {
background-color: #ffffff;
padding-top: 0.8rem;
padding-bottom: 0.8rem;
}

0 comments on commit 4103291

Please sign in to comment.