/** * Register the given object tree under the given reference, and select a name * for a local copy of that object if it ends up in the constructed spec. */ public LocalContent register(Reference ref, JsonNode node) { if (!localContentItems.containsKey(ref)) { register(new LocalContent(ref, node)); } return localContentItems.get(ref); }
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()]))); }
@Override public String toString() { return String.format("LocalContent[%s]\n", getLocalizedRefString()); } }
private String chooseLocalName() { String name = ref.getObjectName(); if (name == null) { name = "_ANON"; } String key = getSectionPath() + ":" + name; if (!itemsByLocalName.containsKey(key)) { itemsByLocalName.put(key, this); return name; } for (int i = 1;; i++) { String disambiguatedKey = key + "_" + i; if (!itemsByLocalName.containsKey(disambiguatedKey)) { itemsByLocalName.put(disambiguatedKey, this); return name + "_" + i; } } }
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; }
/** * Get a reference to the local copy of the referenced object in the constructed * spec. * <p> * Obtaining a localized reference has the side-effect of retaining the object * in the constructed spec. */ public Reference getLocalizedRef(Reference ref) { LocalContent localContent = localContentItems.get(ref); if (localContent != null) { localContent.retain(); return new Reference(localContent.getLocalizedRefString(), modelVersion); } else { return ref.getBadRef(); } }
public String getLocalizedRefString() { return "#" + getSectionPath() + "/" + name; }
private void register(LocalContent localContent) { localContentItems.put(localContent.getRef(), localContent); }
public void retainImplicitlyReferencedObjects() { for (LocalContent item : localizer.getLocalContentItems()) { if (item.isRetained()) { if (item.getSectionType() == ObjectType.PATH && item.isRetained()) { getRequiredSecuritySchemesFromPath(item).forEach(LocalContent::retain); } } else if (item.getSectionType() == ObjectType.SECURITY_SCHEME) { item.retain(); } } }
public LocalContent(Reference ref, JsonNode node) { this.ref = ref; this.content = node; this.name = chooseLocalName(); this.position = ContentLocalizer.this.nextPositionValue++; }