Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use custom T4 template when generating client code #273

Closed
dziedrius opened this issue Sep 7, 2016 · 8 comments
Closed

Comments

@dziedrius
Copy link

Currently I could not find ability to customize T4 template without using custom NSwag build and there are many cases when using base class or partial method does not cover the extensibility needs.

Swagger codegen allows to use custom templates, but it has other issues (java runtime :)

If it is not possible to use custom T4 template directly from command line, may be it would be possible to load compiled T4 template as dll and use it such way.

@RicoSuter
Copy link
Owner

Currently you can provide your own TemplateFactory and render your own code... but it cannot be used in the command line because there is no way to load external DLLs into the process and instantiate a template factory. However we could add a new cmd line parameters:

  • ExtensionAssemblies: Assemblies which are loaded into the cmd line process
  • TemplateFactoryType: The full type name which is instantiated and used as template factory (loaded from an extension assembly)

This way you can implement the template factory and then use it in the cmd line tool.
What do you think?

@RicoSuter
Copy link
Owner

Another option would be to use another template engine which can also compile/run templates at runtime, see #263
But then you can only change the template but not the logic - which may be limiting in some scenarios...

@dziedrius
Copy link
Author

Your suggestion regarding additional cmd line parameters to provide own extension assembly with custom template factory type seems good to me, it should cover most cases that I can think of.

@dziedrius
Copy link
Author

Looks like even using NSwag not from command line it is not possible to use custom template, as I need pass into template's constructor instance ClientTemplateModel, which is internal :(

NSwag.CodeGeneration.CodeGenerators.CSharp.Models { internal class ClientTemplateModel

@RicoSuter
Copy link
Owner

ClientTemplateModel and the other models will be public in the next version...

@RicoSuter
Copy link
Owner

Please write your own simple cmd line tool until this feature has been implemented.

@RicoSuter
Copy link
Owner

See #263

@RicoSuter
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants