public OpenApiReferenceProcessor(Options options) { this.options = options; this.modelVersion = options.getModelVersion(); this.contentManager = new ContentManager(modelVersion); }
/** * Request that a document be loaded and registered with the content manager. * <p> * This will be called for every document (i.e. a reference minus its fragment) * referenced in any loaded document. */ public void requestDocument(URL url) { toBeLoaded.add(cacheUrl(url)); }
private Set<LocalContent> getRequiredSecuritySchemesFromPath(LocalContent path) { JsonNode tree = path.getContent(); List<JsonNode> securityRequirementArrays = Stream .of("get", "put", "post", "delete", "options", "head", "patch", "trace") // .filter(e -> tree.has(e)) // .map(e -> tree.get(e).path("security")) // .filter(e -> e != null && !e.isMissingNode())// .collect(Collectors.toList()); return collectSecuritySchemeObjects(collectSecuritySchemeNames( securityRequirementArrays.toArray(new ArrayNode[securityRequirementArrays.size()]))); }
Content topLevel = contentManager.load(base, spec, options.isRewriteSimpleRefs()); if (topLevel.isValid()) { contentManager.localizeObjects(topLevel); } else { badRoots.add(topLevel); Content content = contentManager.load(url, null, options.isRewriteSimpleRefs()); if (content.isValid()) { contentManager.localizeObjects(content); } else { badRoots.add(content); contentManager.applyRetentionPolicy(retentionPolicy); contentManager.retainImplicitlyReferencedObjects();
if (options.isInlined(section)) { Optional<JsonNode> replacement = contentManager.getModelObject(ref); if (replacement.isPresent()) { } catch (VisitRecursionException e) { return contentManager.getLocalizedRefNode(ref); return contentManager.getLocalizedRefNode(ref);
public DefinitionProcessor(ContentManager contentManager) { this.contentManager = contentManager; this.modelVersion = contentManager.getModelVersion(); }
public JsonNode getLocalizedRefNode(Reference ref) { Optional<JsonNode> node = getModelObject(ref); if (node.isPresent()) { localizer.register(ref, node.get()); return localizer.getLocalizedRefNode(ref); } else { return ref.getBadRefNode(); } }
public void setTypeNames(boolean setMissingTitles) { for (Content contentItem : contentManager.contentItems()) { setTypeNames(contentItem, setMissingTitles); } }
private ObjectNode buildObjectTree() { ObjectNode tree = JsonNodeFactory.instance.objectNode(); while (true) { Optional<LocalContent> optItem = contentManager.getAndRemoveRetainedModelObject(); if (optItem.isPresent()) { LocalContent item = optItem.get(); JsonNode object = Util.safeDeepCopy(item.getContent()); object = inline(object, item.getRef()); OpenApiMarkers.markPosition(object, item.getPosition()); addToTree(tree, object, item.getSectionType(), item.getName()); addJsonPointers(object, item.getRef()); } else { break; } } return tree; }
public ContentLoader(ContentManager contentManager) { this.contentManager = contentManager; this.docLoader = new DocLoader(contentManager.getModelVersion()); }
public Reference getLocalizedRef(Reference ref) { Optional<JsonNode> node = getModelObject(ref); if (node.isPresent()) { localizer.register(ref, node.get()); return localizer.getLocalizedRef(ref); } else { return ref.getBadRef(); } }
/** * Recursive method to search out and handle all references in this loaded spec */ private JsonNode assembleNode(JsonNode node, Reference base, Set<Reference> visited) { if (Util.isRef(node)) { Reference ref = Reference.fromNode(node, base, contentManager.getModelVersion()); return assembleRef(ref, base, visited); } else { assembleObjectProperties(node, base, visited); assembleArrayElements(node, base, visited); return node; } }
/** * Load a JSON tree from the given URL (unless preloaded tree is provided), * register the content, and maybe rewrite "simple" refs to local object refs */ private Content loadInternal(URL url, JsonNode tree, boolean rewriteSimpleRefs) { String urlString = cacheUrl(url); Content content = contentItems.get(urlString); if (content == null) { content = new ContentLoader(this).load(url, tree, rewriteSimpleRefs); contentItems.put(urlString, content); } return content; }
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> 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(); }