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

feat: support files listed in nonRenderableFiles with conditionalFiles #363

Merged
merged 7 commits into from
May 29, 2020
Merged

feat: support files listed in nonRenderableFiles with conditionalFiles #363

merged 7 commits into from
May 29, 2020

Conversation

derberg
Copy link
Member

@derberg derberg commented May 27, 2020

Description

  • nonRenderableFiles are also supported by conditionalFiles.
  • extend some details in authoring.md

Related issue(s)
Resolves #358

@derberg
Copy link
Member Author

derberg commented May 28, 2020

@fmvilas

I added support for nonrenderablefiles as agreed in the related issue

I tested against:

"nonRenderableFiles": [
      "src/api/middlewares/*.*",
      "src/lib/config.js"
    ],
    "conditionalFiles": {
      "src/lib/config.js": {
        "subject": "server.protocol",
        "validation": {
          "const": "amqp"
        }
      }
    }

and works as expected, src/lib/config.js is not getting through

ready for review

@derberg derberg changed the title docs: clarify how to use conditionalFiles feature feat: support files listed in nonRenderableFiles with conditionalFiles May 28, 2020
@Tenischev
Copy link
Member

@derberg i do not agree that this will resolve #358
First of all, example of "subject": "server.protocol", is not sufficient since there is no hint that every time when you wish to generate template, in the fact, you must specify server paramter otherwise conditionalFiles will no work.

@derberg
Copy link
Member Author

derberg commented May 28, 2020

@Tenischev it is not yet merged, so for sure it doesn't resolve yet. But the goal is that it does 😉

First of all, example of "subject": "server.protocol", is not sufficient since there is no hint that every time when you wish to generate template, in the fact, you must specify server paramter otherwise conditionalFiles will no work.

  • there are 2 examples now
  • descriptions of server param is enriched

Do you like it 😄
If not I need some hints on how to make you happy 😄

@Tenischev
Copy link
Member

I ❤️ new server parameter description 👏 😄

But there still issue about these

if subject is not resolved in AsyncAPI, then file will be rendered because of this condition

@derberg
Copy link
Member Author

derberg commented May 28, 2020

@Tenischev oh, I know what you mean, that actually sucks, you are right, in this new example I added about info.contact, if entire contact is not provided, support.html doc will be created

so I made a fix but to fix it nice there would have to be a nice log message. But we have too many of those already, so I added another use case to our new debug flag.

example of log messages for different cases, where there is debug on or off

$ ./cli.js ../nodejs-template/asyncapi.yml ../nodejs-template -o output --force-write -p server=dummy-mqtt --debug
docs/support.html was not generated because info.contact specified in template configuration in conditionalFiles was not found in provided AsyncAPI specification file

Done! ✨
Check out your shiny new generated files at /Users/wookiee/Documents/sources/generator/output.

$ ./cli.js ../nodejs-template/asyncapi.yml ../nodejs-template -o output --force-write -p server=dummy-mqtt --debug

docs/support.html was not generated because condition specified for this file in template configuration in conditionalFiles matched

Done! ✨
Check out your shiny new generated files at /Users/wookiee/Documents/sources/generator/output.

$ ./cli.js ../nodejs-template/asyncapi.yml ../nodejs-template -o output --force-write -p server=dummy-mqtt


Done! ✨
Check out your shiny new generated files at /Users/wookiee/Documents/sources/generator/output.

fmvilas
fmvilas previously approved these changes May 28, 2020
@@ -211,17 +211,17 @@ The `generator` property from `package.json` file must contain a JSON object tha
}
},
"conditionalFiles": {
"src/api/adapters/amqp.js": {
"template/dir/relative/path/to/file/test-amqp.js": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without template in the beginning, because of

const relativeSourceFile = path.relative(this.templateContentDir, sourceFile);

"validation": {
"const": "mqtt"
}
"template/dir/relative/path/to/file/support.html": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without template in the beginning, because of

const relativeSourceFile = path.relative(this.templateContentDir, sourceFile);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I think I made it a bit too confusing, I meant here in example that path must be relative to template dir. I'll fix

@@ -158,6 +159,8 @@ class Generator {
throw new Error('Parameter entrypoint is required when using output = "string"');
}

if (this.debug) log.setLevel('debug');
Copy link
Member

@Tenischev Tenischev May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! Could we pass debug flag into template? So in template we also could write some debug logs. (Ofc this suggestion is for separate issue)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you for sure have access to it in hooks out of the box, but filters and Nunjucks, that would be awesome, please write an issue for it

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@derberg
Copy link
Member Author

derberg commented May 29, 2020

@Tenischev how about 1c0dccd

Copy link
Member

@Tenischev Tenischev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good fix! Thanks!

@derberg derberg merged commit c5b8f7e into asyncapi:master May 29, 2020
@derberg derberg deleted the docs-clarify-conditionalFiles branch May 29, 2020 08:12
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.52.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

conditionalFiles only works if you are lucky
4 participants