-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
I see an issue inside the openapi spec when using @Form in combination with @Header or @QueryParam.
The openapi spec validator also says the generated spec is invalid: GET operations cannot have a requestBody.
This happens when I create a Form like this:
public class TestForm {
@QueryParam
String queryParameter;
@Header
String headerParameter;
}
And use it like the following: (the test3 endpoints seem to generate a correct openapi spec.).
@Controller("/test")
public class TestController {
@Form
@Get("/test")
public String testGet(final TestForm form) {
return form.headerParameter + " " + form.queryParameter;
}
@Get("/test2")
public String testGet2(@Form final TestForm form) {
return form.headerParameter + " " + form.queryParameter;
}
@Get("/test3")
public String testGet3(@Header final String headerParameter, @QueryParam final String queryParameter) {
return headerParameter + " " + queryParameter;
}
@Form
@Post("/test")
public String testPost(final TestForm form) {
return form.headerParameter + " " + form.queryParameter;
}
@Post("/test2")
public String testPost2(@Form final TestForm form) {
return form.headerParameter + " " + form.queryParameter;
}
@Post("/test3")
public String testPost3(@Header final String headerParameter, @QueryParam final String queryParameter) {
return headerParameter + " " + queryParameter;
}
}
I would expect in the OpenAPI spec that they are all the a same /test3 but the strange thing is then they are not a header parameter but set like the following:
"paths" : {
"/test/test" : {
"get" : {
"tags" : [
],
"summary" : "",
"description" : "",
"requestBody" : {
"content" : {
"application/x-www-form-urlencoded" : {
"schema" : {
"$ref" : "#/components/schemas/TestForm"
}
}
},
"required" : true
},
"responses" : {
"200" : {
"description" : "",
"content" : {
"application/json" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
}
},
"components" : {
"schemas" : {
"TestForm" : {
"type" : "object",
"properties" : {
"queryParameter" : {
"type" : "string"
},
"headerParameter" : {
"type" : "string"
}
}
}
}
}
I think it should be like the test3 endpoint.
"/test/test3" : {
"get" : {
"tags" : [
],
"summary" : "",
"description" : "",
"parameters" : [
{
"name" : "Header-Parameter",
"in" : "header",
"schema" : {
"type" : "string"
}
},
{
"name" : "queryParameter",
"in" : "query",
"schema" : {
"type" : "string"
}
}
],
"responses" : {
"200" : {
"description" : "",
"content" : {
"application/json" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
}
The generated code seems valid and uses the queryParam and header values.
Metadata
Metadata
Assignees
Labels
No labels