I am using swagger 3, I want to add Authorization with "Bearer token" to call this api. I consulted with chatGpt and was instructed to add "@Parameter(name = "Authorization", description = "Bearer token", required = true, in = ParameterIn.HEADER)" but it doesn't work properly, can someone guide me?
@Operation(
description = "Create post, USER/ADMIN",
responses = {
@ApiResponse(content = @Content(schema = @Schema(implementation = PostResponseDTO.class)), responseCode = "200")})
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "200"),
@ApiResponse(responseCode = "401", description = "401", content = @Content(schema = @Schema(implementation = ErrorDTO.class))),
@ApiResponse(responseCode = "403", description = "403", content = @Content(schema = @Schema(implementation = ErrorDTO.class))),
@ApiResponse(responseCode = "404", description = "404", content = @Content(schema = @Schema(implementation = ErrorDTO.class)))
})
@PostMapping
@PreAuthorize("hasAnyRole('USER','ADMIN')")
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(
mediaType = "multipart/form-data",
schema = @Schema(implementation = FormUpload.class)
))
@Parameter(name = "Authorization", description = "Bearer token", required = true, in = ParameterIn.HEADER)
public PostResponseDTO createPost(
@Valid @RequestPart("post") PostRequestDTO postRequestDTO,
@RequestPart(required = false) MultipartFile[] file) throws IOException {
if (!(filesService.notEmpty(file) && filesService.isSingleFile(file) && filesService.isImageFile(file[0]) && filesService.maxSize(file[0], 5))) {
}
return postService.save(postRequestDTO, file);
}