public Optional<JsonNode> getObject(ObjectType section, String name) { if (isValid()) { JsonNode sectionNode = section.getFromNode(tree, version); return sectionNode.has(name) ? Optional.of(sectionNode.get(name)) : Optional.<JsonNode>empty(); } return Optional.empty(); }
private void addToTree(ObjectNode tree, JsonNode object, ObjectType sectionType, String objectName) { if (sectionType.getFromNode(tree, modelVersion).isMissingNode()) { sectionType.setInNode(tree, tree.objectNode(), modelVersion); } ObjectNode section = (ObjectNode) sectionType.getFromNode(tree, modelVersion); section.set(objectName, object); }
private void addPathsIfNeeded(JsonNode tree) { if (ObjectType.PATH.getFromNode(tree, modelVersion).isMissingNode()) { ObjectType.PATH.setInNode(tree, JsonNodeFactory.instance.objectNode(), modelVersion); } } }
public Iterable<String> getObjectNames(ObjectType section) { if (isValid()) { JsonNode sectionNode = section.getFromNode(tree, version); if (sectionNode instanceof ObjectNode) { return Util.iterable(((ObjectNode) sectionNode).fieldNames()); } } return Collections.emptyList(); } }
private void markPositions(ObjectNode tree) { for (ObjectType sectionType : ObjectType.getTypesForVersion(modelVersion)) { JsonNode section = sectionType.getFromNode(tree, modelVersion); if (section != null) { markPositionsInSection(section); if (sectionType == ObjectType.PATH) { for (Entry<String, JsonNode> path : Util.iterable(section.fields())) { markPositionsInPath(path.getValue()); } } } } }
private void sort(ObjectNode tree) { for (ObjectType sectionType : ObjectType.getTypesForVersion(modelVersion)) { JsonNode section = sectionType.getFromNode(tree, modelVersion); if (!section.isMissingNode()) { sortSection(section); if (sectionType == ObjectType.PATH) { for (Entry<String, JsonNode> path : Util.iterable(section.fields())) { sortInPath(path.getValue()); } } } } }
private void reorderTree(JsonNode tree) { for (ObjectType sectionType : ObjectType.getTypesForVersion(modelVersion)) { JsonNode section = sectionType.getFromNode(tree, modelVersion); if (!section.isMissingNode()) { reorderPropertiesInObject((ObjectNode) section); if (sectionType == ObjectType.PATH) { for (Entry<String, JsonNode> path : Util.iterable(section.fields())) { reorderInPath((ObjectNode) path.getValue()); } } } } }
private void addNonObjects(ObjectNode objectTree, JsonNode spec) { for (Entry<String, JsonNode> field : Util.iterable(spec.fields())) { String fieldName = field.getKey(); // Note: the following test assumes that the top-level property on the path to // any container of model // objects is itself an object container or is a JSON object that only contains // object containers. This // avoids what would be a much trickier test before copying a value from the // top-level source model to the // result model. if (!ObjectType.isObjectContainerPrefix(fieldName, modelVersion)) { objectTree.set(fieldName, Util.safeDeepCopy(field.getValue())); } // // That assumption is NOT valid for v3 models, because the `components` property // can contain vendor // extensions. We fudge it by separately copying vendor extensions appearing in // that property. if (modelVersion == OPENAPI3_MODEL_VERSION && fieldName.equals("components")) { addComponentExtensions(objectTree, spec); } } // TODO V2? if (ObjectType.PATH.getFromNode(objectTree, modelVersion).isMissingNode()) { ObjectType.PATH.setInNode(objectTree, JsonNodeFactory.instance.objectNode(), modelVersion); } }