Search in sources :

Example 1 with Aai20Components

use of io.apicurio.datamodels.asyncapi.v2.models.Aai20Components in project apicurio-data-models by Apicurio.

the class NewMessageDefinitionCommand method execute.

@Override
public void execute(Document document) {
    LoggerCompat.info("[NewMessageDefinitionCommand] Executing.");
    Aai20Document doc20 = (Aai20Document) document;
    if (this.isNullOrUndefined(doc20.components)) {
        doc20.components = doc20.createComponents();
        this._nullComponents = true;
    }
    this._nullComponents = false;
    Aai20Components components = (Aai20Components) doc20.components;
    if (this.isNullOrUndefined(components.getMessageTraitDefinition(_newName))) {
        Aai20NodeFactory factory = new Aai20NodeFactory();
        AaiMessage msgDef = factory.createMessage(components, _newName);
        if (!this.isNullOrUndefined(_newDescription != null)) {
            msgDef.description = _newDescription;
        }
        components.addMessage(_newName, msgDef);
        this._defExisted = false;
    } else {
        this._defExisted = true;
    }
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20NodeFactory(io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory) Aai20Components(io.apicurio.datamodels.asyncapi.v2.models.Aai20Components) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 2 with Aai20Components

use of io.apicurio.datamodels.asyncapi.v2.models.Aai20Components in project apicurio-data-models by Apicurio.

the class AddSchemaDefinitionCommand_Aai20 method undo.

@Override
public void undo(Document document) {
    LoggerCompat.info("[AddSchemaDefinitionCommand_Aai20] Reverting.");
    if (this._defExisted) {
        return;
    }
    Aai20Document doc = (Aai20Document) document;
    if (this._nullComponents) {
        doc.components = null;
    }
    ((Aai20Components) doc.components).removeSchemaDefinition(this._newDefinitionName);
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20Components(io.apicurio.datamodels.asyncapi.v2.models.Aai20Components)

Example 3 with Aai20Components

use of io.apicurio.datamodels.asyncapi.v2.models.Aai20Components in project apicurio-data-models by Apicurio.

the class Aai20Traverser method visitComponents.

@Override
public void visitComponents(Components node) {
    Aai20Components components = (Aai20Components) node;
    node.accept(visitor);
    this.traverseCollection(components.getSchemaDefinitions());
    this.traverseCollection(components.getMessagesList());
    this.traverseCollection(components.getSecuritySchemesList());
    this.traverseCollection(components.getParametersList());
    this.traverseCollection(components.getCorrelationIdsList());
    this.traverseCollection(components.getMessageTraitDefinitionsList());
    this.traverseCollection(components.getOperationTraitDefinitionsList());
    this.traverseCollection(components.getServerBindingsDefinitionList());
    this.traverseCollection(components.getChannelBindingsDefinitionList());
    this.traverseCollection(components.getOperationBindingsDefinitionList());
    this.traverseCollection(components.getMessageBindingsDefinitionList());
    this.traverseExtensions(node);
    this.traverseValidationProblems(node);
}
Also used : Aai20Components(io.apicurio.datamodels.asyncapi.v2.models.Aai20Components)

Example 4 with Aai20Components

use of io.apicurio.datamodels.asyncapi.v2.models.Aai20Components in project apicurio-data-models by Apicurio.

the class NewSchemaDefinitionCommand_Aai20 method undo.

@Override
public void undo(Document document) {
    LoggerCompat.info("[NewSchemaDefinitionCommand_Aai20] Reverting.");
    Aai20Document doc20 = (Aai20Document) document;
    if (this._nullComponents) {
        doc20.components = null;
    }
    if (this._defExisted) {
        return;
    }
    ((Aai20Components) doc20.components).removeSchemaDefinition(this._newDefinitionName);
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20Components(io.apicurio.datamodels.asyncapi.v2.models.Aai20Components)

Example 5 with Aai20Components

use of io.apicurio.datamodels.asyncapi.v2.models.Aai20Components in project apicurio-data-models by Apicurio.

the class AaiSchemaFactory method createSchemaDefinitionFromExample.

/**
 * Creates a new definition schema from a given example.  This method will analyze the example
 * object and create a new schema object that represents the example.  Note that this method
 * does not support arbitrarily complicated examples, and should be used as a starting point
 * for a schema, not a canonical one.
 * @param document
 * @param name
 * @param example
 */
public static IDefinition createSchemaDefinitionFromExample(AaiDocument document, String name, Object example) {
    AaiSchema schema;
    if (document.getDocumentType() == DocumentType.asyncapi2) {
        Aai20Document doc = (Aai20Document) document;
        if (NodeCompat.isNullOrUndefined(doc.components)) {
            doc.components = doc.createComponents();
        }
        schema = ((Aai20Components) doc.components).createSchemaDefinition(name);
    } else {
        throw new RuntimeException("Only AsyncAPI 2 is currently supported.");
    }
    if (JsonCompat.isString(example)) {
        example = JsonCompat.parseJSON(JsonCompat.toString(example));
    }
    resolveAll(example, schema);
    schema.title = "Root Type for " + name;
    schema.description = "The root of the " + name + " type's schema.";
    return (IDefinition) schema;
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema) IDefinition(io.apicurio.datamodels.core.models.common.IDefinition)

Aggregations

Aai20Components (io.apicurio.datamodels.asyncapi.v2.models.Aai20Components)9 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)9 Aai20NodeFactory (io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory)3 Aai20SchemaDefinition (io.apicurio.datamodels.asyncapi.v2.models.Aai20SchemaDefinition)2 AaiMessage (io.apicurio.datamodels.asyncapi.models.AaiMessage)1 AaiMessageTraitDefinition (io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition)1 AaiOperationTraitDefinition (io.apicurio.datamodels.asyncapi.models.AaiOperationTraitDefinition)1 AaiSchema (io.apicurio.datamodels.asyncapi.models.AaiSchema)1 Node (io.apicurio.datamodels.core.models.Node)1 IDefinition (io.apicurio.datamodels.core.models.common.IDefinition)1 LinkedHashMap (java.util.LinkedHashMap)1