Forum Discussion

GreatFalcon's avatar
GreatFalcon
Regular Visitor
5 years ago

How to Annotate for Multipart/form-data

I’m using Swagger 2.0 and OpenAPI 3 for my project. I want to annotate endpoints for Multipart/form-data request input(attaches 2 files, payload and metadata) where one file could be xml or json and another should be strictly in json. I tried following code, While parsing the input, getting MediaType of both files are String. Also, I want to put customized header info i.e. “UserID”=”xyz321”

 

class Employee{

                @Post

                @Path("/update")

                @Operation(summary="upload a file", description="it's multipart input request",

                requestBody=@RequestBody(

                                content=

                                                               @Content( mediaType="multipart/form-data",

                                                               schema=@Schema(implementation=MultiRequest.class),

                                                               encoding=@Encoding(

                                                                                               name="payload",

                                                                                               contentType="application/json, application/xml"))))

                Response updateEmpRecords(MultiPart multiPart){

                //business logics

                String ID=?;//get User ID from header of the request

                return null;

                }

               

               

                 }

               

                 classMultiRequest {

    @Schema(type = "string", format = "binary", description = "payload")

    public String file;

    @Schema(description = "metadata")

    public MetaData metadata;

}

 

No RepliesBe the first to reply