Skip to content

Commit

Permalink
JobTracker reports enum values (#12885)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgao authored May 17, 2022
1 parent 6bbd715 commit abc038e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ protected static Map<String, Object> configToMetadata(final String jsonPath, fin
* array) then returns a map of {null: toMetadataValue(config)}.
*/
private static Map<String, Object> configToMetadata(final JsonNode config, final JsonNode schema) {
if (schema.hasNonNull("const")) {
// If this schema is a const, then just dump it into a map:
if (schema.hasNonNull("const") || schema.hasNonNull("enum")) {
// If this schema is a const or an enum, then just dump it into a map:
// * If it's an object, flatten it
// * Otherwise, do some basic conversions to value-ish data.
// It would be a weird thing to declare const: null, but in that case we don't want to report null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
}
},
"const_null": null,
"enum_string": "foo",
"additionalPropertiesUnset": {
"foo": "bar"
},
Expand All @@ -27,5 +28,6 @@
},
"additionalPropertiesConst": {
"foo": 42
}
},
"additionalPropertiesEnumString": "foo"
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"const_null": {
"const": null
},
"enum_string": {
"type": "string",
"enum": ["foo", "bar"]
},
"additionalPropertiesUnset": {
"type": "object"
},
Expand All @@ -62,6 +66,10 @@
"additionalProperties": {
"const": 42
}
},
"additionalPropertiesEnumString": {
"type": "string",
"enum": ["foo", "bar"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,12 @@ void testConfigToMetadata() throws IOException {
.put(JobTracker.CONFIG + ".const_object.sub_key", "bar")
.put(JobTracker.CONFIG + ".const_object.sub_array", "[1,2,3]")
.put(JobTracker.CONFIG + ".const_object.sub_object.sub_sub_key", "baz")
.put(JobTracker.CONFIG + ".enum_string", "foo")
.put(JobTracker.CONFIG + ".additionalPropertiesUnset.foo", JobTracker.SET)
.put(JobTracker.CONFIG + ".additionalPropertiesBoolean.foo", JobTracker.SET)
.put(JobTracker.CONFIG + ".additionalPropertiesSchema.foo", JobTracker.SET)
.put(JobTracker.CONFIG + ".additionalPropertiesConst.foo", 42)
.put(JobTracker.CONFIG + ".additionalPropertiesEnumString", "foo")
.build();

final Map<String, Object> actual = JobTracker.configToMetadata(JobTracker.CONFIG, config, schema);
Expand Down

0 comments on commit abc038e

Please sign in to comment.