Skip to content

Commit

Permalink
Aspect refs inside entity schema are nullable (#10695)
Browse files Browse the repository at this point in the history
LGTM!
  • Loading branch information
kevin1chun authored and yoonhyejin committed Jul 16, 2024
1 parent d2b8f49 commit c004a71
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,23 @@ private static Schema buildEntityScrollSchema(final EntitySpec entity) {
}

private static Schema buildAspectRef(final String aspect, final boolean withSystemMetadata) {
// A non-required $ref property must be wrapped in a { allOf: [ $ref ] }
// object to allow the
// property to be marked as nullable
final Schema result = new Schema<>();

result.setType(TYPE_OBJECT);
result.set$ref(null);
result.setNullable(true);
final String internalRef;
if (withSystemMetadata) {
result.set$ref(
String.format(FORMAT_PATH_DEFINITIONS, toUpperFirst(aspect), ASPECT_RESPONSE_SUFFIX));
internalRef =
String.format(FORMAT_PATH_DEFINITIONS, toUpperFirst(aspect), ASPECT_RESPONSE_SUFFIX);
} else {
result.set$ref(
String.format(FORMAT_PATH_DEFINITIONS, toUpperFirst(aspect), ASPECT_REQUEST_SUFFIX));
internalRef =
String.format(FORMAT_PATH_DEFINITIONS, toUpperFirst(aspect), ASPECT_REQUEST_SUFFIX);
}
result.setAllOf(List.of(new Schema().$ref(internalRef)));
return result;
}

Expand Down

0 comments on commit c004a71

Please sign in to comment.