Open mattt90 opened 5 years ago
Any news on this? Is implementing a custom operation filter the only way to sort of fix this by limiting the content types to the one my code should actually send? My generated code crashes because for some reason application/x-www-form-urlencoded was selected during client code generation (it is the last content type in the list). As a result the generated client tries to serialize and deserialize the object passed in as body argument as a dictionary and set it as FormUrlEncodedContent, which it is not. It should be serialized as json.
@RicoSuter perhaps this requires some overloads to be considered?
I agree, I also need such a funcinonal that will allow me to indicate consumes for requests, and will fill content correctly.
Looking at the client generation templates : https://github.com/RSuter/NSwag/blob/master/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid#L155 this consumes takes the first Content-Type on the swagger.json (https://github.com/RSuter/NSwag/blob/master/src/NSwag.CodeGeneration/Models/OperationModelBase.cs#L227).
My method accepts multiple ContentTypes: "consumes": [ "application/merge-patch+json", "application/json-patch+json" ], When the Client is generated it sets the ContentType to the first one by default, so if I call that method with ContentType "application/json-patch+json" the parameter becomes null.
Is there a way to expose content-type as a parameter or split this method in the contracts so that it exposes two endpoints that call the same method just with different content-types?
What would you suggest doing for this scenario?
Somewhat related to #1150 and #1765
Thanks, I appreciate your feedback.