Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload with a path parameter doesn't invoke the controller method. #308

Closed
genealogy-cz opened this issue May 13, 2019 · 1 comment
Closed

Comments

@genealogy-cz
Copy link

genealogy-cz commented May 13, 2019

The OpeAPI spec (3.0.2) declares an endpoint with a required parameter and a file upload in the request body. The assigned controller method is never invoked by swagger-inflector (2.0.0) as the expected call params aren't matched.

paths:
  /test/{testId}/content:
    parameters:
      - name: testId
        in: path          
        required: true
        schema:
          type: string
          format: uuid
      
    post:
      x-swagger-router-controller: org.test.TestController
      operationId: uploadTest
      
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                fileData:
                  type: string
                  format: binary
                  
      responses:
        '200':
          description: OK, success.
package org.test;

import java.io.File;
import java.util.UUID;

import javax.ws.rs.core.Response.Status;

import io.swagger.oas.inflector.models.RequestContext;
import io.swagger.oas.inflector.models.ResponseContext;

public class TestController  {
  
  public ResponseContext uploadTest(RequestContext request , UUID testId, File fileData) {
      return new ResponseContext().status(Status.INTERNAL_SERVER_ERROR).entity( "Not implemented" );
  }
}

The POST call is done with curl:

curl -F "[email protected]" "http://localhost:8080/api/test/123e4567-e89b-12d3-a456-426655440002/content"

The error is:

java.lang.IllegalArgumentException: argument type mismatch

To reproduce, set a breakpoint in TestController#uploadTest(), and it is never hit in the debugger.

The reason seems to be in io.swagger.oas.inflector.controllers.OpenAPIOperationController.java lines 354-356: the element at index 2 of the original args[3] should be set with the returned argument (the file object), but instead the whole half-populated args[] gets replaced with args2[] that assumes, that the returned file object is always at index 1, which is not correct when the path contains parameters.

@genealogy-cz genealogy-cz changed the title File upload with a path parameter doesn't invoke a container method. File upload with a path parameter doesn't invoke the controller method. May 13, 2019
frantuma added a commit that referenced this issue Aug 28, 2019
fix #308 - fix processing file upload in operations with parameters
@frantuma
Copy link
Member

Thanks for reporting this! fixed in #328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants