Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspect refs inside entity schema are nullable #10695

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading