mtennoe / swagger-typescript-codegen

A Swagger Codegenerator tailored for typescript.
Apache License 2.0
141 stars 52 forks source link

API Proposal: Support other template languages #113

Open erictuvesson opened 4 years ago

erictuvesson commented 4 years ago

Justification

Right now only Mustache is supported, I can see the benefits of the template language. It's just a little bit off putting for people how doesn't know it that well to build custom templates.

I don't consider this important, just would like to open a discussion around it.

API Proposal

There are already a something building on top of this, building this up more to be able to handle more abstract types would make it easy to solve.

https://github.com/mtennoe/swagger-typescript-codegen/blob/master/src/transform/transformToCodeWithMustache.ts#L12-L38

I am not sure what the design reason behind having the default templates inside the transform code, it would be nice to move that out of there. https://github.com/mtennoe/swagger-typescript-codegen/blob/master/src/transform/transformToCodeWithMustache.ts#L40-L52

Considerations

mtennoe commented 4 years ago

I like this! @Markionium and I have previously discussed supporting ES6 template literals for instance. To maintain backwards compatibility and allow people to use their preferred template language, adding the template logic in some plugin-like way (with maybe mustache as the default fallback) would be nice, and would make the generator quite a bit more flexible.

I don't think it's the highest priority feature either, but it's definitely a Nice-to-Have

erictuvesson commented 4 years ago

Yes, as little of breaking changes as possible is always nice.

What would be the ideal naming conversion? Currently it's named transform and transformToCodeWithMustache. The options structure should probably also be revisited in some way, so there can be custom options for each language.

mtennoe commented 4 years ago

Hm, naming wise maybe transform and transformToCode would be decent Options-wise it should probably just be a simple base-config with a set of mandatory and optional properties, with some way of extending that based on the template language.