Writing new templates for generation of files

1,861 views
Skip to first unread message

shenoy tinny

unread,
Sep 25, 2015, 3:08:33 PM9/25/15
to Swagger
Hello,

I am new to using swagger code gen tool. I understand that I can write new templates and have files generated according to the template. I have written the template and added it to the templateDir. But, I am not sure how to implement the code to generate charp files according to the template I have written.

Taking the api.mustache and model.mustache as examples.

// We are adding the template files to ah hash map , like this:

this.modelTemplatesFiles.put("model.mustache",".cs");
this.apiTemplatesFiles.put("api.mustache",".cs");


These two lines seem to generate the api and model cs files in the appropriate package. So, do I have to create a new hash map for my new template and then what all other methods should I be adding to make the auto-generation work?

If you can point me to the methods in the code, that would be helpful

Thanks

wing328

unread,
Sep 28, 2015, 1:20:29 PM9/28/15
to Swagger
You can specify the directory of your own template files using the "-t" option as follows:

 -t <template directory>, --template-dir <template directory>
            folder containing the template files


Here is an example:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
   -l csharp \
   -t  /var/tmp/csharp/templates/ \
   -o /var/tmp/csharp/test


Would this meet your requirement in customising the auto-generated csharp code?

I would also like to know what exactly you would like to customize if you don't mind to share.

Best,
William 




shenoy tinny於 2015年9月26日星期六 UTC+8上午3時08分33秒寫道:

shenoy tinny

unread,
Sep 30, 2015, 5:33:02 PM9/30/15
to Swagger
Hello,

Thanks for your reply. I need to create a template the would create cmdlet cs files for each api operation. Since the example templates work for each operation group, is there a way to have cs files generated for each operation as opposed to each operation group.

Thanks

William Cheng

unread,
Oct 2, 2015, 10:59:38 AM10/2/15
to swagger-sw...@googlegroups.com
Currently, I'm not aware of any way to generate CS files for each operation. As a workaround, can the cmdlet for each operation group according to operation group?

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/PAir3Tw0B64/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tony tam

unread,
Oct 2, 2015, 8:06:44 PM10/2/15
to Swagger
I believe you can override this operation:


To create your own grouping of files.  Current logic is to use `tags`.
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

shenoy tinny

unread,
Oct 5, 2015, 5:57:50 PM10/5/15
to Swagger
OK, yeah thats an option. Is there a way to lowercase or camelcase the variables in the mustache template?

Thanks

William Cheng

unread,
Oct 6, 2015, 12:13:09 AM10/6/15
to swagger-sw...@googlegroups.com
If there's variable naming not conforming to C# style guide in the mustache template, please open an issue here (https://github.com/swagger-api/swagger-codegen/issues) and we'll look into that. 

To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/PAir3Tw0B64/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages