How to suppress requestBody generation in OpenAPI spec using swagger-maven-plugin
I'm using the swagger-maven-plugin in a Java application with an old school servlet implementation. I'm trying to follow the examples here: https://github.com/swagger-api/swagger-samples/, but unfortunately this one: https://github.com/swagger-api/swagger-samples/blob/master/java/java-servlet/src/main/java/io/swagger/sample/servlet/SampleServlet.java which is the closest match, uses the 1.x version of swagger.core, not 2.x.
I found other examples that sort of work (see what I did below), except that it generates an almost 950 line requestBody element in the openapi.yaml doc for this endpoint. Why does it do that? Is there a way to suppress that? Below is the maven import and the code snippet:
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.1.2</version>
The code with annotations is:
@Path("/Test00020")
public class Test00020 extends HttpServlet {
@Override
@GET
@Operation (
summary = "Ask something, get something back.",
parameters = { @Parameter(in = ParameterIn.QUERY, name="TestParam00020", required = true ) }
)
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ...
Thanks, Dave
you can hide any parameter including request body via @Parameter.hidden annotation, like:
@Override @GET @Operation ( summary = "Ask something, get something back.", parameters = { @Parameter(in = ParameterIn.QUERY, name="TestParam00020", required = true ) } ) public void doGet(@Parameter(hidden = true) HttpServletRequest request, @Parameter(hidden = true) HttpServletResponse response) throws ServletException, IOException { }
Did you apply the annotation also to the response? and are you using the latest version?
I suspect you didn't hide the response and you're seeing that in your outcome. As mentioned, the reader is targeting JAX-RS methods, therefore it tries to resolve method parameters if not hidden, and response is a method parameter.
I tested with the code above and request body is correctly not resolved