Reputation: 1963
Has anyone had much experience converting Swagger API definitions to C#.NET client code?
Mostly, Swagger Editor works ok, but the issue we have is that the generated code for some calls has a bunch of required-but-nullable arguments. Eg (truncated argument list for illustration only):
GetCustomers(bool? includeDeceased, string postalCode, string id, string dateAdded)
We would like the generated parameter list to be defined with default values to avoid having to explicitly provide null arguments. So something like this:
GetCustomers(bool? includeDeceased = null, string postalCode = null, int? id = null, string dateAdded = null)
This allows us to make the following call:
GetCustomers(postalCode: "12345")
Rather than:
GetCustomers(includeDeceased: null, postalCode="12345", id: null, dateAdded: null)
We've tried adding "default": null
to the Swagger call definitions where appropriate but this doesn't result in the desired code (in fact, no change, so probably not supported).
Short of manually modifying the resulting client code – which we want to avoid so we can quickly and easily update our code to the latest API definitions – we're a bit stuck.
Upvotes: 0
Views: 421
Reputation: 1963
Well, it seems that the Swagger Editor CsharpDotNet2 client code generator is the culprit here.
I just tried the bog-standard csharp client code generator and it added = null
to all arguments not marked "required": true
.
So I guess it's manually edit the CsharpDotNet2 generator or use the csharp one if you can.
UPDATE And, in case you're wondering, it turns out that the csharp generator is actually the newer one, targeted at .NET 4.5. I was thinking that if one had "DotNet" in the name and the other didn't that that was the one to go for. Silly me.
Upvotes: 1