openapi3-generator icon indicating copy to clipboard operation
openapi3-generator copied to clipboard

Support for any template engine

Open pitpit opened this issue 5 years ago • 4 comments

This is a PR I wrote because I need to reuse a template that I already made on nunjucks

It decouples templating and generator in a clean way using jstransformer.

I think it could be useful for other people. I'll publish my template based on nunjucks in another PR

  • [X] use jstransformer to render template
  • [X] handle specific handlebars partials and helpers with an in-directory config system (.bootstrap.js)
  • [X] customizable target file renaming to work with any template engine (myFile.md.hbs -> myFile.md)
  • [X] customizable files ignore list to work with any template engine
  • [ ] documentation about how to install another template engine in README.md

pitpit avatar Jun 20 '19 10:06 pitpit

I think this is an interesting concept to explore. I'm currently working more on the https://github.com/asyncapi/generator package (similar to this one but for AsyncAPI) and this is interesting. How difficult do you think it would be to migrate and test the whole library to support multiple template engines?

fmvilas avatar Jul 01 '19 09:07 fmvilas

Hi @fmvilas I test it with jstransformer-nunjucks using this PR as a base and it actually works well now. Do you want me to push another PR as an example in order you to try it ?

How difficult do you think it would be to migrate and test the whole library to support multiple template engines?

What do you mean by "test the whole library" ? Unit testing ?

pitpit avatar Jul 08 '19 10:07 pitpit

A PR with an example would be appreciated, thanks!

And by testing I mean unit or integration tests. Just curious, not saying it should be done now. Thanks!

fmvilas avatar Jul 08 '19 10:07 fmvilas

@fmvilas here's a draft PR with nunjucks support https://github.com/fmvilas/openapi3-generator/pull/26

About the tests: we could have some tests using the same openapi spec and two different templating engine, two templates collections supposed to generate the same markdown and check that the output actually match. Or easier, dumping the openapi specs in json through the two template engines and check that the output in json match the input. That will only check that the engines are well linked and bootstrapped but that's a good beginning

pitpit avatar Jul 08 '19 13:07 pitpit