Comments (12)
v2.1.0
allows you to set a generator
property with a render
function in the config. See #118 for details.
from openapi-codegen.
Thank you for merging the feature.
from openapi-codegen.
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.
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.
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.
Can you point me to docs which confirm handlebars supports controlling whitespace?
from openapi-codegen.
https://handlebarsjs.com/guide/expressions.html#whitespace-control
from openapi-codegen.
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.
I can do a PR if you think this feature is useful.
from openapi-codegen.
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.
I see two options here:
- create configs/test-hbr.json and templates/test-hbr.hbr
- 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.
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)
- Unable to use config file from in current working directory or with explicit extension using CLI HOT 2
- $ref not supported in api (path) params
- nodejs template: kebab-case component schema name creates invalid JavaScript HOT 1
- We can use new URL() or const {url} = require('url'); and parse the URL HOT 1
- Error in getReferenceSchema when namespace contains a dot character
- An in-range update of webpack is breaking the build 🚨 HOT 2
- YAMLException: unacceptable kind of an object to dump [object Undefined] HOT 5
- Loading openapi-definition from Url is not possible HOT 4
- Add npx command to README HOT 3
- Ability to call swagger-codegen / openapi-generator APIs directly
- An in-range update of yargs is breaking the build 🚨 HOT 4
- enumVars.name breaks python code
- An in-range update of yaml is breaking the build 🚨 HOT 5
- An in-range update of webpack is breaking the build 🚨 HOT 24
- Error: Cannot find module '<currentpath>\configs\htmlDocs2.json HOT 3
- Exception on `cg --list` HOT 2
- `oneOf` support via Discriminated Unions HOT 1
- schema $refs to objects broken? HOT 5
- model object doesn't have isEnum property
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-codegen.