15
votes

There seems to be millions of options out there for every platform, but I'm struggling to find a simple solution for C#. All the ones I have found seem to have given me trouble: either they simply don't work (e.g. http://swaggercodegen.azurewebsites.net/), or only support 2.0 (e.g. AutoRest and NSwag). Half the tools are not even clear what versions they support :-(

I'm aware of the official tool, but that requires JDK 7 which is not currently an option for me.

In desperation I have even tried converting the swagger spec to 2.0, but half the conversion tools I tried didn't work, gave conflicting advice, or I couldn't figure out how to use (I found myself knee deep in nodejs very quickly...is this really the brave new world?! Bring back WSDL ;-) ).

2
Please move your question to softwarerecs.stackexchange.comJakub Konecki
How long is your 1.2 spec? Maybe post your first API? It shouldn't be hard to convert to 2.0 - I think that's your best bet.Charlie

2 Answers

8
votes

You can use the online swagger codegen to create clients without installing anything:

https://generator.swagger.io/

You would choose POST /gen/clients/{language} and enter a body like this:

{
  "options": {},
  "swaggerUrl": "http://petstore.swagger.io/v2/swagger.json"
}

Put your own URL to access the specification. If you need to pass any options, you can put them in the options hash. The list of available options for C# is also available from the generator:

https://generator.swagger.io/api/gen/clients/csharp-dotnet2

{
  "packageName": {
    "opt": "packageName",
    "description": "C# package name (convention: Camel.Case).",
    "type": "string",
    "default": "IO.Swagger"
  },
  "packageVersion": {
    "opt": "packageVersion",
    "description": "C# package version.",
    "type": "string",
    "default": "1.0.0"
  },
  "clientPackage": {
    "opt": "clientPackage",
    "description": "C# client package name (convention: Camel.Case).",
    "type": "string",
    "default": "IO.Swagger.Client"
  }
}
0
votes

NSwag provides multiple options for client generation including a CLI, code, or a Windows application.

enter image description here

You can check complete article on NSwag