简体   繁体   中英

How do I generate .net CORE SDK from swagger definitions?

I have a REST API which generates a swagger through /swagger endpoint. I need to generate a .net client SDK for consumers so they can easily use it to connect to the service from .net code. 客户端SDK,以便他们可以轻松地使用它从.net 代码连接到服务。 The REST service itself is not developed in .net , but in Node.js. 开发的,而是在Node.js中开发的。

Is there a tool that will read the swagger definitions and generate a .net core sdk bindings ?

Options already evaluated(with no success): a. openapi-generator (only generates .Net Framework code, not compatible with .net core) b. NSwag (could not generate any useful code out of it)

Use any standard swagger and try to generate sdk for .net core. eg https://petstore.swagger.io/v2/swagger.json

I am expecting a client side sdk project that will build on .net core.

You could use AutoRest to generate .net code client.

https://github.com/Azure/autorest

Install with npm and lauch cmd

example :

generate the client

autorest --input-file= https://petstore.swagger.io/v2/ --output-folder=c:\\petstore --namespace=Petstore --csharp

Please try OpenAPI Generator (which supports both OpenAPI spec v2, v3) to generate C# .NET Core API client in 3 steps:

1) Download the Java JAR ( http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/4.0.3/openapi-generator-cli-4.0.3.jar )

2) Rename the JAR as "openapi-generator-cli.jar"

3) Run the following command to generate a C# .NET Core API client for the Petstore API ( https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml ):

Mac/Linux:

Windows:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM