[英]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# 名称中。
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.