use of io.apicurio.datamodels.asyncapi.models.AaiCorrelationId 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;
}
use of io.apicurio.datamodels.asyncapi.models.AaiCorrelationId in project apicurio-data-models by Apicurio.
the class AaiDataModelReader method readMessageBase.
public void readMessageBase(Object json, AaiMessageBase node) {
// headers
Object jsonHeaders = JsonCompat.consumeProperty(json, Constants.PROP_HEADERS);
if (jsonHeaders != null) {
AaiHeaderItem headerModel = nodeFactory.createHeaderItem(node);
this.readHeaderItem(jsonHeaders, headerModel);
node.headers = headerModel;
}
// correlationId
Object jsonCI = JsonCompat.consumeProperty(json, Constants.PROP_CORRELATION_ID);
if (jsonCI != null) {
AaiCorrelationId value = nodeFactory.createCorrelationId(node, null);
this.readCorrelationId(jsonCI, value);
node.correlationId = value;
}
// String properties
node.schemaFormat = JsonCompat.consumePropertyString(json, Constants.PROP_SCHEMA_FORMAT);
node.contentType = JsonCompat.consumePropertyString(json, Constants.PROP_CONTENT_TYPE);
node.name = JsonCompat.consumePropertyString(json, Constants.PROP_NAME);
node.title = JsonCompat.consumePropertyString(json, Constants.PROP_TITLE);
node.summary = JsonCompat.consumePropertyString(json, Constants.PROP_SUMMARY);
node.description = JsonCompat.consumePropertyString(json, Constants.PROP_DESCRIPTION);
node.$ref = JsonCompat.consumePropertyString(json, Constants.PROP_$REF);
// tags
List<Object> jsonTags = JsonCompat.consumePropertyArray(json, Constants.PROP_TAGS);
if (jsonTags != null) {
jsonTags.forEach(j -> {
AaiTag tag = nodeFactory.createTag(node);
this.readTag(j, tag);
node.addTag(tag);
});
}
// external docs
Object jsonED = JsonCompat.consumeProperty(json, Constants.PROP_EXTERNAL_DOCS);
if (jsonED != null) {
AaiExternalDocumentation value = nodeFactory.createExternalDocumentation(node);
this.readExternalDocumentation(jsonED, value);
node.externalDocs = value;
}
// bindings
Object bindings = JsonCompat.consumeProperty(json, Constants.PROP_BINDINGS);
if (bindings != null) {
AaiMessageBindings bindingsModel = nodeFactory.createMessageBindings(node);
this.readMessageBindings(bindings, bindingsModel);
node.bindings = bindingsModel;
}
// examples
List<Object> examples = JsonCompat.consumePropertyArray(json, Constants.PROP_EXAMPLES);
if (examples != null) {
List<Map<String, Object>> examplesList = new ArrayList<>();
this.readMessageExamples(examples, examplesList);
node.examples = examplesList;
}
this.readExtensions(json, node);
this.readExtraProperties(json, node);
}
use of io.apicurio.datamodels.asyncapi.models.AaiCorrelationId in project apicurio-data-models by Apicurio.
the class AaiDataModelReader method readComponents.
public void readComponents(Object json, Components node) {
AaiComponents components = (AaiComponents) node;
// schemas
final Object _jsonSchemas = JsonCompat.consumeProperty(json, Constants.PROP_SCHEMAS);
if (_jsonSchemas != null) {
JsonCompat.keys(_jsonSchemas).forEach(key -> {
Object value = JsonCompat.consumeProperty(_jsonSchemas, key);
AaiSchema schemaModel = nodeFactory.createSchemaDefinition(node, key);
this.readSchema(value, schemaModel);
components.addSchemaDefinition(key, schemaModel);
});
}
// messages
final Object _jsonMessages = JsonCompat.consumeProperty(json, Constants.PROP_MESSAGES);
if (_jsonMessages != null) {
JsonCompat.keys(_jsonMessages).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonMessages, key);
AaiMessage value = nodeFactory.createMessage(node, key);
this.readMessage(jsonValue, value);
components.addMessage(key, value);
});
}
// security schemes
final Object _jsonSecuritySchemes = JsonCompat.consumeProperty(json, Constants.PROP_SECURITY_SCHEMES);
if (_jsonSecuritySchemes != null) {
JsonCompat.keys(_jsonSecuritySchemes).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonSecuritySchemes, key);
AaiSecurityScheme value = nodeFactory.createSecurityScheme(node, key);
this.readSecurityScheme(jsonValue, value);
components.addSecurityScheme(key, value);
});
}
// parameters
final Object _jsonParams = JsonCompat.consumeProperty(json, Constants.PROP_PARAMETERS);
if (_jsonParams != null) {
JsonCompat.keys(_jsonParams).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonParams, key);
AaiParameter value = nodeFactory.createParameter(node, key);
this.readAaiParameter(jsonValue, value);
components.addParameter(key, value);
});
}
// correlationIds
final Object _jsonCorrelationIds = JsonCompat.consumeProperty(json, Constants.PROP_CORRELATION_IDS);
if (_jsonCorrelationIds != null) {
JsonCompat.keys(_jsonCorrelationIds).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonCorrelationIds, key);
AaiCorrelationId value = nodeFactory.createCorrelationId(node, key);
this.readCorrelationId(jsonValue, value);
components.addCorrelationId(key, value);
});
}
// operation traits
final Object _jsonOpTraits = JsonCompat.consumeProperty(json, Constants.PROP_OPERATION_TRAITS);
if (_jsonOpTraits != null) {
JsonCompat.keys(_jsonOpTraits).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonOpTraits, key);
AaiOperationTraitDefinition traitDef = nodeFactory.createOperationTraitDefinition(node, key);
this.readOperationTrait(jsonValue, traitDef);
components.addOperationTraitDefinition(key, traitDef);
});
}
// message traits
final Object _jsonMessageTraits = JsonCompat.consumeProperty(json, Constants.PROP_MESSAGE_TRAITS);
if (_jsonMessageTraits != null) {
JsonCompat.keys(_jsonMessageTraits).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonMessageTraits, key);
AaiMessageTraitDefinition traitDef = nodeFactory.createMessageTraitDefinition(node, key);
this.readMessageTrait(jsonValue, traitDef);
components.addMessageTraitDefinition(key, traitDef);
});
}
// server bindings
final Object _jsonServerBindings = JsonCompat.consumeProperty(json, Constants.PROP_SERVER_BINDINGS);
if (_jsonServerBindings != null) {
JsonCompat.keys(_jsonServerBindings).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonServerBindings, key);
AaiServerBindingsDefinition bindingsDef = nodeFactory.createServerBindingsDefinition(node, key);
this.readServerBindings(jsonValue, bindingsDef);
components.addServerBindingDefinition(key, bindingsDef);
});
}
// channel bindings
final Object _jsonChannelBindings = JsonCompat.consumeProperty(json, Constants.PROP_CHANNEL_BINDINGS);
if (_jsonChannelBindings != null) {
JsonCompat.keys(_jsonChannelBindings).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonChannelBindings, key);
AaiChannelBindingsDefinition bindingsDef = nodeFactory.createChannelBindingsDefinition(node, key);
this.readChannelBindings(jsonValue, bindingsDef);
components.addChannelBindingDefinition(key, bindingsDef);
});
}
// operation bindings
final Object _jsonOpBindings = JsonCompat.consumeProperty(json, Constants.PROP_OPERATION_BINDINGS);
if (_jsonOpBindings != null) {
JsonCompat.keys(_jsonOpBindings).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonOpBindings, key);
AaiOperationBindingsDefinition bindingsDef = nodeFactory.createOperationBindingsDefinition(node, key);
this.readOperationBindings(jsonValue, bindingsDef);
components.addOperationBindingDefinition(key, bindingsDef);
});
}
// message bindings
final Object _jsonMessageBindings = JsonCompat.consumeProperty(json, Constants.PROP_MESSAGE_BINDINGS);
if (_jsonMessageBindings != null) {
JsonCompat.keys(_jsonMessageBindings).forEach(key -> {
Object jsonValue = JsonCompat.consumeProperty(_jsonMessageBindings, key);
AaiMessageBindingsDefinition bindingsDef = nodeFactory.createMessageBindingsDefinition(node, key);
this.readMessageBindings(jsonValue, bindingsDef);
components.addMessageBindingDefinition(key, bindingsDef);
});
}
this.readExtensions(json, node);
this.readExtraProperties(json, node);
}
Aggregations