我正在使用Swagger / OpenAPI文档/规范在C#中生成REST API客户端代码,但我遇到了几个问题 .
最值得注意的是 - 当尝试使用Swagger.io Petstore示例作为起点时:
使用VS 2017中的VS 2017 Add > REST API client
选项,我没有生成任何代码 - 而是显示错误:
生成客户端代码并添加到项目已启动使用以下参数为REST API生成客户端代码:REST API名称:OpenApiClientClient,Base命名空间:OpenApiClient,元数据文件路径:C:\ Users \ Marc \ AppData \ Local \ Temp \ WebToolsAutoRest \ OpenApiClientClient \ 201807162213351660 \ swagger.json [Info] AutoRest Core 0.16.0.0 [Info]初始化建模器 . [Info]初始化建模器 . [信息]解析swagger json文件 . [Info]从swagger模型生成客户端模型 . [致命]生成客户端模型时出错:不支持集合格式“multi”(在参数“status”中) . 例外:代码生成期间尝试为REST API添加客户端时生成客户端代码并添加到项目失败添加REST API客户端失败时出错
因此,如果Swagger示例应用程序不兼容 - 其他人将如何? (不幸的是,我尝试了其他几个,结果相同) .
这有什么不对?我错过了什么,我是否需要为VS 2017添加一些额外的工具才能使其工作?
UPDATE :
好的,所以我现在尝试直接使用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代码生成实用程序[版本:2.0.4280; node:v9.9.0](C)2018 Microsoft Corporation . https://aka.ms/autorest失败:错误:无法从C:\ Users \ Marc.autorest \ @ microsoft.azure_autorest-core @ 2.0.4280 \ node_modules \ @ microsoft.azure \ autorest-core错误启动AutoRest Core :无法从主要的C:\ Users \ Marc.autorest \ @ microsoft.azure_autorest-core @ 2.0.4280 \ node_modules \ @ microsoft.azure \ autorest-core启动AutoRest Core(C:\ Users \ Marc \ AppData \ Roaming \ npm \ node_modules \ autorest \ dist \ app.js:232:19)at
还有什么想法?
1 回答
Visual Studio 2017使用的是非常旧版本的AutoRest . 您看到的问题是this one,已在AutoRest v.1.0中修复 . 在该问题中explained in the comments:
看起来像Visual Studio 2017使用的it's not possible to update AutoRest,因此您需要直接调用AutoRest .