I am wanting to essentially replicate a @RequestBody
with @Parameter
. I found this in Swagger documentation: "Also without a @RequestBody
annotated parameter and with no @RequestBody
annotation at method level or as field of Operation#requestBody, if a parameter is annotated with @Parameter
with no in field specified and no JAX-RS annotation (@QueryParam
, @HeaderParam
, @BeanParam
), the parameter is resolved as a request body."
My use case is that I have an annotation that will be used across many microservices, so we want to define it once in our common library. Spring does not pick up @RequestBody
as a meta-annotation, while @Parameter
is picked up. Essentially, I am trying to use @Parameter
as an @RequestBody
.
My code:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@Parameter(
in = ParameterIn.DEFAULT,
description = "Dynamic query string that will be used to query/filter this resource.",
required = true,
examples = {
@ExampleObject(
name = "example1",
summary = "Search for a...",
value = "hello==4567*",
description = "blah"
),
@ExampleObject(
name = "example2",
summary = "samplee",
value = "hello==John*",
description = "blahhh"
)
},
schema = @Schema(
description = "Query Field and Value",
name = "Query",
allowableValues = {"query"})
)
public @interface Query {
Class<?> value();
}
This works so far EXCEPT for the examples =
. It does work with @RequestBody
, but not with @Parameter
. How can I get @ExampleObject
or something similar work with @Parameter
? example =
does work, but it doesn't have the same toggle option examples
gives. We are using OpenAPI 3.0.
Thanks so much.