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

fix(openapi-v3): comprehensive aspect name casing fix #10484

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 @@ -294,7 +294,9 @@ public ResponseEntity<Object> getAspect(
.flatMap(
e ->
e.getAspects().entrySet().stream()
.filter(entry -> entry.getKey().equals(aspectName))
.filter(
entry ->
entry.getKey().equals(lookupAspectSpec(urn, aspectName).getName()))
.map(Map.Entry::getValue)
.findFirst()));
}
Expand Down Expand Up @@ -324,7 +326,7 @@ public ResponseEntity<Object> headAspect(
authentication,
true);

return exists(opContext, urn, aspectName)
return exists(opContext, urn, lookupAspectSpec(urn, aspectName).getName())
? ResponseEntity.noContent().build()
: ResponseEntity.notFound().build();
}
Expand Down Expand Up @@ -414,7 +416,8 @@ public void deleteAspect(
authentication,
true);

entityService.deleteAspect(opContext, entityUrn, aspectName, Map.of(), true);
entityService.deleteAspect(
opContext, entityUrn, lookupAspectSpec(urn, aspectName).getName(), Map.of(), true);
}

@Tag(name = "Generic Aspects")
Expand Down Expand Up @@ -521,9 +524,9 @@ public ResponseEntity<GenericEntity> patchAspect(
authentication,
true);

RecordTemplate currentValue = entityService.getAspect(opContext, urn, aspectName, 0);

AspectSpec aspectSpec = lookupAspectSpec(entitySpec, aspectName);
RecordTemplate currentValue = entityService.getAspect(opContext, urn, aspectSpec.getName(), 0);

GenericPatchTemplate<? extends RecordTemplate> genericPatchTemplate =
GenericPatchTemplate.builder()
.genericJsonPatch(patch)
Expand Down Expand Up @@ -560,7 +563,7 @@ public ResponseEntity<GenericEntity> patchAspect(
.build(
objectMapper,
Map.of(
aspectName,
aspectSpec.getName(),
Pair.of(
result.getNewValue(),
withSystemMetadata ? result.getNewSystemMetadata() : null)))));
Expand Down Expand Up @@ -598,7 +601,11 @@ private List<GenericEntity> toRecordTemplates(

Map<Urn, List<EnvelopedAspect>> aspects =
entityService.getLatestEnvelopedAspects(
opContext, urnsSet, resolveAspectNames(urnsSet, aspectNames));
opContext,
urnsSet,
resolveAspectNames(urnsSet, aspectNames).stream()
.map(AspectSpec::getName)
.collect(Collectors.toSet()));

return urns.stream()
.map(
Expand All @@ -612,18 +619,21 @@ private List<GenericEntity> toRecordTemplates(
}
}

private Set<String> resolveAspectNames(Set<Urn> urns, Set<String> requestedNames) {
if (requestedNames.isEmpty()) {
private Set<AspectSpec> resolveAspectNames(Set<Urn> urns, Set<String> requestedAspectNames) {
if (requestedAspectNames.isEmpty()) {
return urns.stream()
.flatMap(u -> entityRegistry.getEntitySpec(u.getEntityType()).getAspectSpecs().stream())
.map(AspectSpec::getName)
.collect(Collectors.toSet());
} else {
// ensure key is always present
return Stream.concat(
requestedNames.stream(),
urns.stream()
.map(u -> entityRegistry.getEntitySpec(u.getEntityType()).getKeyAspectName()))
.flatMap(
urn ->
requestedAspectNames.stream()
.map(aspectName -> lookupAspectSpec(urn, aspectName))),
urns.stream()
.map(u -> entityRegistry.getEntitySpec(u.getEntityType()).getKeyAspectSpec()))
.collect(Collectors.toSet());
}
}
Expand Down
Loading