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

DGS-17561 Scrub refs in arrays when searching for inline tags (#59) #3275

Open
wants to merge 1 commit into
base: 7.6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -933,8 +933,13 @@ private void getInlineTaggedEntitiesRecursively(Map<SchemaEntity, Set<String>> t
Map<String, Object> defns = (Map<String, Object>) unprocessedProperties.get("definitions");
if (defns != null) {
for (Map.Entry<String, Object> entry : defns.entrySet()) {
Object rawSchema = null;
if (entry.getValue() instanceof Map) {
Map<String, Object> rawSchema = replaceRefs((Map<String, Object>) entry.getValue());
rawSchema = replaceRefs((Map<String, Object>) entry.getValue());
} else if (entry.getValue() instanceof List) {
rawSchema = replaceRefs((List<Object>) entry.getValue());
}
if (rawSchema != null) {
JsonNode jsonNode = objectMapper.valueToTree(rawSchema);
JsonSchema jsonSchema = new JsonSchema(jsonNode);
getInlineTaggedEntitiesRecursively(
Expand Down Expand Up @@ -962,6 +967,22 @@ private Map<String, Object> replaceRefs(Map<String, Object> defs) {
for (Map.Entry<String, Object> entry : result.entrySet()) {
if (entry.getValue() instanceof Map) {
entry.setValue(replaceRefs((Map<String, Object>) entry.getValue()));
} else if (entry.getValue() instanceof List) {
entry.setValue(replaceRefs((List<Object>) entry.getValue()));
}
}
return result;
}

private List<Object> replaceRefs(List<Object> items) {
List<Object> result = new ArrayList<>();
for (Object item : items) {
if (item instanceof Map) {
result.add(replaceRefs((Map<String, Object>) item));
} else if (item instanceof List) {
result.add(replaceRefs((List<Object>) item));
} else {
result.add(item);
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,88 @@ public void testBasicAddAndRemoveTags() {
assertEquals(ImmutableSet.of("EXTERNAL"), resultSchema.tags());
}

@Test
public void testInlineTagsForRefInArray() {
String schemaString = "{\n"
+ " \"definitions\": {\n"
+ " \"MetricData\": {\n"
+ " \"additionalProperties\": false,\n"
+ " \"properties\": {\n"
+ " \"name\": {\n"
+ " \"oneOf\": [\n"
+ " {\n"
+ " \"title\": \"Not included\",\n"
+ " \"type\": \"null\"\n"
+ " },\n"
+ " {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " ],\n"
+ " \"confluent:tags\": [ \"PII\" ]\n"
+ " },\n"
+ " \"value\": {\n"
+ " \"oneOf\": [\n"
+ " {\n"
+ " \"title\": \"Not included\",\n"
+ " \"type\": \"null\"\n"
+ " },\n"
+ " {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " },\n"
+ " \"type\": \"object\"\n"
+ " },\n"
+ " \"SensorData\": {\n"
+ " \"additionalProperties\": false,\n"
+ " \"properties\": {\n"
+ " \"metricData\": {\n"
+ " \"oneOf\": [\n"
+ " {\n"
+ " \"title\": \"Not included\",\n"
+ " \"type\": \"null\"\n"
+ " },\n"
+ " {\n"
+ " \"items\": {\n"
+ " \"$ref\": \"#/definitions/MetricData\"\n"
+ " },\n"
+ " \"type\": \"array\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " },\n"
+ " \"type\": \"object\"\n"
+ " }\n"
+ " },\n"
+ " \"properties\": {\n"
+ " \"sensorData\": {\n"
+ " \"oneOf\": [\n"
+ " {\n"
+ " \"title\": \"Not included\",\n"
+ " \"type\": \"null\"\n"
+ " },\n"
+ " {\n"
+ " \"items\": {\n"
+ " \"$ref\": \"#/definitions/SensorData\"\n"
+ " },\n"
+ " \"type\": \"array\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " },\n"
+ " \"type\": \"object\"\n"
+ "}\n";
JsonSchema schema = new JsonSchema(schemaString);

Map<SchemaEntity, Set<String>> tags = new HashMap<>();
tags.put(new SchemaEntity("object.definitions.object.name",
SchemaEntity.EntityType.SR_FIELD),
Collections.singleton("PII"));
Map<SchemaEntity, Set<String>> expectedTags = new HashMap<>(tags);
assertEquals(expectedTags, schema.inlineTaggedEntities());
}

@Test
public void testAddTagsToConditional() {
String schemaString = "{\n" +
Expand Down