Closed aloussase closed 1 month ago
@aloussase,
Not reproducible.
This is the current result:
Feel free to provide a Minimal, Reproducible Example - with HelloController that reproduces the problem.
This ticket will be closed, but can be reopened if your provide the reproducible sample.
Mmmm maybe it's an issue with how I am annotating the param
@DocumentType
@RequestParam("identification_type") String identificationType
Is this the right way?
I am using Spring Boot 3.3.3
The following just works:
@RestController
@RequestMapping
public class HelloController {
@GetMapping("/api/testInheritance")
public void testme (DocumentType documentType){
}
@Schema(
description = "Tipo de documento",
example = "IDC",
type = "string",
format = "enum",
allowableValues = {"IDC", "RUC", "PAS"}
)
public @interface DocumentType {
}
}
But you're providing the annotation as a parameter. I have a String parameter that I need to annotate with @DocumentType
. Like this:
@RestController
@RequestMapping
public class HelloController {
@GetMapping("/api/testInheritance")
public void testme (@DocumentType String documentType){
}
@Schema(
description = "Tipo de documento",
example = "IDC",
type = "string",
format = "enum",
allowableValues = {"IDC", "RUC", "PAS"}
)
public @interface DocumentType {
}
}
Minimum reproducible example: https://github.com/aloussase/Spring.OpenApi.RequestParams.Enum.Example.
Well you didn't precise how you pass the annotation :)
You need to correct your code: And add @Retention(RetentionPolicy.RUNTIME)
@Schema(
description = "Tipo de documento",
example = "IDC",
type = "string",
format = "enum",
allowableValues = {"IDC", "RUC", "PAS"}
)
@Retention(RetentionPolicy.RUNTIME)
public @interface DocumentType {
}
I see. I thought the @Inherit
annotation on @Schema
would take care of that. Now the example is working. But with those same changes I can't get it to work on my application. Any ideas why this might be?
This is the whole method signature:
@Operation(
summary = "Listar los consumos de un cliente desde una fecha determinada",
description = "Error en la respuesta es null",
security = {@SecurityRequirement(name = "Bearer Authentication")}
)
@GetMapping("/consumptions")
public ResponseEntity<ResponseFormatOut<List<ConsumptionDto>>> listConsumptions(
@DocumentType
@RequestParam("identification_type")
String identificationType,
@RequestParam String identification,
@Parameter(description = "Fecha desde la cual se desea listar los consumos, en el formato YYYY-MM-DD")
@RequestParam("date_since")
@DateTimeFormat(pattern = "yyyy-MM-dd")
LocalDate dateSince,
@AuthenticationPrincipal TarjetaObsequioAuthToken token
) {
And the annotation:
@Schema(
description = "Tipo de documento",
name = "identification_type",
example = "IDC",
type = "string",
format = "enum",
allowableValues = {"IDC", "RUC", "PAS"}
)
@Retention(RetentionPolicy.RUNTIME)
public @interface DocumentType {
}
I discovered the problem. I was using the swagger in the server instead of my local swagger. Sorry for that.
Describe the bug
I am using a custom annotation to annotate a request parameter in a Spring controller.
In swagger UI, this just shows as a string with no information about the allowable values.
To Reproduce Steps to reproduce the behavior:
pom.xml
Use the annotation
DocumentType
on a request param in a controller and see nothing.Expected behavior
I expect swagger UI to show either a dropdown with the values or some information about the allowable values.
Screenshots
Additional context
No answer.