You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The field is private Optional<byte[]> mycontent = Optional.empty(); and the actual output in equals() is
@Overridepublicbooleanequals(Objecto) {
if (this == o) {
returntrue;
}
if (o == null || getClass() != o.getClass()) {
returnfalse;
}
DTODTO = (DTO) o;
returnArrays.equals(this.mycontent, DTO.mycontent);
}
As you can see, the this.mycontent is assumed to be array but it is not. It is Optional<byte[]> instead. The equals() template needs to take this into account.
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generator with useOptional=true option and with format: byte generates Optional<byte[]> field for which it then generates wrong equals() method that does not take the Optional into account.
Regarding this specific issue, binary data in JSON should be encoded as a base64 string. The schema isn't used to validate the payload directly, as documents containing binary data may include control characters that invalidate the JSON document. This encoding ensures proper handling of binary data within the JSON structure.
A similar issue is highlighted here - mozilla/jsonschema-transpiler#81
So not sure if format bytes is valid in the first place, please add any context which I might have missed here
Ok, there seems to be 2 sources for the OAS formats vs the JSON format specifications.
While there are specific use cases to natively support base64 format in API specs such as:
Embedding images in HTML and CSS
Sending email attachments: Base64 encoding is used to send email attachments because SMTP was originally designed to only transport 7-bit ASCII characters.
SSL certificates
See the value behind this for APIs dealing in this space, albeit niche - do see the rational behind this feature
Bug Report Checklist
Have you provided a full/minimal spec to reproduce the issue? See https://github.com/vhbcm/openapi-spring-optional-bytes/blob/master/src/main/resources/api.yaml
Have you validated the input using an OpenAPI validator (example)?
Have you tested with the latest master to confirm the issue still exists?
Have you searched for related issues/PRs?
What's the actual output vs expected output?
The field is
private Optional<byte[]> mycontent = Optional.empty();
and the actual output inequals()
isAs you can see, the
this.mycontent
is assumed to be array but it is not. It isOptional<byte[]>
instead. Theequals()
template needs to take this into account.[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generator with
useOptional=true
option and withformat: byte
generatesOptional<byte[]>
field for which it then generates wrongequals()
method that does not take theOptional
into account.openapi-generator version
7.8.0 using Maven
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Checkout the project at https://github.com/vhbcm/openapi-spring-optional-bytes and run
mvn clean install
.Related issues/PRs
This looks like similar kind of issue as #17935.
Suggest a fix
🤷🏿
The text was updated successfully, but these errors were encountered: