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;
}
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;
}
Aggregations