'Consumes' field on swagger definition is ignored after v2.0.245 for Get/Delete requests
See original GitHub issueBefore the version 2.0.245 the following was generated for my swagger definition.
...
// Create HTTP transport objects
const httpRequest = new WebResource();
// Set Headers
httpRequest.headers.set("Content-Type", "application/json; charset=utf-8");
...
So the generated package was specifying Content-Type as application/json for all of the types of requests (GET, PUT, etc.).
Since 2.0.245, autorest.typescript seems to only depend on the autorest schema passed to sendOperationRequest function when it comes to the ‘Content-Type’. Eg:
...
operationRes = await this.sendOperationRequest(
httpRequest,
operationArguments,
{
httpMethod: "POST",
baseUrl: this.baseUri,
path: "api/1.0/Controller/Endpoint",
...
requestBody: {
...
},
contentType: "application/json; charset=utf-8",
responses: {
...
},
serializer: this.serializer
});
...
This currently works fine for Patch, Put and Post as far as I can tell but doesn’t work for Get and Delete. For Get and Delete the content type is not set in this autorest schema passed to sendOperationRequest, which makes request coming from a browser default to ‘application/x-www-form-urlencoded’. This fails on the server side (415) because controllers are explicitly specified to consume ‘application/json’.
I have checked the swagger definition generated by the server-side. All endpoints contain:
...
"consumes": [ "application/json"],
...
Am I missing something? Is there a workaround for this other than downgrading?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Got it. I’ll try and have a look tomorrow.
@bernarden thanks for waiting so long on this–please give the newest
@microsoft.azure/autorest.typescript@preview
a try.