swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Custom function in mustache files

Open giovannibotta opened this issue 12 years ago • 8 comments

Is it possible to call a custom function from one of the mustache templates as described in this doc? I looked through the code but couldn't find a way.

giovannibotta avatar Apr 22 '14 20:04 giovannibotta

Yes, you can override the processApiMap or processModelMap functions and put a function in the maps, instead of strings.

fehguy avatar Apr 23 '14 00:04 fehguy

OK thanks!

giovannibotta avatar Apr 23 '14 13:04 giovannibotta

Damn it, that does not work because I need to have the function available when I write support files. Is there a way? Thanks

giovannibotta avatar Apr 23 '14 14:04 giovannibotta

This is now supported nicely in develop_2.0. You can use a model factory to enable your own logic in the pojos and update the templates as needed. Please see https://github.com/swagger-api/swagger-codegen/pull/342

fehguy avatar Dec 24 '14 04:12 fehguy

@wing328 @fehguy Is there a way to do this (custom template functions available in mustache) without having to modify the java code?

ClayAtWork avatar Nov 02 '16 18:11 ClayAtWork

No, it's not possible right now. You can have your own templates with your own mustache conditionals.

fehguy avatar Nov 02 '16 18:11 fehguy

Ok. And its' still valid that we would just modify the processModelMap to insert our own function? Do you think it's a common use case for people to override the java code to suite the generation to their codebase? It'd be nice if this were completely handled by templates, but I understand this is a limitation of mustache.

ClayAtWork avatar Nov 02 '16 18:11 ClayAtWork

Yes, you can do that. We are collecting feedback on the next version of codegen, please chime in with your thoughts on this ticket:

https://github.com/swagger-api/swagger-codegen/issues/3950

And this:

https://github.com/swagger-api/swagger-codegen/issues/3948

fehguy avatar Nov 02 '16 18:11 fehguy