[data-plane priority] Content-Type header parameter next to binary/stream body parameter
See original GitHub issueOn our road to enable data plane generation, we (the C# people) have hit a slightly problematic scenario that was no supported in C# but is now. Please make sure it is also supported in your respective language.
Scenario
An API call accepts images (i.e. binary data) that can be of different types, say image/png
or image/jpeg
.
The Swagger for this call says consumes: ['image/png', 'image/jpeg']
, accordingly.
Since our generated clients accept raw binary data or a stream, we have to enable users to specify the content type header of that data, as otherwise what header are we gonna send?
So far so good, so you add a header parameter called Content-Type
to your Swagger.
Problem 1
According to the OpenAPI standard, a header parameter called Content-Type
are to be ignored as if it was not specified at all.
I guess their idea is that the content type should be fully derivable from the request body, which usually makes sense (why would you offer the opportunity to specify and hence possibly screw up derivable information… just derive it).
However, in this very scenario (I think binary data in general), there is no practical way to derive the content type!
Solution
AutoRest has always ignored that part of the spec, so “you guys” (the language generator) will see the parameters show up on your side already, sweet.
Problem 2
The generated code may not do the “right thing” with the parameter. This hit us in C# since the method to add custom headers to an HTTP request rejects any attempts to set Content-Type
(“this is special, please use the dedicated property, blablabla”).
Solution
Make sure your generator does the right thing and generates working code (note that the C# bug was only exposed at runtime). If not, please fix it.
Example and Testing Strategy
I’ve added an example testing for this very behavior, feel free to use this example as your test case. Ideally, you can just check if the generated code in there works up to the point where a correct HTTP request is sent out. Note that the configuration file also contains some more details about what changes I did for C# and language agnostically, maybe it helps.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (14 by maintainers)
Top GitHub Comments
Verified in Java overwriting
Content-Type
is allowed.Synched up with @olydis and cleared up the issue.