jlo-gmail
jlo-gmail

Reputation: 5038

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 ?

Upvotes: 2

Views: 5164

Answers (1)

jlo-gmail
jlo-gmail

Reputation: 5038

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

Upvotes: 1

Related Questions