Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9372
Closed
Open
Issue created Apr 29, 2021 by Administrator@rootContributor

[BUG] [JaxRS-CDI] Issue with simple file upload: generated code do not build

Created by: selliera

Description

When using the java jaxrs-cxf-cdi generator (but I believe the issue is generic to all java jaxrs server generators), trying to define a simple upload endpoint:

    /test/upload:
      post:
        summary: test upload
        description: upload test
        operationId: testUpload
        requestBody:
          required: false
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        responses:
          default:
            description: whatever

Following the pattern from https://swagger.io/docs/specification/describing-request-body/file-upload/

The generated code do not compile: it creates something like:

 @POST 
   @Consumes({ "application/octet-stream" })
   @ApiOperation(value = "test upload", notes = "upload test", response = Void.class, tags={  })
   @ApiResponses(value = { 
       @ApiResponse(code = 200, message = "whatever", response = Void.class) })
    public Response testUpload(@ApiParam(value = "" ) File body) {
        return delegate.testUpload(bodyInputStream, bodyDetail, securityContext);
    }

Which do not build at all of course. I expected to have something like thin in the Api.java file:

@POST 
     @Consumes({ "application/octet-stream" })
     @ApiOperation(value = "test upload", notes = "upload test", response = Void.class, tags={  })
     @ApiResponses(value = { 
         @ApiResponse(code = 200, message = "whatever", response = Void.class) })
      public Response testUpload(@ApiParam(value = "" ) java.io.InputStream body) {
          return delegate.testUpload(body, securityContext);
      }

And in the ApiService.java I do get:

public interface TestApiService {
      public Response testUpload(File body, SecurityContext securityContext);
}

Where I expected:

public interface TestApiService {
      public Response testUpload(java.io.InputStream body, SecurityContext securityContext);
}
openapi-generator version

I see this with openapi 5.0.0, but I do not think it is a regression: looking at the git history, the definition typeMapping.put("binary", "File"); being obtained from the Default Generator in the jax-rs generator seems quite old.

OpenAPI declaration file content or url
    /test/upload:
      post:
        summary: test upload
        description: upload test
        operationId: testUpload
        requestBody:
          required: false
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        responses:
          default:
            description: whatever
Suggest a fix/enhancement

If this is considered a bug (and I believe it is), I can try to put a patch together. This will probably require to add a

typeMapping.put("binary", "java.io.InputStream");

in the base jaxrs generator. And to find a way for the different parts of the templates to agree not using the multipart arguments.

Assignee
Assign to
Time tracking