asyncapi / java-spring-template

Java Spring template for the AsyncAPI Generator
Apache License 2.0
68 stars 55 forks source link

Command line example does not work with option -p #183

Closed riccardoCorrias closed 2 years ago

riccardoCorrias commented 2 years ago

Describe the bug

While using the Command Line example for the Template in order to generate Java code I've found a bug that does not let the generator create the required schemas described in the .yml file.

How to Reproduce

After Installing the required generator with the following command: npm install -g @asyncapi/generator I've tried using the following command as described in the example: ag -o ./bob -p javaPackage=test.testing asyncapi.yml @asyncapi/java-spring-template The result is the creation of the folder bob in the desired location but then the class that should have been generated are not visible and are not generated, in other words the folder bob/src/main/java/test/testing/ is empty and does not contain any desired class. While debugging I've tried removing the -p option and the relative parameter javaPackage, therefore using the following command: ag -o ./bob asyncapi.yml @asyncapi/java-spring-template With these line I've been able to make the generator create all the desired java class in the specified folder, the problem is that I am not able to specify using the option -p the desired Java Package.

Expected behavior

As described above I'd like to have the option to generate java class starting from my .yml specification file in the desired output directory and with the specified javaPackage using the -p option.

github-actions[bot] commented 2 years ago

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.

derberg commented 2 years ago

@riccardoCorrias might be that docs are broken as when I see https://github.com/asyncapi/java-spring-template/blob/master/hooks/99_packageProcessor.js#L13 it actually expects parameter called userJavaPackage and not javaPackage. Can you please check?

riccardoCorrias commented 2 years ago

@riccardoCorrias might be that docs are broken as when I see https://github.com/asyncapi/java-spring-template/blob/master/hooks/99_packageProcessor.js#L13 it actually expects parameter called userJavaPackage and not javaPackage. Can you please check?

Thanks for the suggestion, unfortunately using userJavaPackage instead of javaPackage the template output the following error: Something went wrong: Error: This template doesn't have the following params: userJavaPackage. Did you mean "javaPackage" instead of "userJavaPackage"? at isProvidedParameterSupported (/usr/local/lib/node_modules/@asyncapi/generator/lib/templateConfigValidator.js:92:9) at module.exports.validateTemplateConfig (/usr/local/lib/node_modules/@asyncapi/generator/lib/templateConfigValidator.js:29:3) at Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:185:5)

derberg commented 2 years ago

ah yes, cause it is not only broken docs but also config,

please clone the repo (perform npm install) and change javaPackage to userJavaPackage in package.json or do reverse change in https://github.com/asyncapi/java-spring-template/blob/master/hooks/99_packageProcessor.js#L13 file (I think javaPackage is better name). Then test if this works, you need to run ag from inside cloned repo, and instead of @asyncapi/java-spring-template type just ./

derberg commented 2 years ago

@riccardoCorrias all good, or still need help? would be great if you could open a PR with fix if it worked for you

Tenischev commented 2 years ago

Hi @riccardoCorrias this is a bit strange, I tested -p javaPackage=test.testing with current version and it works fine. Please try to add --force-write to the commend, maybe this helps, e.g. ag -p javaPackage=test.testing -o ${pwd}/out2 ${pwd}/java-spring-template/tests/kafka.yml @asyncapi/java-spring-template --force-write If it's not help, please provide your asyncapi.yml for deeper investigation.

@derberg regarding userJavaPackage, this variable is used to define final package that will be used. Since template support definition of package via info.x-java-package async api extension as well as via javaPackage parameter, before generation we need to figure out what to use. Here this magic happens - https://github.com/asyncapi/java-spring-template/blob/8442bb70b18d656c69f1cf8522ad017a6f927d74/hooks/99_packageProcessor.js#L30-L50

derberg commented 2 years ago

@Tenischev but the problem is that https://github.com/asyncapi/java-spring-template/blob/master/hooks/99_packageProcessor.js#L13 will always be undefined.

Tenischev commented 2 years ago

no, userJavaPackage will be defined, otherwise path by 'com.asyncapi' will not be generated. the code that you mentioned is generate:after which simply will relocate all generated classes to another folder if user set it. definition of userJavaPackage happens in the generate:before that i mentioned above.

i assume that --force-write will help, because as i wrote generate:after simply move all files from 'com.asyncapi' to the folder defined by user (if it is defined) https://github.com/asyncapi/java-spring-template/blob/8442bb70b18d656c69f1cf8522ad017a6f927d74/hooks/99_packageProcessor.js#L10-L28

derberg commented 2 years ago

OMG, I just noticed:

Object.defineProperty(generator.templateParams, 'userJavaPackage', {
            enumerable: true,
            get() {
                return javaPackage;
            }
        });

🤦🏼 sorry, should have read the code closely. You are doing some interesting magic there.

So yeah @riccardoCorrias I second what @Tenischev. The best would be really to see your AsyncAPI document so we can replicate the issue

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

derberg commented 2 years ago

closing as no more details were provided