- private static Schema createPostJsonSchema(final SchemaNode dataNode, final ObjectNode properties,
- final String postNodeName, final String description) {
- final Schema postSchema = new Schema();
- final ObjectNode postItemProperties;
- if (dataNode instanceof ListSchemaNode) {
- postItemProperties = createListItemProperties(properties, (ListSchemaNode) dataNode);
- } else {
- postItemProperties = properties.deepCopy();
- }
- postSchema.setType(OBJECT_TYPE);
- postSchema.setProperties(postItemProperties);
- postSchema.setTitle(postNodeName);
- postSchema.setDescription(description);
- postSchema.setXml(buildXmlParameter(dataNode));
- return postSchema;
- }
-
- private static ObjectNode createListItemProperties(final ObjectNode properties, final ListSchemaNode listNode) {
- final ObjectNode postListItemProperties = JsonNodeFactory.instance.objectNode();
- final List<QName> keyDefinition = listNode.getKeyDefinition();
- final Set<String> keys = listNode.getChildNodes().stream()
- .filter(node -> keyDefinition.contains(node.getQName()))
- .map(node -> node.getQName().getLocalName())
- .collect(Collectors.toSet());
-
- Iterator<Map.Entry<String, JsonNode>> it = properties.fields();
- while (it.hasNext()) {
- Map.Entry<String, JsonNode> property = it.next();
- if (!keys.contains(property.getKey())) {
- postListItemProperties.set(property.getKey(), property.getValue());
- }
- }
-
- return postListItemProperties;
- }
-