Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from asyncapi:master #4

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
254b072
refactor: use optional chaining in template params validation (#1299)
thebedigupta Oct 14, 2024
298479a
refactor: simplify variable initialization in tests (#1297)
thebedigupta Oct 14, 2024
25c4e53
refactor: better readability of `buildLineCore` filter (#1301)
thebedigupta Oct 15, 2024
cb375c4
refactor: simplify `isAsyncFunction` function with optional chaining …
thebedigupta Oct 21, 2024
aa79245
refactor: simplify `generateFile` function with optional chaining exp…
D-I-R-M Oct 21, 2024
261b66e
docs: update relative links to api docs (#1303)
emmanuel-ferdman Oct 28, 2024
2d16234
feat: add hooks library to generator (#1304)
derberg Oct 30, 2024
294479d
chore(release): release and bump versions of packages (#1313)
asyncapi-bot Oct 30, 2024
d92f6ed
chore: update assets (#1314)
asyncapi-bot Oct 30, 2024
bd956b0
chore(deps): bump jsonpath-plus and @asyncapi/parser in /apps/generat…
dependabot[bot] Oct 30, 2024
3ccfd1f
ci: update update-maintainers-trigger.yaml workflow from global .gith…
asyncapi-bot Nov 12, 2024
f3ca037
chore(deps): bump jsonpath-plus and @asyncapi/parser in /apps/generat…
dependabot[bot] Nov 12, 2024
8bc3a78
chore(deps): bump jsonpath-plus and @stoplight/spectral-core in /apps…
dependabot[bot] Nov 12, 2024
8941d0b
chore: add `components` and `helpers` packages and show example temp…
derberg Dec 25, 2024
59504bc
chore(deps): bump jsonpath-plus and @stoplight/spectral-core in /apps…
dependabot[bot] Dec 25, 2024
7fe7bbb
docs: jsdoc return statement update (#1330)
DhairyaMajmudar Jan 14, 2025
fd5dfd7
feat: set `ag` cli and `nunjucks` as deprecated (#1331)
derberg Jan 23, 2025
02bb852
chore(release): release and bump versions of packages (#1332)
asyncapi-bot Jan 23, 2025
f19960d
docs: add Gmin2 and lmgyuan as a contributor for bug, code, and 4 mor…
allcontributors[bot] Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@
"avatar_url": "https://avatars.githubusercontent.com/u/16447041?v=4",
"profile": "https://github.com/lmgyuan",
"contributions": [
"doc"
"doc",
"bug",
"code",
"ideas",
"review",
"test"
]
},
{
Expand All @@ -205,6 +210,20 @@
"contributions": [
"bug"
]
},
{
"login": "Gmin2",
"name": "Mintu Gogoi",
"avatar_url": "https://avatars.githubusercontent.com/u/127925465?v=4",
"profile": "https://github.com/Gmin2",
"contributions": [
"bug",
"code",
"ideas",
"doc",
"review",
"test"
]
}
],
"contributorsPerLine": 3,
Expand Down
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ apps/generator/output/*
.github/templates-list-validator/dist/*
apps/generator/test/temp/*
apps/generator/test/test-templates/react-template/__transpiled/*

packages/components/lib/*
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ rules:
react/react-in-jsx-scope: off
react/display-name: off
react/prop-types: off
react/jsx-key: off
react/jsx-key: off
react/no-unescaped-entities: off
28 changes: 28 additions & 0 deletions .github/workflows/update-maintainers-trigger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This action is centrally managed in https://github.com/asyncapi/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo

name: Trigger MAINTAINERS.yaml file update

on:
push:
branches: [ master ]
paths:
# Check all valid CODEOWNERS locations:
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-file-location
- 'CODEOWNERS'
- '.github/CODEOWNERS'
- '.docs/CODEOWNERS'

jobs:
trigger-maintainers-update:
name: Trigger updating MAINTAINERS.yaml because of CODEOWNERS change
runs-on: ubuntu-latest

steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # https://github.com/peter-evans/repository-dispatch/releases/tag/v3.0.0
with:
# The PAT with the 'public_repo' scope is required
token: ${{ secrets.GH_TOKEN }}
repository: ${{ github.repository_owner }}/community
event-type: trigger-maintainers-update
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

**/node_modules/

.DS_Store
# Local env files
.env
.env.local
Expand All @@ -15,3 +15,4 @@ coverage
.turbo

/.idea
temp
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#we need to explicitly exclude them as some are commit to the repo
sonar.exclusions=test/**/*
sonar.exclusions=**/test/**/*,**/*__transpiled/**/*.js,packages/templates/clients/js/websocket/example.js,
2 changes: 1 addition & 1 deletion Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cd apps/generator
3. Run the generator with the react-template:

```bash
asyncapi generate fromTemplate ./test/docs/dummy.yml ./test/test-templates/react-template -o ./test/output --force-write
node ./cli ./test/docs/dummy.yml ./test/test-templates/react-template -o ./test/output --force-write
```

4. Check the output in the `./test/output` directory to verify the output that you desired.
Expand Down
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
[![AsyncAPI Generator](./assets/readme-banner.png)](https://www.asyncapi.com/tools/generator)

> Some parts of the AsyncAPI Generator are deprecated and the plan is to remove them in October 2025. For more details read notes from release [@asyncapi/[email protected]](https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.6.0).

This is a Monorepo managed using [Turborepo](https://turbo.build/) and contains the following package:

1. [Generator](apps/generator): This is a tool that you can use to generate whatever you want basing on the AsyncAPI specification file as an input.

2. [Nunjucks-filters](apps/nunjucks-filters): This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies seprately.
1. [Hooks](apps/hooks): This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. Hooks are designed to let template developers hook into the template generation process. For example, one can create a hook code that will be automatically invoked right after the template generation process has ended.

1. [Nunjucks-filters](apps/nunjucks-filters): This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies separately.

![npm](https://img.shields.io/npm/v/@asyncapi/generator?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/generator?style=for-the-badge)
> [!IMPORTANT]
> **Deprecation Notice:** The Nunjucks renderer engine is deprecated and will be removed in future releases. We strongly recommend using the React renderer engine instead. You can find how to migrate from Nunjucks to React in the [migration guide](apps/generator/docs/nunjucks-depreciate.md)

> warning: This package doesn't support AsyncAPI 1.x anymore. We recommend to upgrade to the latest AsyncAPI version using the [AsyncAPI converter](https://github.com/asyncapi/converter-js) (You can refer to [installation guide](/apps/generator//docs//installation-guide.md)). If you need to convert documents on the fly, you may use the [Node.js](https://github.com/asyncapi/converter-js) or [Go](https://github.com/asyncapi/converter-go) converters.
![npm](https://img.shields.io/npm/v/@asyncapi/generator?style=for-the-badge) ![npm](https://img.shields.io/npm/dt/@asyncapi/generator?style=for-the-badge)

<!-- toc is generated with GitHub Actions do not remove toc markers -->

<!-- toc -->

- [Overview](#overview)
- [List of official generator templates](#list-of-official-generator-templates)
- [Filters](#filters)
- [Hooks](#hooks)
- [Contributing](#contributing)
- [Contributors ✨](#contributors-%E2%9C%A8)

Expand Down Expand Up @@ -53,18 +59,24 @@ There is a large number of templates that are ready to use and are officially su

You can find above templates and the ones provided by the community in **[this list](https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate)**

# Generator Filters
## Filters

This library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies seprately.
`apps/nunjucks-filters` library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. These filters are designed specifically for Nunjucks templates and are included by default with the generator, so there's no need to add them to dependencies separately.

This library consists of:

- Custom filters. Check out [API docs](apps/nunjucks-filters/docs/api.md) for complete list
- Lodash-powered filters. For the list of all available filters check [official docs](https://lodash.com/docs/)

## Hooks

The `apps/hooks` library contains generator filters that can be reused across multiple templates, helping to avoid redundant work. [Hooks](https://www.asyncapi.com/docs/tools/generator/hooks) are functions called by the generator at specific moments in the generation process. Hooks can be anonymous functions, but you can also assign them function names. These hooks can have arguments provided to them, or they may be expected to return a value.

These hooks are included in the generator without adding any specific dependency to the library. You still have to enable the given hook in the configuration explicitly because some hooks can execute automatically without passing a specific parameter. [Learn more about configuration and what hooks are available out of the box](https://www.asyncapi.com/docs/tools/generator/hooks#official-library).

## Contributing

For developement setup you can follow the detailed guide in [Developement guide](Development.md)
For the development setup, you can follow the detailed guide in [Developement guide](Development.md)

Read [CONTRIBUTING](CONTRIBUTING.md) guide.

Expand Down Expand Up @@ -100,11 +112,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<tr>
<td align="center" valign="top" width="33.33%"><a href="https://github.com/swastiksuvam55"><img src="https://avatars.githubusercontent.com/u/90003260?v=4?s=100" width="100px;" alt="swastik suvam singh"/><br /><sub><b>swastik suvam singh</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=swastiksuvam55" title="Code">💻</a></td>
<td align="center" valign="top" width="33.33%"><a href="https://blog.orzzh.icu/"><img src="https://avatars.githubusercontent.com/u/33168669?v=4?s=100" width="100px;" alt="GavinZhengOI"/><br /><sub><b>GavinZhengOI</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=GavinZhengOI" title="Documentation">📖</a></td>
<td align="center" valign="top" width="33.33%"><a href="https://github.com/lmgyuan"><img src="https://avatars.githubusercontent.com/u/16447041?v=4?s=100" width="100px;" alt="lmgyuan"/><br /><sub><b>lmgyuan</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=lmgyuan" title="Documentation">📖</a></td>
<td align="center" valign="top" width="33.33%"><a href="https://github.com/lmgyuan"><img src="https://avatars.githubusercontent.com/u/16447041?v=4?s=100" width="100px;" alt="lmgyuan"/><br /><sub><b>lmgyuan</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=lmgyuan" title="Documentation">📖</a> <a href="https://github.com/asyncapi/generator/issues?q=author%3Almgyuan" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/generator/commits?author=lmgyuan" title="Code">💻</a> <a href="#ideas-lmgyuan" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/asyncapi/generator/pulls?q=is%3Apr+reviewed-by%3Almgyuan" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/generator/commits?author=lmgyuan" title="Tests">⚠️</a></td>
</tr>
<tr>
<td align="center" valign="top" width="33.33%"><a href="https://github.com/pierrick-boule"><img src="https://avatars.githubusercontent.com/u/3237116?v=4?s=100" width="100px;" alt="pierrick-boule"/><br /><sub><b>pierrick-boule</b></sub></a><br /><a href="https://github.com/asyncapi/generator/commits?author=pierrick-boule" title="Code">💻</a> <a href="https://github.com/asyncapi/generator/commits?author=pierrick-boule" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/generator/commits?author=pierrick-boule" title="Documentation">📖</a></td>
<td align="center" valign="top" width="33.33%"><a href="https://dhaiyra-majmudar.netlify.app/"><img src="https://avatars.githubusercontent.com/u/124715224?v=4?s=100" width="100px;" alt="Dhairya Majmudar"/><br /><sub><b>Dhairya Majmudar</b></sub></a><br /><a href="https://github.com/asyncapi/generator/issues?q=author%3ADhairyaMajmudar" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="33.33%"><a href="https://github.com/Gmin2"><img src="https://avatars.githubusercontent.com/u/127925465?v=4?s=100" width="100px;" alt="Mintu Gogoi"/><br /><sub><b>Mintu Gogoi</b></sub></a><br /><a href="https://github.com/asyncapi/generator/issues?q=author%3AGmin2" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/generator/commits?author=Gmin2" title="Code">💻</a> <a href="#ideas-Gmin2" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/asyncapi/generator/commits?author=Gmin2" title="Documentation">📖</a> <a href="https://github.com/asyncapi/generator/pulls?q=is%3Apr+reviewed-by%3AGmin2" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/generator/commits?author=Gmin2" title="Tests">⚠️</a></td>
</tr>
</tbody>
</table>
Expand Down
1 change: 1 addition & 0 deletions apps/generator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ test/temp/reactTemplate
test/test-project/package-lock.json
test/test-project/verdaccio/storage/
test/test-project/storage/
__transpiled
18 changes: 18 additions & 0 deletions apps/generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @asyncapi/generator

## 2.6.0

### Minor Changes

- fd5dfd7: - **Deprecation of `ag` CLI**: The `ag` CLI is deprecated in favour of the `AsyncAPI CLI` that is a single entry point for all the AsyncAPI tools. No new features will be added to `ag` and it will be completely removed. The official documentation of AsyncAPI Generator has not mentioned `ag` for over a year, instead only using `AsyncAPI CLI` and `asyncapi generate fromTemplate` commands. Refer to the [migration guide](https://www.asyncapi.com/docs/tools/generator/migration-cli) that will help you understand how to migrate your `ag` commands to the new `AsyncAPI CLI` command.

- **Deprecation of Nunjucks render engine:** The [Nunjucks render engine](https://www.asyncapi.com/docs/tools/generator/nunjucks-render-engine) is deprecated and will be removed in October 2025. It is recommended to switch to the [React render engine](https://www.asyncapi.com/docs/tools/generator/react-render-engine) instead. If you are using Nunjucks in production, read the [migration guide](https://www.asyncapi.com/docs/tools/generator/migration-nunjucks-react) that will help you understand how to migrate to the new engine. The removal of the Nunjucks render engine results also in removal of [Nunjucks-filters](apps/nunjucks-filters) library.

Removal of both deprecated parts of the generator is planned for October 2025, which gives you 9 months to migrate.

## 2.5.0

### Minor Changes

- 2d16234: - Package `@asyncapi/generator-hooks` is now part of `generator` repo and won't be released separately. Theource code is stored under `apps/hooks` but the `package/library` name stays as it was originally for backward compatibility,
- By default, the `@asyncapi/generator-hooks` package, known as **package** contains many different hooks used in templates and is available in the generator. You no longer have to configure it in your `package.json` in `dependencies`. The package, `@asyncapi/generator-hooks` will no longer be published to NPM separately and is deprecated. You can still have your own hooks, store them in a separate package, and configure them with your template.
- Remember that the fact that the hooks package is now included by default, doesn't mean all hooks from it are enabled by default. You still have to enable a given hook in the configuration file explicitly because some hooks can execute automatically without passing a specific parameter. Also, a hook's supported parameters need to be defined in your template's config.

## 2.4.1

### Patch Changes
Expand Down
7 changes: 7 additions & 0 deletions apps/generator/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ program
.option('-o, --output <outputDir>', 'directory where to put the generated files (defaults to current directory)', parseOutput, process.cwd())
.option('-p, --param <name=value>', 'additional param to pass to templates', paramParser)
.option('--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)')
.option('--disable-warning', 'disable "ag" deprecation warning (defaults to false)')
.option('--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.')
.option('--map-base-url <url:folder>','maps all schema references from base url to local folder',mapBaseUrlParser)
.parse(process.argv);

if (!program.disableWarning) {
console.warn(yellow(
'Warning: The "ag" CLI is deprecated and will be removed in a future release. Please use the AsyncAPI CLI instead. See release notes for details: https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.6.0. You can hide this working using --disable-warning flag.')
);
}

if (!asyncapiDocPath) {
console.error(red('> Path or URL to AsyncAPI file not provided.'));
program.help(); // This exits the process
Expand Down
15 changes: 12 additions & 3 deletions apps/generator/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Reference API documentation for AsyncAPI Generator library.
* [Generator](#Generator)
* [new Generator(templateName, targetDir, options)](#new_Generator_new)
* _instance_
* [.compile](#Generator+compile) : `Boolean`
* [.registry](#Generator+registry) : `Object`
* [.templateName](#Generator+templateName) : `String`
* [.targetDir](#Generator+targetDir) : `String`
Expand All @@ -38,9 +39,9 @@ Reference API documentation for AsyncAPI Generator library.
* [.executeAfterHook()](#Generator+executeAfterHook) ⇒ `Promise.<void>`
* [.parseInput()](#Generator+parseInput)
* [.configureTemplate()](#Generator+configureTemplate)
* ~~[.generateFromString(asyncapiString, [parseOptions])](#Generator+generateFromString) ⇒ `Promise`~~
* [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒ `Promise`
* [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒ `Promise`
* ~~[.generateFromString(asyncapiString, [parseOptions])](#Generator+generateFromString) ⇒ `Promise.<(TemplateRenderResult|undefined)>`~~
* [.generateFromURL(asyncapiURL)](#Generator+generateFromURL) ⇒ `Promise.<(TemplateRenderResult|undefined)>`
* [.generateFromFile(asyncapiFile)](#Generator+generateFromFile) ⇒ `Promise.<(TemplateRenderResult|undefined)>`
* [.installTemplate([force])](#Generator+installTemplate)
* _static_
* [.getTemplateFile(templateName, filePath, [templatesDir])](#Generator.getTemplateFile) ⇒ `Promise`
Expand All @@ -64,6 +65,7 @@ Instantiates a new Generator object.
- [.forceWrite] `Boolean` ` = false` - Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty dir. Default is set to false.
- [.install] `Boolean` ` = false` - Install the template and its dependencies, even when the template has already been installed.
- [.debug] `Boolean` ` = false` - Enable more specific errors in the console. At the moment it only shows specific errors about filters. Keep in mind that as a result errors about template are less descriptive.
- [.compile] `Boolean` ` = true` - Whether to compile the template or use the cached transpiled version provided by template in '__transpiled' folder
- [.mapBaseUrlToFolder] `Object.<String, String>` - Optional parameter to map schema references from a base url to a local base folder e.g. url=https://schema.example.com/crm/ folder=./test/docs/ .
- [.registry] `Object` - Optional parameter with private registry configuration
- [.url] `String` - Parameter to pass npm registry url
Expand All @@ -85,6 +87,13 @@ const generator = new Generator('@asyncapi/html-template', path.resolve(__dirnam
});
```

<a name="Generator+compile"></a>

* generator.compile : `Boolean`** :
Whether to compile the template or use the cached transpiled version provided by template in '__transpiled' folder.

**Kind**: instance property of [`Generator`](#Generator)

<a name="Generator+registry"></a>

* generator.registry : `Object`** :
Expand Down
Loading
Loading