Package io.apicurio.datamodels
Class Library
- java.lang.Object
-
- io.apicurio.datamodels.Library
-
public class Library extends Object
The most common entry points into using the data models library. Provides convenience methods for performing common actions such as i/o, visiting, and validation.- Author:
- eric.wittmann@gmail.com, jsenko@redhat.com
-
-
Constructor Summary
Constructors Constructor Description Library()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddReferenceResolver(IReferenceResolver resolver)Adds a reference resolver to the library.static DocumentcloneDocument(Document source)Clones the given document by serializing it to a JS object, and then re-parsing it.static DocumentcloneDocument(Document source, UnaryOperator<com.fasterxml.jackson.databind.node.ObjectNode> transformer)Clones the given document by serializing it to a JS object, and then re-parsing it.static DocumentcreateDocument(ModelType type)Creates a new, empty document of the given type.static NodePathcreateNodePath(Node node)Called to create a node path for a given data model node.static DocumentdereferenceDocument(Document source)Dereferences a document - this will take all external references ($ref) found in the document and pull them into this document.static DocumentdereferenceDocument(Document source, boolean strict)Dereferences a document - this will take all external references ($ref) found in the document and pull them into this document.static DocumentdereferenceDocument(Document source, IReferenceResolver resolver, boolean strict)Dereferences a document - this will take all external references ($ref) found in the document and pull them into this document.static NodePathparseNodePath(String path)Called to create a node path instance for a stringified node path.static DocumentreadDocument(com.fasterxml.jackson.databind.node.ObjectNode json)Reads an entire document from JSON data.static DocumentreadDocumentFromJSONString(String jsonString)Reads an entire document from a JSON formatted string.static NodereadNode(com.fasterxml.jackson.databind.node.ObjectNode json, Node node)Call this to do a "partial read" on a given node.static voidremoveReferenceResolver(IReferenceResolver resolver)static NoderesolveNodePath(NodePath nodePath, Document doc)Resolves the given node path relative to a root document.static DocumenttransformDocument(Document source, ModelType toType)Transforms from older versions of specs to newer versions.static List<ValidationProblem>validate(Node node, IValidationSeverityRegistry severityRegistry)Called to validate a data model node.static voidvisitNode(Node node, Visitor visitor)Visits a node with the given visitor.static voidvisitTree(Node node, Visitor visitor, TraverserDirection direction)Visits an entire tree (either up or down).static com.fasterxml.jackson.databind.node.ObjectNodewriteDocument(Document document)Called to serialize a given data model node to a JSON object.static StringwriteDocumentToJSONString(Document document)Called to serialize a given data model to a JSON formatted string.static com.fasterxml.jackson.databind.node.ObjectNodewriteNode(Node node)Called to serialize a given data model node to a JSON object.static StringwriteNodeToString(Node node)Called to serialize a given data model node to a JSON string.
-
-
-
Method Detail
-
addReferenceResolver
public static void addReferenceResolver(IReferenceResolver resolver)
Adds a reference resolver to the library. The resolver will be used whenever the library needs to resolve a $ref reference.- Parameters:
resolver-
-
removeReferenceResolver
public static void removeReferenceResolver(IReferenceResolver resolver)
-
createDocument
public static Document createDocument(ModelType type)
Creates a new, empty document of the given type.- Parameters:
type-
-
readDocument
public static Document readDocument(com.fasterxml.jackson.databind.node.ObjectNode json)
Reads an entire document from JSON data. The JSON data (already parsed, not in string format) is read as a data modelDocumentand returned.- Parameters:
json-
-
readDocumentFromJSONString
public static Document readDocumentFromJSONString(String jsonString)
Reads an entire document from a JSON formatted string. This will parse the given string into JSON data and then call Library.readDocument.- Parameters:
jsonString-
-
writeDocument
public static com.fasterxml.jackson.databind.node.ObjectNode writeDocument(Document document)
Called to serialize a given data model node to a JSON object.- Parameters:
document-
-
writeDocumentToJSONString
public static String writeDocumentToJSONString(Document document)
Called to serialize a given data model to a JSON formatted string.- Parameters:
document-
-
readNode
public static Node readNode(com.fasterxml.jackson.databind.node.ObjectNode json, Node node)
Call this to do a "partial read" on a given node. You must pass the JSON data for the node type and an empty instance of the node class. For example, you could read just an Operation by passing the JSON data for the operation along with an instance of e.g.OpenApi30Operationand this will read the data and store it in the instance.- Parameters:
json-node-
-
writeNode
public static com.fasterxml.jackson.databind.node.ObjectNode writeNode(Node node)
Called to serialize a given data model node to a JSON object.- Parameters:
node-
-
writeNodeToString
public static String writeNodeToString(Node node)
Called to serialize a given data model node to a JSON string.- Parameters:
node-
-
visitNode
public static void visitNode(Node node, Visitor visitor)
Visits a node with the given visitor. Convenience method really - you could just call node.accept(visitor) ... and probably should.- Parameters:
node-visitor-
-
visitTree
public static void visitTree(Node node, Visitor visitor, TraverserDirection direction)
Visits an entire tree (either up or down).- Parameters:
node-visitor-direction-
-
createNodePath
public static NodePath createNodePath(Node node)
Called to create a node path for a given data model node.- Parameters:
node-
-
parseNodePath
public static NodePath parseNodePath(String path)
Called to create a node path instance for a stringified node path.- Parameters:
path-
-
resolveNodePath
public static Node resolveNodePath(NodePath nodePath, Document doc)
Resolves the given node path relative to a root document.- Parameters:
nodePath-doc-
-
transformDocument
public static Document transformDocument(Document source, ModelType toType)
Transforms from older versions of specs to newer versions. Currently supports: - OpenAPI 2.0 document into a 3.0 document - OpenAPI 3.0 document into a 3.1 document - AsyncAPI early version to any later version- Parameters:
source-toType-
-
cloneDocument
public static Document cloneDocument(Document source)
Clones the given document by serializing it to a JS object, and then re-parsing it.- Parameters:
source-
-
cloneDocument
public static Document cloneDocument(Document source, UnaryOperator<com.fasterxml.jackson.databind.node.ObjectNode> transformer)
Clones the given document by serializing it to a JS object, and then re-parsing it.- Parameters:
source-transformer-
-
validate
public static List<ValidationProblem> validate(Node node, IValidationSeverityRegistry severityRegistry)
Called to validate a data model node. All validation rules will be evaluated and reported. The list of validation problems found during validation is returned. In addition, validation problems will be reported on the individual nodes themselves. Validation problem severity is determined by checking with the included severity registry. If the severity registry is null, a default registry is used.- Parameters:
node-severityRegistry-
-
dereferenceDocument
public static Document dereferenceDocument(Document source)
Dereferences a document - this will take all external references ($ref) found in the document and pull them into this document. It will then update any external reference to instead point to the local copy. The result is a functionally equivalent document with all resolvable external references removed.- Parameters:
source- the source document
-
dereferenceDocument
public static Document dereferenceDocument(Document source, boolean strict)
Dereferences a document - this will take all external references ($ref) found in the document and pull them into this document. It will then update any external reference to instead point to the local copy. The result is a functionally equivalent document with all resolvable external references removed.- Parameters:
source- the source documentstrict- if true, throws an exception if unresolvable references remain
-
dereferenceDocument
public static Document dereferenceDocument(Document source, IReferenceResolver resolver, boolean strict)
Dereferences a document - this will take all external references ($ref) found in the document and pull them into this document. It will then update any external reference to instead point to the local copy. The result is a functionally equivalent document with all resolvable external references removed.- Parameters:
source- the source documentresolver- a custom reference resolver to use on this dereference operationstrict- if true, throws an exception if unresolvable references remain
-
-