Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate C# client from Swagger 1.2 spec?

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 ;-) ).

like image 726
Jack Ukleja Avatar asked Mar 14 '16 11:03

Jack Ukleja


People also ask

Can you write C in MATLAB?

In MATLAB®, you can extend your C and C++ code with a MEX function and call it like any MATLAB built-in function. That means you can use existing C and C++ code without rewriting your algorithms in MATLAB. MEX functions enable C and C++ code to create and modify MATLAB arrays in the MATLAB workspace.

What is C Code generation?

20-sim has a C-Code Generator which automatically converts a complete 20-sim model or submodel into C-Code. The application can be used to generate Matlab™/Simulink™ S-Functions, to generate Stand-Alone executables or to generate input/output functions for use in other C and C++ programs.

Can Simulink generate C Code?

Simulink® Coder™ generates standalone C and C++ code from Simulink models for deployment in a wide variety of applications. For a list of DSP System Toolbox™ features supported by Simulink Coder, see Blocks Supported for C Code Generation.


2 Answers

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"
  }
}
like image 156
fehguy Avatar answered Oct 21 '22 02:10

fehguy


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

like image 1
Pankaj Rawat Avatar answered Oct 21 '22 02:10

Pankaj Rawat