Coder Social home page Coder Social logo

Comments (12)

MikeRalphson avatar MikeRalphson commented on June 15, 2024 1

v2.1.0 allows you to set a generator property with a render function in the config. See #118 for details.

from openapi-codegen.

iilyak avatar iilyak commented on June 15, 2024 1

Thank you for merging the feature.

from openapi-codegen.

iilyak avatar iilyak commented on June 15, 2024

Actually according to https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.0-rc0 the swagger-api switched to handlebarjs.

from openapi-codegen.

MikeRalphson avatar MikeRalphson commented on June 15, 2024

We use hogan.js here as it was the only js template engine which actually worked with the Swagger-Codegen 2.3 templates we imported.

See https://github.com/wycats/handlebars.js/blob/master/README.markdown#compatibility for a list of reasons why handebarsjs is not currently an option.

Maybe you could write a plugin for prettier or something for your target language?

Alternatively the new custom lambda support might help you refractor your templates.

from openapi-codegen.

iilyak avatar iilyak commented on June 15, 2024

what if we would support both? We could choose the engine based on file extension. If it .mustache we would choose hogan. If it is .hbr we would select handlebars.

from openapi-codegen.

MikeRalphson avatar MikeRalphson commented on June 15, 2024

Can you point me to docs which confirm handlebars supports controlling whitespace?

from openapi-codegen.

iilyak avatar iilyak commented on June 15, 2024

https://handlebarsjs.com/guide/expressions.html#whitespace-control

from openapi-codegen.

iilyak avatar iilyak commented on June 15, 2024

Implementation wise it is quite easy. I patched openapi-codegen in few places and successfully using it in my project.

const Handlebars = require('handlebars');

....
Handlebars.registerHelper(lambda, generator.lambdas[lambda]);
....
Handlebars.registerPartial(p, ff.readFileSync(tpl(config, configName, partial),'utf8'));
...
let template = Handlebars.compile(action.template);
let content = template(model);

from openapi-codegen.

iilyak avatar iilyak commented on June 15, 2024

I can do a PR if you think this feature is useful.

from openapi-codegen.

MikeRalphson avatar MikeRalphson commented on June 15, 2024

Are you in a position to also contribute a config and set of templates and a CI test, I.e. Will we have test coverage for this feature?

from openapi-codegen.

iilyak avatar iilyak commented on June 15, 2024

I see two options here:

  1. create configs/test-hbr.json and templates/test-hbr.hbr
  2. create tests/fixtures/configs/test-hbr.json and tests/fixtures/templates/test-hbr.hbr

The test can check that

  • the simple .hbr template rendered correctly
  • the template in the filename of the target is rendered using engine depending on template file extension

from openapi-codegen.

MikeRalphson avatar MikeRalphson commented on June 15, 2024

I would prefer to only add the complexity of supporting multiple rendering engines if we can demonstrate a real-world set of templates that need the functionality. Happy to hear from anyone else who might need the functionality.

from openapi-codegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.