Skip to content

Commit

Permalink
update boolean schema support
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Nov 15, 2022
1 parent 92f36c4 commit 98a3e70
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public Schema deserialize(JsonParser jp, DeserializationContext ctxt)
schema = deserializeJsonSchema(node);
return schema;
}

if (node.isBoolean()) {
return new Schema().booleanSchemaValue(node.booleanValue());
}

List<String> composed = Arrays.asList("allOf", "anyOf", "oneOf");
for (String field: composed) {
Expand Down Expand Up @@ -98,23 +100,22 @@ private Schema deserializeObjectSchema(JsonNode node) {
JsonNode additionalProperties = node.get("additionalProperties");
Schema schema = null;
if (additionalProperties != null) {
// try first to convert to Schema, if it fails it must be a boolean
try {
Schema innerSchema = Json.mapper().convertValue(additionalProperties, Schema.class);
((ObjectNode)node).remove("additionalProperties");
MapSchema ms = Json.mapper().convertValue(node, MapSchema.class);
ms.setAdditionalProperties(innerSchema);
schema = ms;
} catch (Exception e) {
if (additionalProperties.isBoolean()) {
Boolean additionalPropsBoolean = Json.mapper().convertValue(additionalProperties, Boolean.class);
((ObjectNode)node).remove("additionalProperties");
if (additionalPropsBoolean) {
schema = Json.mapper().convertValue(node, MapSchema.class);
} else {
schema = Json.mapper().convertValue(node, ObjectSchema.class);
}
schema.setAdditionalProperties(additionalPropsBoolean);
} else {
Schema innerSchema = Json.mapper().convertValue(additionalProperties, Schema.class);
((ObjectNode)node).remove("additionalProperties");
MapSchema ms = Json.mapper().convertValue(node, MapSchema.class);
ms.setAdditionalProperties(innerSchema);
schema = ms;
}

} else {
schema = Json.mapper().convertValue(node, ObjectSchema.class);
}
Expand Down

0 comments on commit 98a3e70

Please sign in to comment.