swagger-core annotations required to specify HTTP requestBody form parameters?
This is related to my other question today: https://community.smartbear.com/t5/Swagger-Open-Source-Tools/How-to-suppress-requestBody-generation-in-OpenAPI-spec-using/m-p/203314#M1192. I’m trying to now figure out how to use swagger-core annotations to specify requestBody form parameters. What I want to generate is described here: https://swagger.io/docs/specification/describing-request-body/ in the section “Form Data”. I specifically want to generate the .yaml described in the box under: “In OpenAPI 3.0, form data is modelled using a type: object schema where the object properties represent the form fields:”
Here is my relevant swagger-core annotated code:
@Path("/Test00020")
public class Test00020 extends HttpServlet {
@Override
@POST
@Operation (
summary = "Ask something, get something back.",
requestBody = @RequestBody( description = "Form POST parameters in request body", required = true,
content = @Content( schema = @Schema(implementation = Object.class,
name = "Test00020" ))))
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ...
which results in this .yaml:
paths:
/Test00020:
post:
summary: Ask something, get something back.
operationId: doPost
requestBody:
description: Form POST parameters in request body
content:
application/x-www-form-urlencoded:
schema:
type: object. <-- Good up to here, but properties: block missing (see below)
required: true
responses:
default:
description: default response
content:
text/html: {}
This is pretty close, but it is missing the parameter name and type param properties in the request body schema:
properties:
Test00020: # <!--- form field name
type: string
I couldn’t find any example of how to actually do this, and my trial and error got me this far. The name = "Test00020" element of the Content Schema is being ignored. Any clue how I fix my annotations to get it to work properly?