Search in sources :

Example 1 with DataModelReader

use of io.apicurio.datamodels.core.io.DataModelReader in project apicurio-data-models by Apicurio.

the class Library method readNode.

/**
 * 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 property 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.
 * {@link Oas30Operation} and this will read the data and store it in the instance.
 * @param json
 * @param node
 */
public static Node readNode(Object json, Node node) {
    // Clone the input because the reader is destructive to the source data.
    Object clonedJson = JsonCompat.clone(json);
    DocumentType type = node.ownerDocument().getDocumentType();
    DataModelReader reader = VisitorFactory.createDataModelReader(type);
    DataModelReaderDispatcher dispatcher = VisitorFactory.createDataModelReaderDispatcher(type, clonedJson, reader);
    Library.visitNode(node, dispatcher);
    return node;
}
Also used : DocumentType(io.apicurio.datamodels.core.models.DocumentType) DataModelReaderDispatcher(io.apicurio.datamodels.core.io.DataModelReaderDispatcher) DataModelReader(io.apicurio.datamodels.core.io.DataModelReader)

Example 2 with DataModelReader

use of io.apicurio.datamodels.core.io.DataModelReader in project apicurio-data-models by Apicurio.

the class Library method readDocument.

/**
 * Reads an entire document from JSON data.  The JSON data (already parsed, not in string format) is
 * read as a data model {@link Document} and returned.
 * @param json
 */
public static Document readDocument(Object json) {
    // Clone the input because the reader is destructive to the source data.
    Object clonedJson = JsonCompat.clone(json);
    DocumentType type = discoverDocumentType(clonedJson);
    DataModelReader reader = VisitorFactory.createDataModelReader(type);
    Document document = DocumentFactory.create(type);
    reader.readDocument(clonedJson, document);
    return document;
}
Also used : DocumentType(io.apicurio.datamodels.core.models.DocumentType) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Document(io.apicurio.datamodels.core.models.Document) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) DataModelReader(io.apicurio.datamodels.core.io.DataModelReader)

Aggregations

DataModelReader (io.apicurio.datamodels.core.io.DataModelReader)2 DocumentType (io.apicurio.datamodels.core.models.DocumentType)2 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 DataModelReaderDispatcher (io.apicurio.datamodels.core.io.DataModelReaderDispatcher)1 Document (io.apicurio.datamodels.core.models.Document)1 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)1 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)1