Search code examples
swagger-codegen

Is it possible to specify the client library using swagger codegen?


When generating a client based on Swagger metadata, is it possible to specify or configure things somehow that the output should use some other client library?

So if it was a C# client for example, to automatically replace the HttpClient or RestSharp client (I don't recall what it is now as I have not used it in a while) with some custom library?


Solution

  • Yes it is possible,

    The codegen uses templates and configuation java classes to generate code in different languages. If you're willing to modify these templates and classes this would be a quite simple modification.

    You can find the opensource repository here Swagger-Codegen

    The template files for each language can be found here:

    https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources

    Java config classes:

    https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages

    List of template variables:

    https://github.com/swagger-api/swagger-codegen/wiki/Mustache-Template-Variables

    Template are written in mustache: https://mustache.github.io/mustache.5.html

    Interesting read if you want to start from scratch:

    https://github.com/swagger-api/swagger-codegen/wiki/How-to-add-a-generator-for-a-new-language-or-framework