Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Consumes' field on swagger definition is ignored after v2.0.245 for Get/Delete requests

See original GitHub issue

Before 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(
          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:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

RikkiGibsoncommented, Jun 24, 2018

Got it. I’ll try and have a look tomorrow.

RikkiGibsoncommented, Jul 26, 2018

@bernarden thanks for waiting so long on this–please give the newest a try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

global "consumes" flag should be ignored when method is ...
Description In the Swagger UI if you have a global consumes set then all ... field should be ignored but the one directly...
Read more >
OpenAPI Specification - Version 2.0 - Swagger
Version 2.0 specification defines a set of files required to describe an API. These files can then be used by the Swagger-UI project...
Read more >
Describing Request Body - Swagger
It is required but ignored (it is used for documentation purposes only). Object Payload (JSON, etc.) Many APIs transmit data as an object,...
Read more >
Describing Request Body - Swagger
GET, DELETE and HEAD are no longer allowed to have request body because it does not have defined semantics as per RFC 7231....
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
An OpenAPI definition uses and conforms to the OpenAPI Specification. ... (OAS 2.0 documents contain a top-level version field named swagger and value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found