swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.91k stars 6.03k forks source link

Improper function parameters in client code generated for file upload (Image) #5573

Open YathendraPrasad opened 7 years ago

YathendraPrasad commented 7 years ago
Description

A generated post method (JAX-RS code) which takes 2 query parameters of string type and 2 @FormDataParam one for InputStream and one for FormDataContentDisposition for file object. There is client code generated which takes 3 parameters , one File parameter object and two string datatype values. The flow goes like this , A call is made to the POST Rest call which inturn makes call to the generated API client and from there to 3 rd party service (In my case it is watson service). My doubt here is that the code is failing when i try to build with the below exception

class com.ibm.mfp.adapters.sample.api.VisualRecognitionApi cannot be applied to given types; required: java.lang.String,java.io.File,java.lang.String,java.lang.String found: java.lang.String,java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,java.lang.String,javax.ws.rs.core.SecurityContext reason: actual and formal argument lists differ in length

Server code generated :

@POST @Path("/detect_faces") @Consumes({ "multipart/form-data" }) @Produces({ "application/json" }) @io.swagger.annotations.ApiOperation(value = "Detect faces in an image", notes = "", response = Faces.class, tags={ "VisualRecognition" })@io.swagger.annotations.ApiResponses(value = { @io.swagger.annotations.ApiResponse(code = 200, message = "success", response = Faces.class), @io.swagger.annotations.ApiResponse(code = 400, message = "Invalid request", response = Faces.class) }) @OAuthSecurity(enabled=false) public Response v3DetectFacesPost(@ApiParam(value = "API Key used to authenticate.")@QueryParam("api_key") String apiKey, @FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail , @ApiParam(value = "")@FormDataParam("parameters") String parameters ,@ApiParam(value = "") @DefaultValue("2016-05-20") @QueryParam("version") String version ,@Context SecurityContext securityContext),throws NotFoundException, ServiceFactoryFinderException { com.ibm.mfp.adapters.sample.ApiClient apiAuthInstance = new com.ibm.mfp.adapters.sample.ApiClient(); com.ibm.mfp.adapters.sample.api.VisualRecognitionApi apiInstance = new com.ibm.mfp.adapters.sample.api.VisualRecognitionApi(apiAuthInstance);

result = apiInstance.v3DetectFacesPost(apiKey,fileInputStream, fileDetail,parameters,version,securityContext);

Java Client code generated

public Faces v3DetectFacesPost(String apiKey, File file, String parameters, String version) throws ApiException { ApiResponse<Faces> resp = v3DetectFacesPostWithHttpInfo(apiKey, file, parameters, version); return resp.getData(); }

is the client code generated correct ??

Swagger-codegen version

version of swagger-codegen : 2.2.2

Swagger declaration file content or url

"post": {
                "summary": "Detect faces in an image",
                "tags": [
                    "VisualRecognition"
                ],
         "consumes": [ "multipart/form-data" ],
             "produces": [ "application/json"],
                "parameters": [
                    {
                        "$ref": "#/parameters/ApiKeyParam"
                    },
                    {
                        "name": "file",
                        "in": "formData",
                         "description": "The image file (.jpg, .png) or compressed (.zip) file of images.  The total number of images is limited to 20, with a max .zip size of 5 MB.",
                         "required": false,
                        "type": "file"
                    },
                    {
                        "$ref": "#/parameters/URLsOnlyConfigParam"
                    },
                    {
                        "$ref": "#/parameters/DateVersionParam"
                    }
                ]
  }

Please let me know your input on this 
YathendraPrasad commented 7 years ago

Using Swagger codegen maven plugin 2.2.2 version

YathendraPrasad commented 7 years ago

@jencodingatwork , FYI

YathendraPrasad commented 7 years ago

@jencodingatwork : You can probably change the header description if not relevant

YathendraPrasad commented 7 years ago

Hi , can i have update on this please

wing328 commented 7 years ago

@YathendraPrasad I would suggest you to try the latest master to see if the issue has already been addressed.