Description
Bug Report Checklist
- [x ] Have you provided a full/minimal spec to reproduce the issue?
- [x ] Have you validated the input using an OpenAPI validator (example)?
- [ x] Have you tested with the latest master to confirm the issue still exists?
- [x ] Have you searched for related issues/PRs?
- [x ] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using the delegate pattern, delegates are generated with incorrect types for requests which accept file parameters.
You can see the following below, the delegate is generated accepting a MultipartFile while the controller passes a Resource.
Controller Code:
default ResponseEntity<Void> uploadFile(
@Parameter(name = "body", description = "", schema = @Schema(description = "")) @Valid @RequestBody(required = false) org.springframework.core.io.Resource body
) {
return getDelegate().uploadFile(body);
}
Delegate Code:
default ResponseEntity<Void> uploadFile(MultipartFile body) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
openapi-generator version
I have found related issues, but every version I have tried contains this bug:
6.0.0-beta
5.4.0
5.1.0 <-- found similar tickets that said it should not exists here (Seems like the GET version of this issue has been fixed)
OpenAPI declaration file content or url
You can find the issue reproduced in this project here spring resource bug
Generation Details
I am simply using mvn clean compile
here is the pom.xml
Steps to reproduce
- Use the delegate generator config option
- Create a request which accept the following as a request body:
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
- Watch your builds fail running
mvn clean compile
due to type mismatches between delegates and controllers
Related issues/PRs
#9462
#3905 <-- this issue states it was fixed in v4.0.0-beta3 but maybe it was reintroduced or the beta never became a stable release?
Suggest a fix
I have found two work around both of which do not conform to OAS3, but I have found to at least get past build errors:
Solution 1 Custom Type:
- Declare this in your spec -
requestBody:
content:
application/octet-stream:
schema:
type: custom-type-name
- Add this to your type mappings in pom.xml
<typeMappings>custom-type-name=org.springframework.core.io.Resource</typeMappings>
Solution 2 Codegen Type:
Use this in your spec
requestBody:
content:
application/octet-stream:
schema:
type: file
format: binary
This works because this line in SpringCodegen.java
typeMapping.put("file", "org.springframework.core.io.Resource");
I suspect the solution would be to fix the code generating delegate interfaces.