Skip to content

Commit

Permalink
feat: add version parameter to allow version override (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovic Dussart authored Feb 17, 2021
1 parent d76e99e commit 80600b6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 8 additions & 0 deletions macros/commons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% macro getApiVersion() %}
{% if params.version %}
{% set version = params.version %}
{% else %}
{% set version = asyncapi.info().version() %}
{% endif %}
<span>{{version}}</span>
{% endmacro %}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion partials/introduction.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% from "macros/commons.html" import getApiVersion with context %}

<div class="center-block p-8">
<a name="introduction"></a>
<h1>{{asyncapi.info().title()}} {{asyncapi.info().version()}}</h1>

<h1>{{asyncapi.info().title()}} {{getApiVersion()}}</h1>
<div class="leading-normal mb-4">
{% if asyncapi.info().termsOfService() %}
<a class="border border-solid border-purple-300 hover:bg-purple-300 hover:text-purple-600 font-bold no-underline text-purple-500 text-xs uppercase rounded mr-2 px-3 py-1"
Expand Down
5 changes: 3 additions & 2 deletions partials/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "./sliced-string.html" import slicedString %}
{% from "macros/commons.html" import getApiVersion with context %}

<input id="burger-menu" type="checkbox" />
<label for="burger-menu" class="shadow">
Expand All @@ -15,7 +16,7 @@
<img src="{{ asyncapi.info().ext('x-logo') }}" alt="{{ asyncapi.info().title() }} logo">
{% else %}
<h1 class="text-2xl font-thin">
{{ asyncapi.info().title() }} {{ asyncapi.info().version() }}
{{ asyncapi.info().title() }} {{ getApiVersion() }}
</h1>
{% endif %}
<ul class="text-sm mt-10 mt-2">
Expand Down Expand Up @@ -92,4 +93,4 @@ <h2 class="text-xs uppercase text-gray-500 mt-10 mb-4 font-thin">Messages</h2>
</ul>
{% endif %}
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion template/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<!DOCTYPE html>
{% from "macros/commons.html" import getApiVersion with context %}
<html lang="en">
<head>
<meta charset="UTF-8">
{% if params.baseHref %}
<base href="{{params.baseHref}}">
{% endif %}
<title>{{asyncapi.info().title()}} {{asyncapi.info().version()}} documentation</title>

<title>{{asyncapi.info().title()}} {{getApiVersion()}} documentation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% if params.singleFile %}
<style type="text/css">
Expand Down

0 comments on commit 80600b6

Please sign in to comment.