cancel
Showing results for 
Search instead for 
Did you mean: 

I'm trying to add an upload file button in Swagger-UI using annotations with swagger-jaxrs2

Highlighted
New Contributor

I'm trying to add an upload file button in Swagger-UI using annotations with swagger-jaxrs2

Can someone please provide example code on how to add a upload file button in the swagger-ui with annotations using swagger-jaxrs2 library?  I've tried many things to no success.  

This is one of the formats I tried: 

 

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/upload")
@Operation(
    summary = "summary",
    description = "description"
    responses = {@ApiResponse(
        responseCode = "200", 
        description = "OK"            
    )}
)
public Response uploadFile(
@FormDataParam("file") InputStream inputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail
)throws RestException{
    //process file code
}


This is the request body that gets produced by swagger-jaxrs2 for file upload with the above code: 

      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  $ref: '#/components/schemas/FormDataContentDisposition'

 

1 REPLY 1
Highlighted
New Contributor

Re: I'm trying to add an upload file button in Swagger-UI using annotations with swagger-jaxrs2

I finally found the solution after 3 weeks of swapping Annotation combinations.  

@Parameter(schema = @Schema(name = "file", type = "string", format = "binary"))

This is needed for the InputStream @FormDataParam annotation.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/upload")
@Operation(
    summary = "summary",
    description = "description"
    responses = {@ApiResponse(
        responseCode = "200", 
        description = "OK"            
    )}
)
public Response uploadFile(
@Parameter(name = "file", type = "string", format = "binary")
@FormDataParam("file") InputStream inputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail
)throws RestException{
    //process file code
}

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors