I dont know if this helps but I did something like this below. It could be
completely wrong but it seems to work for us. The incoming argument is the
HttpServletRequest and we pump that through Apache FileUploader...
@POST
@Operation(
summary = "Upload content",
description = "Upload file(s) to content",
parameters = {},
security = {},
requestBody = @RequestBody(
content = @Content(
mediaType = MULTIPART_FORM_DATA,
schema = @Schema(implementation = MultipartRequest.class))),
responses = {
@ApiResponse(
responseCode = "200",
description = "The uploaded files",
content = @Content(
mediaType = APPLICATION_JSON,
array = @ArraySchema(
schema = @Schema(implementation =
FileResult.class)))),
@Produces(APPLICATION_JSON)
@Consumes(MULTIPART_FORM_DATA)
And creating this to hold my multipart data.
/**
* Multipart Content
* <p>
* Used for OpenAPI to mimic a multipart request and/or be used in an array
of
* multipart files.
*/
public final class MultipartRequest
{
/**
* The array of files in OpenAPI format to be upploaded
*/
//@ArraySchema(
// schema = @Schema(type = "string", format = "binary", description
= "File"))
//public List<String> file;
@Schema(type = "string", format = "binary", description = "File")
public String file;
}
On Thu, Nov 14, 2019 at 3:34 PM Oliver Schweitzer
<[email protected]> wrote:
> Hi,
>
> The code below works wonderful in a Karaf Container using CXF (explicit
> via JAXRSServerFactoryBean and also implicitly via Jax-RS whiteboard).
>
> Actually, it is the only way I got Multipart to work and at the same time
> generate sensible Swagger/OpenAPI 2.0 Api description.
>
> Now I’m stuck replicating this same behaviour for OpenAPI 3.0 - the
> Annotations and their semantics have changed, and I can’t get swagger-core
> to generate the right schema.
>
> Has someone on this mailing list encountered the same challenge? Or, if
> not, can point me to a forum where people have?
>
> Best regards,
>
> Oliver
>
> ----------------
>
> import javax.ws.rs.*;
> import javax.ws.rs.core.*;
>
> import org.apache.cxf.jaxrs.ext.multipart.Multipart;
>
> import io.swagger.annotations.Api;
> import io.swagger.annotations.ApiImplicitParam;
> import io.swagger.annotations.ApiImplicitParams;
> import io.swagger.annotations.ApiOperation;
> import io.swagger.annotations.ApiParam;
>
>
> @Path("/upload")
> @POST
> @Produces(MediaType.APPLICATION_JSON)
> @ApiOperation(value = "file upload", response = Result.class)
> @ApiImplicitParams({@ApiImplicitParam(name = "mode", value =
> "mode", required = true, dataType = "string", paramType = "form"),
> @ApiImplicitParam(name = "file", value = "file",
> required = true, dataType =
> "java.io.File", paramType = "form"),
> })
> @Consumes(MediaType.MULTIPART_FORM_DATA)
>
> public Response uploadFile(
> @ApiParam(hidden = true)
> @Multipart(value = "mode",
> required = true)
> String mode,
> @ApiParam(hidden = true)
> @Multipart(value = "file",
> required = true)
> InputStream file) {
> Result result = doStuff(mode,file);
> return Response.ok(serialize(result)).build();
> }
--
*KimJohn Quinn**[email protected] <[email protected]>*
*Logicdrop*22620 Woodward Avenue - Suite D
Ferndale, MI 48220
*O* 888.229.2817
*M* 248.882.0728
*www.logicdrop.com <http://www.logicdrop.com/>*