visual-studio-2017 - 为什么 Visual Studio 2017 无法为 Swagger Petstore 生成 REST API 客户端?

标签 visual-studio-2017 swagger autorest

我正在尝试使用 Swagger/OpenAPI 文档/规范在 C# 中生成 REST API 客户端代码,但我遇到了几个问题。

最值得注意的是 - 在尝试使用 Swagger.io Petstore 示例作为起点时:

enter image description here

使用 VS 2017 Add > REST API client VS 2017 中的选项,我没有生成任何代码 - 而是显示错误:

enter image description here

Generating client code and adding to project started
Generate client code for REST API with following parameters:
REST API Name: OpenApiClientClient, Base namespace: OpenApiClient, Metadata file path: C:\Users\Marc\AppData\Local\Temp\WebToolsAutoRest\OpenApiClientClient\201807162213351660\swagger.json
[Info]AutoRest Core 0.16.0.0
[Info]Initializing modeler.
[Info]Initializing modeler.
[Info]Parsing swagger json file.
[Info]Generating client model from swagger model.
[Fatal]Error generating client model: Collection format "multi" is not supported (in parameter 'status').
Exception: There was an error during code generation when trying to add a client for the REST API
Generating client code and adding to project failed
Adding REST API client for failed



因此,如果 Swagger 示例应用程序不兼容 - 其他人会如何?? (不幸的是,我尝试了其他几个,结果都一样)。

这里有什么问题?我是否遗漏了什么,我是否需要向 VS 2017 添加一些额外的工具才能使其工作?

更新 :

好的,所以我现在尝试直接使用 npm 安装 Autorest:
npm install -g autorest

这似乎有效 - 没有显示错误或任何内容。

但是尝试运行 Autorest - 使用一组命令行参数,或者甚至单独运行 - 会导致错误:
AutoRest -CodeGenerator CSharp -Modeler Swagger 
         -Input https://petstore.swagger.io/v2/swagger.json 
         -Namespace Services.UserServiceClient -OutputDirectory d:\projects 
         -AddCrendentials true

要不就
AutoRest <kbd>Enter</kbd>

结果是:

AutoRest code generation utility [version: 2.0.4280; node: v9.9.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
Failure:
Error: Unable to start AutoRest Core from C:\Users\Marc.autorest\@microsoft.azure_autorest-core@2.0.4280\node_modules\@microsoft.azure\autorest-core
Error: Unable to start AutoRest Core from C:\Users\Marc.autorest\@microsoft.azure_autorest-core@2.0.4280\node_modules\@microsoft.azure\autorest-core
at main (C:\Users\Marc\AppData\Roaming\npm\node_modules\autorest \dist\app.js:232:19) at



任何进一步的想法?

最佳答案

Visual Studio 2017 使用的是非常旧版本的 AutoRest .您看到的问题是 this one这是在 AutoRest v. 1.0 中修复的。如 explained in the comments在那个问题上:

Are you referring to the autorest version that's built-into visual studio? -- That's incredibly old, and we didn't update that (we've changed the whole way autorest works).

You are going to need to install node and use autorest from the command line.


看起来像 it's not possible to update AutoRest Visual Studio 2017 使用,因此您需要直接调用 AutoRest。

关于visual-studio-2017 - 为什么 Visual Studio 2017 无法为 Swagger Petstore 生成 REST API 客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51369396/

相关文章:

c++ - 使用 Visual Studio 2017 进行并行编程

c# - 编译 Autorest 生成的客户端时出错

c# - 系统.反射.TargetException : 'Non-static method requires a target.' only with VS 2017 not with VS 2013

iis - 在 Visual Studio 2017 中设置 .NET Core MVC 应用程序以使用完整的 IIS(不是 IIS Express)

swagger - 生成 REST API 文档的步骤

java - 在 Spring MVC 中包含 swagger 后,无法在 jetty 中运行应用程序

node.js - @nestjs/Swagger : How to add API URL?

c# - Swashbuckle 正在生成没有域类型信息的 Swagger 定义文件(缺少 #/definition/domain-type 部分)

swagger - Autorest 错误 - swagger.json' 不是有效的 OpenAPI 2.0 定义(预期为 'swagger: 2.0')

.net - 如何从 .NET Core/Standard 项目中排除文件/文件夹?