Skip to content

Commit

Permalink
fix(openapiv3): v3 scroll response fix (#10654)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Chun <kevin1chun@gmail.com>
  • Loading branch information
david-leifker and kevin1chun committed Jun 7, 2024
1 parent 54a2d2a commit 1b6763f
Show file tree
Hide file tree
Showing 17 changed files with 1,071 additions and 626 deletions.
1 change: 1 addition & 0 deletions metadata-service/openapi-analytics-servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation project(':metadata-service:auth-impl')
implementation project(':metadata-service:factories')
implementation project(':metadata-service:openapi-servlet')
implementation project(':metadata-service:openapi-servlet:models')
implementation project(':metadata-models')

implementation externalDependency.springBoot
Expand Down
1 change: 1 addition & 0 deletions metadata-service/openapi-entity-servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation project(':metadata-service:auth-impl')
implementation project(':metadata-service:factories')
implementation project(':metadata-service:openapi-servlet')
implementation project(':metadata-service:openapi-servlet:models')
implementation project(':metadata-models')

implementation externalDependency.servletApi
Expand Down
8 changes: 8 additions & 0 deletions metadata-service/openapi-servlet/models/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ dependencies {
implementation project(':entity-registry')
implementation project(':metadata-operation-context')
implementation project(':metadata-auth:auth-api')
implementation project(':metadata-service:auth-impl')
implementation project(':metadata-io')

implementation externalDependency.springWeb
implementation(externalDependency.springDocUI) {
exclude group: 'org.springframework.boot'
}
implementation externalDependency.swaggerAnnotations

implementation externalDependency.jacksonDataBind
implementation externalDependency.httpClient
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.datahubproject.openapi.models;

import java.util.Map;

public interface GenericEntity {
Map<String, Object> getAspects();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.datahubproject.openapi.models;

public interface GenericEntityScrollResult<T extends GenericEntity> {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.datahubproject.openapi.v2.models;
package io.datahubproject.openapi.models;

import java.util.List;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
public class BatchGetUrnResponse implements Serializable {
@JsonProperty("entities")
@Schema(description = "List of entity responses")
List<GenericEntity> entities;
List<GenericEntityV2> entities;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.datahubproject.openapi.v2.models;

import io.datahubproject.openapi.models.GenericEntity;
import io.datahubproject.openapi.models.GenericEntityScrollResult;
import java.util.List;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class GenericEntityScrollResultV2<T extends GenericEntity>
implements GenericEntityScrollResult<T> {
private String scrollId;
private List<T> results;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.mxe.SystemMetadata;
import com.linkedin.util.Pair;
import io.datahubproject.openapi.models.GenericEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -23,7 +24,7 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
@AllArgsConstructor
public class GenericEntity {
public class GenericEntityV2 implements GenericEntity {
@JsonProperty("urn")
@Schema(description = "Urn of the entity")
private String urn;
Expand All @@ -32,9 +33,9 @@ public class GenericEntity {
@Schema(description = "Map of aspect name to aspect")
private Map<String, Object> aspects;

public static class GenericEntityBuilder {
public static class GenericEntityV2Builder {

public GenericEntity build(
public GenericEntityV2 build(
ObjectMapper objectMapper, Map<String, Pair<RecordTemplate, SystemMetadata>> aspects) {
Map<String, Object> jsonObjectMap =
aspects.entrySet().stream()
Expand Down Expand Up @@ -63,7 +64,7 @@ public GenericEntity build(
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

return new GenericEntity(urn, jsonObjectMap);
return new GenericEntityV2(urn, jsonObjectMap);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.datahubproject.openapi.v3.models;

import io.datahubproject.openapi.models.GenericEntity;
import io.datahubproject.openapi.models.GenericEntityScrollResult;
import java.util.List;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class GenericEntityScrollResultV3<T extends GenericEntity>
implements GenericEntityScrollResult<T> {
private String scrollId;
private List<T> entities;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.datahubproject.openapi.v3.models;

import com.datahub.util.RecordUtils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.mxe.SystemMetadata;
import com.linkedin.util.Pair;
import io.datahubproject.openapi.models.GenericEntity;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@AllArgsConstructor
public class GenericEntityV3 extends LinkedHashMap<String, Object> implements GenericEntity {

public GenericEntityV3(Map<? extends String, ?> m) {
super(m);
}

@Override
public Map<String, Object> getAspects() {
return this;
}

public static class GenericEntityV3Builder {

public GenericEntityV3 build(
ObjectMapper objectMapper,
@Nonnull Urn urn,
Map<String, Pair<RecordTemplate, SystemMetadata>> aspects) {
Map<String, Object> jsonObjectMap =
aspects.entrySet().stream()
.map(
e -> {
try {
Map<String, Object> valueMap =
Map.of(
"value",
objectMapper.readTree(
RecordUtils.toJsonString(e.getValue().getFirst())
.getBytes(StandardCharsets.UTF_8)));

if (e.getValue().getSecond() != null) {
return Map.entry(
e.getKey(),
Map.of(
"systemMetadata", e.getValue().getSecond(),
"value", valueMap.get("value")));
} else {
return Map.entry(e.getKey(), Map.of("value", valueMap.get("value")));
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

GenericEntityV3 genericEntityV3 = new GenericEntityV3();
genericEntityV3.put("urn", urn.toString());
genericEntityV3.putAll(jsonObjectMap);
return genericEntityV3;
}
}
}
Loading

0 comments on commit 1b6763f

Please sign in to comment.