From 524406b710569f07e879fe21750c9245420f0276 Mon Sep 17 00:00:00 2001 From: Ludovic Dussart Date: Fri, 12 Feb 2021 16:39:36 +0100 Subject: [PATCH] feat: add version parameter to allow version override Close #107 --- README.md | 1 + macros/commons.html | 8 ++++++++ package.json | 4 ++++ partials/introduction.html | 5 ++++- partials/sidebar.html | 5 +++-- template/index.html | 4 +++- 6 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 macros/commons.html diff --git a/README.md b/README.md index 9093a3507..c09726279 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ npm install -g @asyncapi/generator |---|---|---|---|---| |sidebarOrganization|Defines how the sidebar should be organized. Set its value to `byTagsNoRoot` to categorize operations by operations tags. Set its value to `byTags` when you have tags on a root level. These tags are used to model tags navigation and need to have the same tags in operations.|No|`byTags`, `byTagsNoRoot`|`byTagsNoRoot`| |baseHref|Sets the base URL for links and forms.|No|*Any*|`/docs`| +|version|Override the Async API version displayed in the generated pages.|No|*Any* ([See Semver versionning](https://semver.org/))|`1.0.0`| |singleFile|Set output into one html-file with styles and scripts inside|No|`true`,`false`|`true`| |outFilename|The filename of the output file.|No|*Any*|`asyncapi.html`| |pdf|Generates output HTML as PDF|No|`true,false`|`false`| diff --git a/macros/commons.html b/macros/commons.html new file mode 100644 index 000000000..040979974 --- /dev/null +++ b/macros/commons.html @@ -0,0 +1,8 @@ +{% macro getApiVersion() %} + {% if params.version %} + {% set version = params.version %} + {% else %} + {% set version = asyncapi.info().version() %} + {% endif %} + {{version}} +{% endmacro %} diff --git a/package.json b/package.json index 4e1b573e7..bedd869fb 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,10 @@ "description": "Sets the base URL for links and forms.", "required": false }, + "version": { + "description": "Override the Async API version displayed in the generated pages.", + "required": false + }, "singleFile": { "description": "If set this parameter to true generate single html file with scripts and styles inside", "required": false, diff --git a/partials/introduction.html b/partials/introduction.html index 3f7050f9a..feb6b4f8d 100644 --- a/partials/introduction.html +++ b/partials/introduction.html @@ -1,6 +1,9 @@ +{% from "macros/commons.html" import getApiVersion with context %} +
-

{{asyncapi.info().title()}} {{asyncapi.info().version()}}

+ +

{{asyncapi.info().title()}} {{getApiVersion()}}

-
\ No newline at end of file + diff --git a/template/index.html b/template/index.html index 631dbc93a..4f8feb08b 100644 --- a/template/index.html +++ b/template/index.html @@ -1,11 +1,13 @@ +{% from "macros/commons.html" import getApiVersion with context %} {% if params.baseHref %} {% endif %} - {{asyncapi.info().title()}} {{asyncapi.info().version()}} documentation + + {{asyncapi.info().title()}} {{getApiVersion()}} documentation {% if params.singleFile %}