从OpenApi.json生成C#客户端

时间:2019-10-22 10:19:32

标签: c#

我有一个.net core 2.2类库。

我已经安装了VS Studio 2017“ OpenAPI(Swagger)连接服务”扩展。

enter image description here

我尝试使用此扩展程序为以下API生成c#客户端:

https://skybox.vividseats.com/services/openapi.json

该扩展程序运行并生成许多文件:

enter image description here

但是,当我构建项目时,出现1640个错误:

enter image description here

似乎已经生成了所有功能,并分别命名为1Async,2Async等...

enter image description here

有人可以看到我在做什么错吗?还是建议使用另一种方法从URL生成客户端?

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

您可能想尝试OpenAPI Generator生成C#.NET Core客户端:

下载最新的稳定版本v4.1.3:http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/4.1.3/openapi-generator-cli-4.1.3.jar,并将其重命名为openapi-generator-cli.jar

  

java -jar openapi-generator-cli.jar生成-g csharp-netcore -i https://skybox.vividseats.com/services/openapi.json -o / var / tmp / --skip-validate-spec

我可以毫无问题地构建项目。请测试一下是否适合您。

存在规范验证错误,因此我使用--skip-validate-spec来跳过这些错误。有空时,请检查这些错误。

还有其他安装OpenAPI Generator的方法:https://github.com/OpenAPITools/openapi-generator#1---installation