Bug Report Checklist
Description
Having a field of type string with format byte marked as both nullable and required will result in the generator creating a model with a field of type JsonNullable<byte[]> (So far, so good). However, in the implementation of the equals method, the generated code will try to compare the values of this field using Arrays.equals, resulting in a compilation error.
openapi-generator version
7.4.0-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Nullable string<byte> bug
version: 1.0.0
paths: {}
components:
schemas:
Foo:
type: object
properties:
bar:
type: string
format: byte
nullable: true
required:
- bar
Generation Details
spring generator.
Field string with format byte marked as nullable and required
Output
// ...
private JsonNullable<byte[]> bar = JsonNullable.<byte[]>undefined();
// ...
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Foo foo = (Foo) o;
return Arrays.equals(this.bar, foo.bar);
}
// ...
Steps to reproduce
- Use above specification with filename
api-docs.yml
- Run the generator
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:latest generate -i /local/api-docs.yml -g spring -o /local/output
- Change to generated folder
cd output
- Attempt to compile project
mvn compile
Related issues/PRs
Couldn't find any
Suggest a fix
When the field is not marked required, the generated code is correct.
// ...
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Foo foo = (Foo) o;
return equalsNullable(this.bar, foo.bar);
}
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}
// ...
Bug Report Checklist
Description
Having a field of type
stringwith formatbytemarked as bothnullableandrequiredwill result in the generator creating a model with a field of typeJsonNullable<byte[]>(So far, so good). However, in the implementation of theequalsmethod, the generated code will try to compare the values of this field usingArrays.equals, resulting in a compilation error.openapi-generator version
7.4.0-SNAPSHOT
OpenAPI declaration file content or url
Generation Details
springgenerator.Field
stringwith formatbytemarked asnullableandrequiredOutput
Steps to reproduce
api-docs.ymldocker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:latest generate -i /local/api-docs.yml -g spring -o /local/outputcd outputmvn compileRelated issues/PRs
Couldn't find any
Suggest a fix
When the field is not marked
required, the generated code is correct.