From 80600b674ad6c37239d48fb75fadcc095868761e Mon Sep 17 00:00:00 2001 From: Ludovic Dussart Date: Wed, 17 Feb 2021 13:04:54 +0100 Subject: [PATCH] feat: add version parameter to allow version override (#147) --- README.md | 15 ++++++++------- macros/commons.html | 8 ++++++++ package.json | 4 ++++ partials/introduction.html | 5 ++++- partials/sidebar.html | 5 +++-- template/index.html | 4 +++- 6 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 macros/commons.html diff --git a/README.md b/README.md index 9093a3507..e3b26c352 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,14 @@ npm install -g @asyncapi/generator ## Supported parameters -|Name|Description|Required|Allowed values|Example| -|---|---|---|---|---| -|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`| -|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`| +|Name|Description|Required|Default|Allowed values|Example| +|---|---|---|---|---|---| +|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|undefined|`byTags`, `byTagsNoRoot`|`byTagsNoRoot`| +|baseHref|Sets the base URL for links and forms.|No|`/`|*Any*|`/docs`| +|version|Override the version of your application provided under `info.version` location in the specification file.|No|Version is taken from the spec file.|*Any* ([See Semver versionning](https://semver.org/))|`1.0.0`| +|singleFile|Set output into one html-file with styles and scripts inside|No|`false`|`true`,`false`|`true`| +|outFilename|The filename of the output file.|No|`index.html`|*Any*|`asyncapi.html`| +|pdf|Generates output HTML as PDF|No|`false`|`true,false`|`false`| If you only generate an html website, set the environment variable `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` to `true` and the generator will skip downloading chromium. 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 6033e8d8b..e997f5a6b 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,10 @@ "description": "Sets the base URL for links and forms.", "required": false }, + "version": { + "description": "Override the version of your application provided under `info.version` location in the specification file.", + "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 cde8b3c20..e83ea9780 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 %}