@asyncapi/generator 1.9.13 → 1.9.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CODEOWNERS +3 -0
- package/README.md +9 -216
- package/docs/README.md +12 -9
- package/docs/api.md +122 -100
- package/docs/asyncapi-document.md +87 -0
- package/docs/configuration-file.md +3 -3
- package/docs/file-templates.md +1 -1
- package/docs/hooks.md +1 -1
- package/docs/index.md +48 -1
- package/docs/installation-guide.md +81 -0
- package/docs/jsdoc2md-handlebars/custom-sig-name.hbs +12 -0
- package/docs/jsdoc2md-handlebars/defaultvalue.hbs +1 -0
- package/docs/jsdoc2md-handlebars/header.hbs +12 -0
- package/docs/jsdoc2md-handlebars/link.hbs +25 -0
- package/docs/jsdoc2md-handlebars/main.hbs +8 -0
- package/docs/jsdoc2md-handlebars/params-table.hbs +9 -0
- package/docs/nunjucks-render-engine.md +2 -2
- package/docs/parser.md +92 -2
- package/docs/react-render-engine.md +3 -3
- package/docs/special-file-names.md +1 -1
- package/docs/template-context.md +41 -0
- package/docs/template-development.md +153 -0
- package/docs/template.md +69 -2
- package/docs/typescript-support.md +2 -2
- package/docs/usage.md +151 -0
- package/docs/versioning.md +31 -0
- package/lib/generator.js +2 -2
- package/package.json +4 -4
- package/.releaserc +0 -10
- package/docs/asyncapi-context.md +0 -6
- package/docs/asyncapi-file.md +0 -6
- package/docs/authoring-templates.md +0 -17
package/CODEOWNERS
CHANGED
|
@@ -6,4 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
|
|
8
8
|
|
|
9
|
+
# All .md files
|
|
10
|
+
*.md @Florence-Njeri @pratik2315
|
|
11
|
+
|
|
9
12
|
* @fmvilas @derberg @magicmatatjahu @jonaslagoni @asyncapi-bot-eve
|
package/README.md
CHANGED
|
@@ -12,16 +12,8 @@
|
|
|
12
12
|
- [List of official generator templates](#list-of-official-generator-templates)
|
|
13
13
|
- [Requirements](#requirements)
|
|
14
14
|
- [Using from the command-line interface (CLI)](#using-from-the-command-line-interface-cli)
|
|
15
|
-
* [
|
|
16
|
-
* [Update the CLI](#update-the-cli)
|
|
15
|
+
* [CLI installation](#cli-installation)
|
|
17
16
|
* [CLI usage](#cli-usage)
|
|
18
|
-
* [Global templates installed with yarn or npm](#global-templates-installed-with-yarn-or-npm)
|
|
19
|
-
* [CLI usage examples](#cli-usage-examples)
|
|
20
|
-
* [CLI usage with Docker](#cli-usage-with-docker)
|
|
21
|
-
* [CLI usage with npx instead of npm](#cli-usage-with-npx-instead-of-npm)
|
|
22
|
-
- [Using as a module/package](#using-as-a-modulepackage)
|
|
23
|
-
* [Install the module](#install-the-module)
|
|
24
|
-
* [Example using the module](#example-using-the-module)
|
|
25
17
|
- [Generator version vs Template version](#generator-version-vs-template-version)
|
|
26
18
|
- [How to create a template](#how-to-create-a-template)
|
|
27
19
|
- [Contributing](#contributing)
|
|
@@ -67,221 +59,20 @@ You can find above templates and the ones provided by the community in **[this l
|
|
|
67
59
|
|
|
68
60
|
Install both packages using [official installer](https://nodejs.org/en/download/). After installation make sure both packages have proper version by running `node -v` and `npm -v`. To upgrade invalid npm version run `npm install npm@latest -g`
|
|
69
61
|
|
|
70
|
-
>
|
|
62
|
+
> The generator is tested at the moment against Node 14 and NPM 6. Using newer versions is enabled but we don't guarantee they work well. Please provide feedback via issues.
|
|
71
63
|
|
|
72
64
|
## Using from the command-line interface (CLI)
|
|
73
65
|
|
|
74
|
-
###
|
|
75
|
-
|
|
76
|
-
To use it as CLI, install generator globally:
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
npm install -g @asyncapi/generator
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Update the CLI
|
|
83
|
-
|
|
84
|
-
You might want to update your local installation of generator for different reasons:
|
|
85
|
-
|
|
86
|
-
* You want the latest generator to have its latest features. Perform usual installation and in case you had generator installed already, it will upgrade to latest available:
|
|
87
|
-
```bash
|
|
88
|
-
npm install -g @asyncapi/generator
|
|
89
|
-
```
|
|
90
|
-
* You want a specific version of the generator because your template might not be compatible with the latest generator. Check [what version you need](https://github.com/asyncapi/generator/releases) and perform installation, specifying the exact version with the `@` character:
|
|
91
|
-
```bash
|
|
92
|
-
npm install -g @asyncapi/generator@0.50.0
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
> Sometimes you have to force additional npm installation like this: `npm install -g --force @asyncapi/generator`
|
|
96
|
-
|
|
97
|
-
### CLI usage
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
Usage: ag [options] <asyncapi> <template>
|
|
101
|
-
|
|
102
|
-
- <asyncapi>: Local path or URL pointing to AsyncAPI specification file
|
|
103
|
-
- <template>: Name of the generator template like for example @asyncapi/html-template or https://github.com/asyncapi/html-template
|
|
104
|
-
|
|
105
|
-
Options:
|
|
106
|
-
-V, --version output the version number
|
|
107
|
-
-d, --disable-hook [hooks...] disable a specific hook type or hooks from given hook type
|
|
108
|
-
--debug enable more specific errors in the console
|
|
109
|
-
-i, --install installs the template and its dependencies (defaults to false)
|
|
110
|
-
-n, --no-overwrite <glob> glob or path of the file(s) to skip when regenerating
|
|
111
|
-
-o, --output <outputDir> directory where to put the generated files (defaults to current directory)
|
|
112
|
-
-p, --param <name=value> additional param to pass to templates
|
|
113
|
-
--force-write force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir (defaults to false)
|
|
114
|
-
--watch-template watches the template directory and the AsyncAPI document, and re-generate the files when changes occur. Ignores the output directory. This flag should be used only for template development.
|
|
115
|
-
--map-base-url <url:folder> maps all schema references from base url to local folder
|
|
116
|
-
-h, --help display help for command
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
<details>
|
|
120
|
-
<summary>Click here to read more about supported values for the <code><template></code> parameter.</summary>
|
|
121
|
-
<br>
|
|
122
|
-
Templates are installable npm packages. Therefore, the value of <code><template></code> can be anything supported by <code>npm install</code>. Here's a summary of the possibilities:
|
|
123
|
-
<br><br>
|
|
124
|
-
<pre><code>
|
|
125
|
-
npm install [<@scope>/]<name>
|
|
126
|
-
npm install [<@scope>/]<name>@<tag>
|
|
127
|
-
npm install [<@scope>/]<name>@<version>
|
|
128
|
-
npm install [<@scope>/]<name>@<version range>
|
|
129
|
-
npm install <git-host>:<git-user>/<repo-name>
|
|
130
|
-
npm install <git repo url>
|
|
131
|
-
npm install <tarball file>
|
|
132
|
-
npm install <tarball url>
|
|
133
|
-
npm install <folder></code></pre>
|
|
134
|
-
</details>
|
|
135
|
-
<br>
|
|
66
|
+
### CLI installation
|
|
67
|
+
Learn to install the AsyncAPI CLI from the [installation guide](docs/installation-guide.md).
|
|
136
68
|
|
|
137
|
-
###
|
|
69
|
+
### CLI usage
|
|
138
70
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
npm install -g @asyncapi/html-template@0.16.0
|
|
143
|
-
ag asyncapi.yaml @asyncapi/html-template
|
|
144
|
-
# The generator uses template in version 0.16.0 and not latest
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### CLI usage examples
|
|
148
|
-
|
|
149
|
-
**The shortest possible syntax:**
|
|
150
|
-
```bash
|
|
151
|
-
ag asyncapi.yaml @asyncapi/html-template
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
**Generating from a URL:**
|
|
155
|
-
```bash
|
|
156
|
-
ag https://bit.ly/asyncapi @asyncapi/html-template
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
**Specify where to put the result:**
|
|
160
|
-
```bash
|
|
161
|
-
ag asyncapi.yaml @asyncapi/html-template -o ./docs
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
**Passing parameters to templates:**
|
|
165
|
-
```bash
|
|
166
|
-
ag asyncapi.yaml @asyncapi/html-template -o ./docs -p title='Hello from param'
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
In the template you can use it like this: ` {{ params.title }}`
|
|
170
|
-
|
|
171
|
-
**Disabling the hooks:**
|
|
172
|
-
```bash
|
|
173
|
-
ag asyncapi.yaml @asyncapi/html-template -o ./docs -d generate:before generate:after=foo,bar
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
The generator skips all hooks of the `generate:before` type and `foo`, `bar` hooks of the `generate:after` type.
|
|
177
|
-
|
|
178
|
-
**Installing the template from a folder:**
|
|
179
|
-
```bash
|
|
180
|
-
ag asyncapi.yaml ~/my-template
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
It creates a symbolic link to the target directory (`~/my-template` in this case).
|
|
184
|
-
|
|
185
|
-
**Installing the template from a git URL:**
|
|
186
|
-
```bash
|
|
187
|
-
ag asyncapi.yaml https://github.com/asyncapi/html-template.git
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
**Map schema references from baseUrl to local folder:**
|
|
191
|
-
```bash
|
|
192
|
-
ag test/docs/apiwithref.json @asyncapi/html-template -o ./build/ --force-write --map-base-url https://schema.example.com/crm/:./test/docs/
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
The parameter `--map-base-url` maps external schema references to local folders.
|
|
196
|
-
|
|
197
|
-
### CLI usage with Docker
|
|
198
|
-
|
|
199
|
-
Install [Docker](https://docs.docker.com/get-docker/) first. Thanks to Docker you do not need Node.js even though the generator is written with it.
|
|
200
|
-
|
|
201
|
-
```bash
|
|
202
|
-
docker run --rm -it \
|
|
203
|
-
-v [ASYNCAPI SPEC FILE LOCATION]:/app/asyncapi.yml \
|
|
204
|
-
-v [GENERATED FILES LOCATION]:/app/output \
|
|
205
|
-
asyncapi/generator [COMMAND HERE]
|
|
206
|
-
|
|
207
|
-
# Example that you can run inside generator directory after cloning this repository. First you specify mount in location of your AsyncAPI specification file and then you mount in directory where generation result should be saved.
|
|
208
|
-
docker run --rm -it \
|
|
209
|
-
-v ${PWD}/test/docs/dummy.yml:/app/asyncapi.yml \
|
|
210
|
-
-v ${PWD}/output:/app/output \
|
|
211
|
-
asyncapi/generator -o /app/output /app/asyncapi.yml @asyncapi/html-template --force-write
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
### CLI usage with npx instead of npm
|
|
215
|
-
|
|
216
|
-
The [npx](https://www.npmjs.com/package/npx) is very useful when you want to run Generator in CI/CD environment. In such a scenario, you do not want to install generator globally and most environments that provide Node.js and npm, also provide npx out of the box.
|
|
217
|
-
|
|
218
|
-
```bash
|
|
219
|
-
npx -p @asyncapi/generator ag ./asyncapi.yaml @asyncapi/html-template
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Using as a module/package
|
|
223
|
-
|
|
224
|
-
### Install the module
|
|
225
|
-
|
|
226
|
-
```bash
|
|
227
|
-
npm install @asyncapi/generator --save
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### Example using the module
|
|
231
|
-
|
|
232
|
-
Below you can find an example of HTML generation using official `@asyncapi/html-template` template and fetching the spec document from server like `https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0/examples/2.0.0/streetlights.yml` :
|
|
233
|
-
|
|
234
|
-
```js
|
|
235
|
-
const path = require('path');
|
|
236
|
-
const generator = new Generator('@asyncapi/html-template', path.resolve(__dirname, 'example'));
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
await generator.generateFromURL('https://raw.githubusercontent.com/asyncapi/asyncapi/2.0.0/examples/2.0.0/streetlights.yml');
|
|
240
|
-
console.log('Done!');
|
|
241
|
-
} catch (e) {
|
|
242
|
-
console.error(e);
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
See [API documentation](docs/api.md) for more example and full API reference information.
|
|
71
|
+
Learn more about different ways of using the CLI from the [usage document](docs/usage.md).
|
|
247
72
|
|
|
248
73
|
## Generator version vs Template version
|
|
249
74
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
In other words, a template depends on the Generator and its features. For example, it might work with the latest version of the Generator but not the previous ones.
|
|
253
|
-
|
|
254
|
-
The owner of the template specifies in the configuration what version of the Generator it is compatible with:
|
|
255
|
-
```bash
|
|
256
|
-
"generator": ">=0.50.0 <2.0.0",
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
The Generator doesn't work in case the template is not compatible:
|
|
260
|
-
```bash
|
|
261
|
-
Something went wrong:
|
|
262
|
-
Error: This template is not compatible with the current version of the generator (0.50.0). This template is compatible with the following version range: >=0.60.0 <2.0.0.
|
|
263
|
-
at Generator.validateTemplateConfig (/Users/wookiee/.nvm/versions/node/v12.16.1/lib/node_modules/@asyncapi/generator/lib/generator.js:678:13)
|
|
264
|
-
at Generator.loadTemplateConfig (/Users/wookiee/.nvm/versions/node/v12.16.1/lib/node_modules/@asyncapi/generator/lib/generator.js:663:16)
|
|
265
|
-
at Generator.generate (/Users/wookiee/.nvm/versions/node/v12.16.1/lib/node_modules/@asyncapi/generator/lib/generator.js:146:18)
|
|
266
|
-
at processTicksAndRejections (internal/process/task_queues.js:97:5)
|
|
267
|
-
at async /Users/wookiee/.nvm/versions/node/v12.16.1/lib/node_modules/@asyncapi/generator/cli.js:135:7
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
In case you use Generator CLI and a specific template on production, it is safer to lock to a specific version of the template and the Generator.
|
|
271
|
-
|
|
272
|
-
Instead of generating HTML with latest `html-template` and the generator CLI:
|
|
273
|
-
```bash
|
|
274
|
-
npm install -g @asyncapi/generator
|
|
275
|
-
ag asyncapi.yaml @asyncapi/html-template -o ./docs
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
Generate HTML with the version of the `html-template` and the Generator CLI that you are happy with:
|
|
279
|
-
```bash
|
|
280
|
-
npm install -g @asyncapi/generator@0.50.0
|
|
281
|
-
ag asyncapi.yaml @asyncapi/html-template@0.7.0 -o ./docs
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
Before using newer versions of the template, always look at the [changelog](https://github.com/asyncapi/html-template/releases) first. Generator features are not important for you, just make sure to use a version compatible with the template.
|
|
75
|
+
Learn more about versioning from the [versioning document](docs/versioning.md).
|
|
285
76
|
|
|
286
77
|
## How to create a template
|
|
287
78
|
|
|
@@ -318,6 +109,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
318
109
|
</tr>
|
|
319
110
|
<tr>
|
|
320
111
|
<td align="center"><a href="https://github.com/lkmandy"><img src="https://avatars.githubusercontent.com/u/17765231?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Amanda Shafack </b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=lkmandy" title="Documentation">📖</a></td>
|
|
112
|
+
<td align="center"><a href="https://github.com/Florence-Njeri"><img src="https://avatars.githubusercontent.com/u/40742916?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Florence Njeri</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=Florence-Njeri" title="Documentation">📖</a> <a href="https://github.com/asyncapi/generator/pulls?q=is%3Apr+reviewed-by%3AFlorence-Njeri" title="Reviewed Pull Requests">👀</a> <a href="#infra-Florence-Njeri" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-Florence-Njeri" title="Maintenance">🚧</a></td>
|
|
113
|
+
<td align="center"><a href="https://unruffled-goodall-dd424e.netlify.app/"><img src="https://avatars.githubusercontent.com/u/77961530?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pratik Haldankar</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=pratik2315" title="Documentation">📖</a> <a href="https://github.com/asyncapi/generator/pulls?q=is%3Apr+reviewed-by%3Apratik2315" title="Reviewed Pull Requests">👀</a> <a href="#maintenance-pratik2315" title="Maintenance">🚧</a> <a href="#talk-pratik2315" title="Talks">📢</a></td>
|
|
321
114
|
</tr>
|
|
322
115
|
</table>
|
|
323
116
|
|
package/docs/README.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
Table of Contents
|
|
2
2
|
|
|
3
3
|
- [Introduction](index.md)
|
|
4
|
-
- [
|
|
5
|
-
- [
|
|
6
|
-
- [
|
|
7
|
-
- [
|
|
8
|
-
- [React Render Engine](react-render-engine.md)
|
|
9
|
-
- [Nunjucks Render Engine](nunjucks-render-engine.md)
|
|
10
|
-
- [AsyncAPI Context](asyncapi-context.md)
|
|
4
|
+
- [Installation Guide](installation-guide.md)
|
|
5
|
+
- [Usage](usage.md)
|
|
6
|
+
- [AsyncAPI document](asyncapi-document.md)
|
|
7
|
+
- [Template](template.md)
|
|
11
8
|
- [Parser](parser.md)
|
|
9
|
+
- [Generator version vs template version](versioning.md)
|
|
10
|
+
- [Template Development](template-development.md)
|
|
11
|
+
- [Configuration File](configuration-file.md)
|
|
12
|
+
- [Template context](template-context.md)
|
|
13
|
+
- [React render engine](react-render-engine.md)
|
|
14
|
+
- [Nunjucks render engine](nunjucks-render-engine.md)
|
|
12
15
|
- [Hooks](hooks.md)
|
|
13
|
-
- [File
|
|
14
|
-
- [TypeScript
|
|
16
|
+
- [File templates](file-templates.md)
|
|
17
|
+
- [TypeScript support](typescript-support.md)
|
|
15
18
|
- [Special file names](special-file-names.md)
|