swagger-api / swagger-api/swagger-codegen

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

Open
#5,573 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Issue: Bug Server: Java
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the generated JAX-RS server method signature with the generated Java client method for v3DetectFacesPost, using the supplied Swagger declaration and multipart/form-data parameters. Check how the file, query, and form parameters are mapped, then verify that the generated client and server signatures are compatible and the reported build error is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.