Skip to content

Commit

Permalink
extract the aspect json from the of the request body. Revert change t…
Browse files Browse the repository at this point in the history
…o request body declaration in open api
  • Loading branch information
kevin1chun committed Jul 22, 2024
1 parent 318c76f commit 9148e08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.datahub.authorization.AuthorizerChain;
import com.datahub.util.RecordUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableSet;
import com.linkedin.common.urn.Urn;
Expand Down Expand Up @@ -511,7 +512,7 @@ public ResponseEntity<E> createAspect(
@RequestParam(value = "createIfNotExists", required = false, defaultValue = "true")
Boolean createIfNotExists,
@RequestBody @Nonnull String jsonAspect)
throws URISyntaxException {
throws URISyntaxException, JsonProcessingException {

Urn urn = validatedUrn(entityUrn);
EntitySpec entitySpec = entityRegistry.getEntitySpec(entityName);
Expand Down Expand Up @@ -649,8 +650,8 @@ protected Boolean exists(
* fixes)
*
* @param requestedAspectNames requested aspects
* @return updated map
* @param <T> map values
* @return updated map
*/
protected <T> LinkedHashMap<Urn, Map<String, T>> resolveAspectNames(
LinkedHashMap<Urn, Map<String, T>> requestedAspectNames, @Nonnull T defaultValue) {
Expand Down Expand Up @@ -732,15 +733,17 @@ protected ChangeMCP toUpsertItem(
Boolean createIfNotExists,
String jsonAspect,
Actor actor)
throws URISyntaxException {
throws JsonProcessingException {
JsonNode jsonNode = objectMapper.readTree(jsonAspect);
String aspectJson = jsonNode.get("value").toString();
return ChangeItemImpl.builder()
.urn(entityUrn)
.aspectName(aspectSpec.getName())
.changeType(Boolean.TRUE.equals(createIfNotExists) ? ChangeType.CREATE : ChangeType.UPSERT)
.auditStamp(AuditStampUtils.createAuditStamp(actor.toUrnStr()))
.recordTemplate(
GenericRecordUtils.deserializeAspect(
ByteString.copyString(jsonAspect, StandardCharsets.UTF_8),
ByteString.copyString(aspectJson, StandardCharsets.UTF_8),
GenericRecordUtils.JSON,
aspectSpec))
.build(aspectRetriever);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ private static PathItem buildSingleEntityAspectPath(
new Schema()
.$ref(
String.format(
"#/components/schemas/%s", upperFirstAspect)))));
"#/components/schemas/%s%s",
upperFirstAspect, ASPECT_REQUEST_SUFFIX)))));
final Operation postOperation =
new Operation()
.summary(String.format("Create aspect %s on %s ", aspect, upperFirstEntity))
Expand Down

0 comments on commit 9148e08

Please sign in to comment.