Ask a Question

ApiImplicitParam not showing File param on swagger UI

ubaidshahid
New Contributor

ApiImplicitParam not showing File param on swagger UI

I am creating swagger document using annotations in springboot application, all the APIs params are working instead of file param, file param is not being shown in the swagger UI. It is also not giving any errors in the logs related to the file attribute.

 

Below is the annotation being used to display the file param.

@ApiImplicitParam(name="mediafile", value="upload the file", dataTypeClass="File.class", required=true, paramType="form")

I also have changed paramType="formData" but still file attribute is still not showing up. Any help will be appreciated.

 

Swagger = v3.0

2 REPLIES 2
ponelat
Staff

Re: ApiImplicitParam not showing File param on swagger UI

Hi @ubaidshahid 

 

I'm no Java expert.

OpenAPI v3 has changed the way it handles file uploads (via Multipart) away from `paramters` and into `requestBody`.

This example may help...

https://github.com/swagger-api/swagger-core/blob/438230d79d4597d6b703437a03c32cdbf8a28ba5/modules/sw...

 

package io.swagger.v3.jaxrs2.it.resources;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import org.glassfish.jersey.media.multipart.FormDataParam;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.InputStream;

@Path("/files")
@Produces("application/json")
public class MultiPartFileResource {
    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(@FormDataParam("fileIdRenamed") final String fileId,
                               @Parameter(schema = @Schema(type = "string", format = "binary")) @FormDataParam("fileRenamed") final InputStream file) {
        return Response.status(200).entity("File  " + fileId + " has been uploaded").build();
    }
}
ubaidshahid
New Contributor

Re: ApiImplicitParam not showing File param on swagger UI

Thanks for giving me some solution advice, but this same thing i replicated to my code editor and tried to run, but it is not showing file attribute on swagger UI, it is just showing the 

fileIdRename attribute not fileRename attribute

cancel
Showing results for 
Search instead for 
Did you mean: