Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Swagger Codegen with .net core

I am able to integrate the Swagge UI in my web api using Swashbuckle. I also want to explore the swagger codegen feature. Can somebody help in - how I can integrate swagger codegen into my web api project? Or do I need to download any tool? I want to be able it to host the codegen and pass the json/raml form specs to generate client in .net core.

I am not able to find enough docs on above.

EDIT : I want to know how I can host codegen in my WEBAPI.

Thanks!

like image 737
arpymastro Avatar asked Jan 31 '18 10:01

arpymastro


People also ask

How do I enable Swagger in .NET Core?

Add and configure Swagger middleware Launch the app and navigate to https://localhost:<port>/swagger/v1/swagger.json . The generated document describing the endpoints appears as shown in OpenAPI specification (openapi. json). The Swagger UI can be found at https://localhost:<port>/swagger .

What is Swagger codegen for?

Swagger Codegen is an open source project which allows generation of API client libraries (SDK generation), server stubs, and documentation automatically from an OpenAPI Specification.


1 Answers

It seems like you just want to generate C# from the OpenApi specification (your Swagger implementation provides the input) of your API.

To generate code (e.g. C#) from the OpenApi spec file of your API, you can do something like this:

java -jar .\openapi-generator-cli-5.0.0-beta3.jar generate -i https://localhost:xxxx/api/v1/swagger.json -g csharp

You have to download the OpenApi Generator Jar. Alternatively you can upload your code to a web generator. But I would always run this locally; you never know where your code ends up.

like image 162
Jeffrey Verpoort Avatar answered Oct 25 '22 11:10

Jeffrey Verpoort