Skip to content

Commit

Permalink
Fix file upload OpenAPI annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
amanteaux committed Oct 14, 2024
1 parent 7ac559f commit 6edf007
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.coreoz.webservices.api.file;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataParam;

import java.io.InputStream;

@Data
public class FileUploadRequest {
@Hidden
@FormDataParam("file")
private FormDataBodyPart fileMetadata;

@Schema(name = "file", type = "string", format = "binary")
@FormDataParam("file")
private InputStream fileData;
}
33 changes: 13 additions & 20 deletions src/main/java/com/coreoz/webservices/api/file/FileUploadWs.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
import com.coreoz.plume.jersey.security.permission.PublicApi;
import com.coreoz.services.file.ShowcaseFileType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataParam;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import jakarta.ws.rs.BeanParam;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.io.InputStream;

import java.util.Set;

@Path("/files")
Expand All @@ -46,14 +45,11 @@ public FileUploadWs(FileUploadWebJerseyService fileService, FileMimeTypeDetector
@POST
@Path("/pictures")
@Operation(description = "Upload a file")
public Response uploadPicture(
@Context ContainerRequestContext context,
@FormDataParam("file") FormDataBodyPart fileMetadata,
@FormDataParam("file") InputStream fileData
) {
@RequestBody(content = @Content(schema = @Schema(implementation = FileUploadRequest.class)))
public Response uploadPicture(@BeanParam FileUploadRequest request) {
FileUploadData fileUploadMetadata = FileUploadValidator.from(
fileMetadata,
fileData,
request.getFileMetadata(),
request.getFileData(),
this.fileMimeTypeDetector
)
.fileMaxSize(2_000_000)
Expand All @@ -77,14 +73,11 @@ public Response uploadPicture(
@POST
@Path("/reports")
@Operation(description = "Upload a file")
public Response uploadExcelFile(
@Context ContainerRequestContext context,
@FormDataParam("file") FormDataBodyPart fileMetadata,
@FormDataParam("file") InputStream fileData
) {
@RequestBody(content = @Content(schema = @Schema(implementation = FileUploadRequest.class)))
public Response uploadExcelFile(@BeanParam FileUploadRequest request) {
FileUploadData fileUploadMetadata = FileUploadValidator.from(
fileMetadata,
fileData,
request.getFileMetadata(),
request.getFileData(),
this.fileMimeTypeDetector
)
.fileMaxSize(2_000_000)
Expand Down

0 comments on commit 6edf007

Please sign in to comment.