openapi-contrib / openapi3-generator

Use your API OpenAPI 3 definition to generate code, documentation, and literally anything you need.
Apache License 2.0
89 stars 27 forks source link

Proposed solution to avoid require cache providing unpredictable module instances #7

Closed scipilot closed 5 years ago

scipilot commented 5 years ago

re. Issue https://github.com/fmvilas/openapi3-generator/issues/6

Note most of the diffs to the templates are whitespace as I indented them. The changes are really just:

- const _ = require('lodash'); 
- const Handlebars = require('handlebars');
+ module.exports = (_, Handlebars) =>{
...
+ }
fmvilas commented 5 years ago

Awesome! Really appreciate. I'm gonna merge it, but gonna do a change on it immediately after.

I'm gonna change the signature of the helpers as follows:

module.exports = (Handlebars, _) => {
};

The reason is that Underscore is not actually needed for registering a Handlebars helper. It's needed for the default helpers and it's good to leave it there for backward compatibility, but could be removed in future versions.

Thank you very much!

fmvilas commented 5 years ago

https://github.com/fmvilas/openapi3-generator/commit/40d68823a18cc0235e1a68ad453ee0e5918c9c90

fmvilas commented 5 years ago

It's already on npm: https://www.npmjs.com/package/openapi3-generator.

scipilot commented 5 years ago

Great. Glad to help - I learned something.