Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger Codegen - Content Type for GET not getting set in Spring-MVC generated

Downloaded Swagger Pet Store (Simple) from swagger.io editor page and did a mvn jetty:run

When opening up DevTools on Chrome and exercising a GET, I don't see the header Content-Type field being set.

This is on the GET /pets{id}

screen capture

like image 379
Michael H Avatar asked Nov 04 '15 00:11

Michael H


People also ask

How do I get swagger codegen?

Swagger Codegen is available for download in the GitHub repository, or can be generated for any new or existing OpenAPI-defined API in the integrated SwaggerHub platform.

What is codegen in swagger?

The Swagger Codegen is an open source code-generator to build server stubs and client SDKs directly from a Swagger defined RESTful API. The source code for the Swagger Codegen can be found in GitHub.


1 Answers

OK, found the root cause of this problem thanks to wing328 on the swagger codegen project on github.

It turns out that at the top of our yaml definition file we have:

consumes:
 - application/json

That causes all generated controller methods to expect application/json on content-type. This breaks GET, DELETE, and PATCH api calls which in our case do not have any payload.

like image 196
Michael H Avatar answered Sep 22 '22 13:09

Michael H