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