Search in sources :

Example 1 with INamed

use of io.apicurio.datamodels.core.models.common.INamed 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 2 with INamed

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

the class IoTestRunner method cloneNode.

static Node cloneNode(Node node) {
    Constructor<? extends Node> constructor;
    Node clonedNode = null;
    try {
        if (node instanceof INamed) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((INamed) node).getName());
        } else if (node instanceof OasPathItem) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((OasPathItem) node).getPath());
        } else if (node instanceof Operation) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((Operation) node).getType());
        } else if (node instanceof Oas20PropertySchema) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((Oas20PropertySchema) node).getPropertyName());
        } else if (node instanceof Oas30PropertySchema) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((Oas30PropertySchema) node).getPropertyName());
        } else if (node instanceof ServerVariable) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((ServerVariable) node).getName());
        } else {
            constructor = node.getClass().getConstructor();
            clonedNode = constructor.newInstance();
        }
    } catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        System.err.println("Skipping partial I/O for: " + node.getClass().getSimpleName());
    }
    if (clonedNode != null) {
        clonedNode._parent = node._parent;
        clonedNode._ownerDocument = node.ownerDocument();
        if (clonedNode instanceof Document) {
            clonedNode._ownerDocument = (Document) clonedNode;
        }
    }
    return clonedNode;
}
Also used : Node(io.apicurio.datamodels.core.models.Node) Operation(io.apicurio.datamodels.core.models.common.Operation) Document(io.apicurio.datamodels.core.models.Document) ServerVariable(io.apicurio.datamodels.core.models.common.ServerVariable) Oas20PropertySchema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema.Oas20PropertySchema) InvocationTargetException(java.lang.reflect.InvocationTargetException) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Oas30PropertySchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30PropertySchema) INamed(io.apicurio.datamodels.core.models.common.INamed)

Aggregations

INamed (io.apicurio.datamodels.core.models.common.INamed)2 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 Document (io.apicurio.datamodels.core.models.Document)1 Node (io.apicurio.datamodels.core.models.Node)1 Operation (io.apicurio.datamodels.core.models.common.Operation)1 ServerVariable (io.apicurio.datamodels.core.models.common.ServerVariable)1 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)1 Oas20PropertySchema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema.Oas20PropertySchema)1 Oas30PropertySchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30PropertySchema)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1