[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.