简体   繁体   English

Generating C# Rest API Client from swagger.json

[英]Generating C# Rest API Client from swagger.json

I am attempting to create a Rest API Client from the Swagger json file generated by Ambari.我正在尝试从 Ambari 生成的 Swagger Z466DEEC76ECDF5FCA6D38571FZ624 文件创建 Rest API 客户端。 Unfortunately the json uses # in item names:不幸的是 json 在项目名称中使用 # :

  "get": {
    "tags": [ "Actions" ],
    "summary": "Get all action definitions",
    "description": "",
    "operationId": "ActionService#getActionDefinitions",       <<<<<
    "produces": [ "text/plain" ],

I have tried AutoRest, Nswag, Swagger and Open API Rest API Client Generators.我已经尝试过 AutoRest、Nswag、Swagger 和打开 API Rest ZDB974238714CA8DE634A7D 客户端 ACE1。 Nswag is the only one that does not crash and burn. Nswag 是唯一不会崩溃和燃烧的。 However it's output is unusable because the '#' characters end up in the c# names.但是,它的 output 无法使用,因为“#”字符最终出现在 c# 名称中。

is reserved for the compiler directives.为编译器指令保留。

I end up with lines like...unusable:我最终得到了......无法使用的线条:

System.Threading.Tasks.Task<System.Collections.Generic.ICollection<ActionResponseSwagger>> ActionService#getActionDefinitionsAsync(string fields, string sortBy, int? page_size, string from, string to);

Is there a work around to this issue?有解决这个问题的方法吗?

I ended up using SwaggerHub https://swagger.io/tools/swaggerhub/ .我最终使用了 SwaggerHub https://swagger.io/tools/swaggerhub/ It did a good job of generating a RestSharp client.它在生成 RestSharp 客户端方面做得很好。 Unfortunately, the Ambari Swagger json is poorly defined.不幸的是,Ambari Swagger json 定义不明确。 You still need to edit the Requests.您仍然需要编辑请求。 But at least SwaggerGen created the entire client without choking.但至少 SwaggerGen 在没有窒息的情况下创建了整个客户端。 Most of the tools I tried needed manual edits of the json.我尝试的大多数工具都需要手动编辑 json。

More detailed information at: How to use RestSharp with Ambari Swagger更多详细信息请参见: 如何将 RestSharp 与 Ambari Swagger 一起使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swagger 不生成 swagger.json - Swagger is not generating swagger.json 从基础 controller 继承 controller 操作时生成 swagger.json 文件的问题 - Issue generating swagger.json file when inheriting controller actions from a base controller 从 JSON Schema 为 Sabre REST API 生成 C# 模型类 - Generating C# model classes from JSON Schema for Sabre REST API Swashbuckle C#swagger插件默认情况下如何使用我自己的个人swagger.json而不是依靠它生成的一个? - Swashbuckle C# swagger plugin how to use my own personal swagger.json by default instead of relying on one it generates? .net core/swagger - 生成 swagger.json 文件时如何绕过控制器文件? - .net core/swagger - How can I around a controller file when generating the swagger.json file? 显示 Swagger.json 但 UI 不显示 - Swagger.json is displayed but the UI not Blazor Swagger:无法加载 API 定义。 获取错误:未定义 /swagger/v1/swagger.json - Blazor Swagger: Failed to load API definition. Fetch error: undefined /swagger/v1/swagger.json 如何从 swagger.json 中删除反引号 - How to remove back quote from swagger.json 未能加载 API 定义,获取错误:未定义 /swagger/v1/swagger.json - Failed to load API definition, Fetch error: undefined /swagger/v1/swagger.json ASP NET Boilerplate>使用swagger codegen工具(nswag)生成C#swagger客户端无法正常工作 - ASP NET Boilerplate > Generating C# swagger client using swagger codegen tool (nswag) not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM