Search in sources :

Example 1 with Aai20SchemaDefinition

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

the class Aai20IReferenceManipulationStrategy method attachAsComponent.

@Override
public ReferenceAndNode attachAsComponent(Document document, String name, Node component) {
    if (!(document instanceof Aai20Document))
        throw new IllegalArgumentException("Aai20Document expected.");
    Aai20Document model = (Aai20Document) document;
    if (model.components == null)
        model.components = model.createComponents();
    // TODO reduce code repetition?
    if (component instanceof Aai20Message) {
        if (model.components.messages != null && model.components.messages.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20Message definition = wrap(component, new Aai20Message(name), model);
        // TODO this should be done by vvv
        definition.attachToParent(model.components);
        model.components.addMessage(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "messages/" + name, definition);
    }
    if (component instanceof AaiSecurityScheme) {
        if (model.components.securitySchemes != null && model.components.securitySchemes.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20SecurityScheme definition = wrap(component, new Aai20SecurityScheme(name), model);
        definition.attachToParent(model.components);
        model.components.addSecurityScheme(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "securitySchemes/" + name, definition);
    }
    if (component instanceof Aai20SchemaDefinition) {
        if (model.components.schemas != null && model.components.schemas.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20SchemaDefinition definition = wrap(component, new Aai20SchemaDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addSchemaDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "schemas/" + name, definition);
    }
    if (component instanceof AaiParameter) {
        if (model.components.parameters != null && model.components.parameters.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20Parameter definition = wrap(component, new Aai20Parameter(name), model);
        definition.attachToParent(model.components);
        model.components.addParameter(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "parameters/" + name, definition);
    }
    if (component instanceof AaiCorrelationId) {
        if (model.components.correlationIds != null && model.components.correlationIds.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20CorrelationId definition = wrap(component, new Aai20CorrelationId(name), model);
        definition.attachToParent(model.components);
        model.components.addCorrelationId(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "correlationIds/" + name, definition);
    }
    // ---
    if (component instanceof AaiOperationTrait) {
        if (model.components.operationTraits != null && model.components.operationTraits.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20OperationTraitDefinition definition = wrap(component, new Aai20OperationTraitDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addOperationTraitDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "operationTraits/" + name, definition);
    }
    if (component instanceof AaiMessageTrait) {
        if (model.components.messageTraits != null && model.components.messageTraits.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20MessageTraitDefinition definition = wrap(component, new Aai20MessageTraitDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addMessageTraitDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "messageTraits/" + name, definition);
    }
    if (component instanceof AaiServerBindings) {
        if (model.components.serverBindings != null && model.components.serverBindings.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20ServerBindingsDefinition definition = wrap(component, new Aai20ServerBindingsDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addServerBindingDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "serverBindings/" + name, definition);
    }
    if (component instanceof AaiChannelBindings) {
        if (model.components.channelBindings != null && model.components.channelBindings.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20ChannelBindingsDefinition definition = wrap(component, new Aai20ChannelBindingsDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addChannelBindingDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "channelBindings/" + name, definition);
    }
    if (component instanceof AaiOperationBindings) {
        if (model.components.operationBindings != null && model.components.operationBindings.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20OperationBindingsDefinition definition = wrap(component, new Aai20OperationBindingsDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addOperationBindingDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "operationBindings/" + name, definition);
    }
    if (component instanceof AaiMessageBindings) {
        if (model.components.messageBindings != null && model.components.messageBindings.get(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Aai20MessageBindingsDefinition definition = wrap(component, new Aai20MessageBindingsDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addMessageBindingDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "messageBindings/" + name, definition);
    }
    return null;
}
Also used : AaiServerBindings(io.apicurio.datamodels.asyncapi.models.AaiServerBindings) Aai20SchemaDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20SchemaDefinition) Aai20SecurityScheme(io.apicurio.datamodels.asyncapi.v2.models.Aai20SecurityScheme) Aai20CorrelationId(io.apicurio.datamodels.asyncapi.v2.models.Aai20CorrelationId) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20OperationBindingsDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20OperationBindingsDefinition) AaiOperationBindings(io.apicurio.datamodels.asyncapi.models.AaiOperationBindings) Aai20Parameter(io.apicurio.datamodels.asyncapi.v2.models.Aai20Parameter) AaiParameter(io.apicurio.datamodels.asyncapi.models.AaiParameter) Aai20MessageTraitDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20MessageTraitDefinition) AaiSecurityScheme(io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme) Aai20ServerBindingsDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20ServerBindingsDefinition) AaiMessageTrait(io.apicurio.datamodels.asyncapi.models.AaiMessageTrait) AaiChannelBindings(io.apicurio.datamodels.asyncapi.models.AaiChannelBindings) AaiOperationTrait(io.apicurio.datamodels.asyncapi.models.AaiOperationTrait) Aai20ChannelBindingsDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20ChannelBindingsDefinition) AaiMessageBindings(io.apicurio.datamodels.asyncapi.models.AaiMessageBindings) Aai20MessageBindingsDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20MessageBindingsDefinition) Aai20Message(io.apicurio.datamodels.asyncapi.v2.models.Aai20Message) Aai20OperationTraitDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20OperationTraitDefinition) AaiCorrelationId(io.apicurio.datamodels.asyncapi.models.AaiCorrelationId)

Example 2 with Aai20SchemaDefinition

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

the class Aai20IReferenceManipulationStrategy method removeComponent.

@Override
public boolean removeComponent(Document document, String name) {
    if (document.getDocumentType() != DocumentType.asyncapi2) {
        throw new IllegalArgumentException("Aai20Document expected.");
    }
    Aai20Document model = (Aai20Document) document;
    // Some components do not implement IDefinition, have to use INamed.
    // See also .Aai20IReferenceManipulationStrategy#getComponentName(Document, Node)
    // Does not implement IDefinition
    INamed removed = model.components.messages.remove(name);
    if (removed != null)
        return true;
    removed = model.components.securitySchemes.remove(name);
    if (removed != null)
        return true;
    removed = (Aai20SchemaDefinition) model.components.schemas.remove(name);
    if (removed != null)
        return true;
    // Does not implement IDefinition
    removed = model.components.parameters.remove(name);
    if (removed != null)
        return true;
    // Does not implement IDefinition
    removed = model.components.correlationIds.remove(name);
    if (removed != null)
        return true;
    removed = model.components.operationTraits.remove(name);
    if (removed != null)
        return true;
    removed = model.components.messageTraits.remove(name);
    if (removed != null)
        return true;
    removed = model.components.serverBindings.remove(name);
    if (removed != null)
        return true;
    removed = model.components.channelBindings.remove(name);
    if (removed != null)
        return true;
    removed = model.components.operationBindings.remove(name);
    if (removed != null)
        return true;
    return model.components.messageBindings.remove(name) != null;
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) INamed(io.apicurio.datamodels.core.models.common.INamed)

Example 3 with Aai20SchemaDefinition

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

the class AaiComponents method createSchemaDefinition.

/**
 * Creates a schema definition.
 * @param name
 */
public Aai20SchemaDefinition createSchemaDefinition(String name) {
    Aai20SchemaDefinition rval = new Aai20SchemaDefinition(name);
    rval._ownerDocument = this._ownerDocument;
    rval._parent = this;
    return rval;
}
Also used : Aai20SchemaDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20SchemaDefinition)

Example 4 with Aai20SchemaDefinition

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

the class ReplaceSchemaDefinitionCommand_Aai20 method readNode.

/**
 * @see ReplaceNodeCommand#readNode(Document, Object)
 */
@Override
protected Aai20SchemaDefinition readNode(Document doc, Object node) {
    Aai20Document doc20 = (Aai20Document) doc;
    Aai20SchemaDefinition definition = doc20.components.createSchemaDefinition(this._defName);
    Library.readNode(node, definition);
    return definition;
}
Also used : Aai20SchemaDefinition(io.apicurio.datamodels.asyncapi.v2.models.Aai20SchemaDefinition) Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)

Example 5 with Aai20SchemaDefinition

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

the class ReplaceSchemaDefinitionCommand_Aai20 method removeNode.

/**
 * @see ReplaceNodeCommand#removeNode(Document, io.apicurio.datamodels.core.models.Node)
 */
@Override
protected void removeNode(Document doc, Aai20SchemaDefinition node) {
    Aai20Document doc20 = (Aai20Document) doc;
    doc20.components.removeSchemaDefinition(node.getName());
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)

Aggregations

Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)8 Aai20SchemaDefinition (io.apicurio.datamodels.asyncapi.v2.models.Aai20SchemaDefinition)6 Aai20Components (io.apicurio.datamodels.asyncapi.v2.models.Aai20Components)2 AaiChannelBindings (io.apicurio.datamodels.asyncapi.models.AaiChannelBindings)1 AaiCorrelationId (io.apicurio.datamodels.asyncapi.models.AaiCorrelationId)1 AaiMessageBindings (io.apicurio.datamodels.asyncapi.models.AaiMessageBindings)1 AaiMessageTrait (io.apicurio.datamodels.asyncapi.models.AaiMessageTrait)1 AaiOperationBindings (io.apicurio.datamodels.asyncapi.models.AaiOperationBindings)1 AaiOperationTrait (io.apicurio.datamodels.asyncapi.models.AaiOperationTrait)1 AaiParameter (io.apicurio.datamodels.asyncapi.models.AaiParameter)1 AaiSecurityScheme (io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme)1 AaiServerBindings (io.apicurio.datamodels.asyncapi.models.AaiServerBindings)1 Aai20ChannelBindingsDefinition (io.apicurio.datamodels.asyncapi.v2.models.Aai20ChannelBindingsDefinition)1 Aai20CorrelationId (io.apicurio.datamodels.asyncapi.v2.models.Aai20CorrelationId)1 Aai20Message (io.apicurio.datamodels.asyncapi.v2.models.Aai20Message)1 Aai20MessageBindingsDefinition (io.apicurio.datamodels.asyncapi.v2.models.Aai20MessageBindingsDefinition)1 Aai20MessageTraitDefinition (io.apicurio.datamodels.asyncapi.v2.models.Aai20MessageTraitDefinition)1 Aai20OperationBindingsDefinition (io.apicurio.datamodels.asyncapi.v2.models.Aai20OperationBindingsDefinition)1 Aai20OperationTraitDefinition (io.apicurio.datamodels.asyncapi.v2.models.Aai20OperationTraitDefinition)1 Aai20Parameter (io.apicurio.datamodels.asyncapi.v2.models.Aai20Parameter)1