简体   繁体   中英

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. Unfortunately the json uses # in item names:

  "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. Nswag is the only one that does not crash and burn. However it's output is unusable because the '#' characters end up in the c# names.

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/ . It did a good job of generating a RestSharp client. Unfortunately, the Ambari Swagger json is poorly defined. You still need to edit the Requests. But at least SwaggerGen created the entire client without choking. Most of the tools I tried needed manual edits of the json.

More detailed information at: How to use RestSharp with Ambari Swagger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM