Support custom templates generator - differents frameworks?
jarpz opened this issue · 10 comments
Reason/Context
How we can use custom templates to generate code for any framework?
The idea is, having any kind of libraries generate code for spring/quarkus/micronaut, etc...
Have you planned for that?
Regards
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
@jarpz do you mean https://github.com/asyncapi/generator/?
@jarpz do you mean https://github.com/asyncapi/generator/?
Yes, where did we find your templates, or how we implement our custom templates? I mean for instance in: https://github.com/OpenAPITools/openapi-generator
You can create your custom templates or extends existing ones.
Regards
so AsyncAPI Generator is what you're looking for. It is a tool that allows you to write templates. We have some official templates like this and you can also write custom ones on your own. There is a sample that teaches all generator options. We also write a library that can in addition generate models for different languages, so when you write a template you focus on writing template for main app logic and do not have to care about templating models.
Makes sense?
so AsyncAPI Generator is what you're looking for. It is a tool that allows you to write templates. We have some official templates like this and you can also write custom ones on your own. There is a sample that teaches all generator options. We also write a library that can in addition generate models for different languages, so when you write a template you focus on writing template for main app logic and do not have to care about templating models.
Makes sense?
No, I missunderstand this plugin allow me to use it just with maven. In the case of https://github.com/asyncapi/generator, you need to install npm and nodejs. We are looking for a plugin full java that allows code generation.
Any info about that?
Or if we can use your plugin.. any example? I can find any documentation about how to use it as maven plugin, config options.
Our approach is to generate code from the contract and put it in the target folder, use it at runtime.. we don't git models.
Regards
@jarpz I know people are able to run npm
with maven
but I'm personally not java user so never tried it:
- https://gist.github.com/phillipgreenii/7c954e3c3911e5c32bd0
- https://auth0.com/blog/integrating-node-dot-js-build-tools-with-maven/
- https://github.com/eirslett/frontend-maven-plugin
have a look at those articles, once you get it running it would be super cool if you could contribute an instruction. Better to integrate npm with maven then write completely separate code generator
@jarpz did you give it a try?
Yeah, that was my solution, but it is not elegant. As you know this method generated a complete scaffolding for an "empty" application, So When we used to put files in the target. the code is not recognized because generated java sources change the order of the folders (src,main). So, we had to use another plugin to add additional classpath classes.
The solution is like that:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.0</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>run generator</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<arguments>run generate -- -p javaPackage=${package}</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v14.17.0</nodeVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/asyncapi/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
That's why I'm looking for a java-native asyncapi plugin.
Regards
@jarpz I think it is better to have just few lines of XML than writing an alternative generator in Java. Much less work, even if it doesn't look super elegant. Unless you mean That's why I'm looking for a java-native asyncapi plugin.
that it would be cool to have maven plugin just like frontend-maven-plugin
- this would be cool I think. Then please propose a solution here https://github.com/asyncapi/community/issues
As for your current configuration:
<execution>
<id>run generator</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<arguments>run generate -- -p javaPackage=${package}</arguments>
</configuration>
</execution>
Do I get it right that you have a package JSON where you have a generator and the template set as dependencies. Probably to lock versions, right? Then it makes sense
This issue has been automatically marked as stale because it has not had recent activity 😴
It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation.
Thank you for your contributions ❤️