/** * Create a content object for a URL that cannot be loaded. */ public static Content getUnloadableContentItem(Reference reference, String unloadableReason) { return new Content(reference, null, unloadableReason); }
private Content assemble(JsonNode tree, Reference base) { Set<Reference> visited = new HashSet<Reference>(); JsonNode assembly = assembleNode(tree, base, visited); return Content.getContentItem(base, assembly); }
public void localizeObjectsInSection(Content content, ObjectType section) { for (String objectName : content.getObjectNames(section)) { Reference ref = content.getObjectReference(section, objectName); JsonNode obj = content.getObject(section, objectName).get(); localizer.register(ref, obj); } }
private void setTypeNames(Content contentItem, boolean setMissingTitles) { ObjectType section = modelVersion == ObjectType.SWAGGER_MODEL_VERSION ? ObjectType.DEFINITION : modelVersion == ObjectType.OPENAPI3_MODEL_VERSION ? ObjectType.SCHEMA : null; if (section != null) { for (String name : contentItem.getObjectNames(section)) { ObjectNode schema = (ObjectNode) contentItem.getObject(section, name).get(); OpenApiMarkers.markTypeName(schema, name); if (setMissingTitles && !schema.has("title")) { schema.put("title", name); } } } } }
if (topLevel.isValid()) { if (content.isValid()) { contentManager.localizeObjects(content); } else { .map(root -> String.format("%s: %s", root.getRefString(), root.getUnresolvedReason())) .collect(Collectors.joining("\n"))); addNonObjects(tree, topLevel.getTree());
if (content.isValid()) { try { tree = ref.getFragment() != null ? content.getTree().at(ref.getFragment()) : content.getTree(); if (tree.isMissingNode()) { invalidReason = "Ref fragment does not address a value in the retrived document"; invalidReason = content.getUnresolvedReason();
public Content load(URL url) { Reference ref = new Reference(url, modelVersion); Content doc = docCache.get(ref); if (doc == null) { try { String text = readFromUrl(url); JsonNode root = toJson(text, url, modelVersion); doc = Content.getContentItem(ref, root); } catch (LoadException e) { doc = Content.getUnloadableContentItem(ref, e.getMessage()); } } docCache.put(ref, doc); return doc; }
public Content load(URL url, JsonNode tree, boolean rewriteSimpleRefs) { this.base = new Reference(url, contentManager.getModelVersion()); if (tree == null) { Content content = docLoader.load(url); if (content.isValid()) { tree = content.getTree(); } else { return content; } } if (rewriteSimpleRefs) { SimpleRefFixer.fixSimpleRefs(tree); } return assemble(tree, base); }
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(); }
public RetentionPolicy(Content topContent, Options options) { this.topHasPaths = topContent.getObjectNames(ObjectType.PATH).iterator().hasNext(); this.options = options; }
public Optional<JsonNode> getModelObject(Reference ref) { if (ref.isModelObjectRef()) { String urlString = cacheUrl(ref.getUrl()); Content content = contentItems.get(urlString); if (content != null) { return content.getObject(ref.getSection(), ref.getObjectName()); } } return Optional.empty(); }
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 retainObjectsInSection(Content content, ObjectType section) { for (String objectName : content.getObjectNames(section)) { Reference ref = content.getObjectReference(section, objectName); JsonNode obj = content.getObject(section, objectName).get(); localizer.register(ref, obj).retain(); } }
/** * Wrap loaded content in a Content object */ public static Content getContentItem(Reference reference, JsonNode content) { return new Content(reference, content, null); }