Search in sources :

Example 6 with AaiMessage

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

the class AaiDataModelReader method readOperation.

@Override
public void readOperation(Object json, Operation node) {
    AaiOperation aaiNode = (AaiOperation) node;
    // traits
    List<Object> traits = JsonCompat.consumePropertyArray(json, Constants.PROP_TRAITS);
    if (traits != null) {
        traits.forEach(trait -> {
            AaiOperationTrait traitModel = nodeFactory.createOperationTrait(node, null);
            this.readOperationTrait(trait, traitModel);
            aaiNode.addTrait(traitModel);
        });
    }
    // message
    Object json_ = JsonCompat.consumeProperty(json, Constants.PROP_MESSAGE);
    if (json_ != null) {
        AaiMessage value = nodeFactory.createMessage(node, null);
        this.readMessage(json_, value);
        aaiNode.message = value;
    }
    this.readOperationBase(json, aaiNode);
}
Also used : AaiOperation(io.apicurio.datamodels.asyncapi.models.AaiOperation) AaiOperationTrait(io.apicurio.datamodels.asyncapi.models.AaiOperationTrait) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 7 with AaiMessage

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

the class AaiDataModelReader method readMessage.

public void readMessage(Object json, AaiMessage node) {
    // payload
    Object jPayload = JsonCompat.consumeProperty(json, Constants.PROP_PAYLOAD);
    if (jPayload != null) {
        node.payload = jPayload;
    }
    // traits
    List<Object> traits = JsonCompat.consumePropertyArray(json, Constants.PROP_TRAITS);
    if (traits != null) {
        traits.forEach(trait -> {
            AaiMessageTrait traitModel = nodeFactory.createMessageTrait(node, null);
            this.readMessageTrait(trait, traitModel);
            node.addTrait(traitModel);
        });
    }
    // Process a "oneOf" message
    List<Object> oneOfJson = JsonCompat.consumePropertyArray(json, Constants.PROP_ONE_OF);
    if (oneOfJson != null) {
        for (Object itemJson : oneOfJson) {
            AaiMessage item = nodeFactory.createMessage(node, null);
            this.readMessage(itemJson, item);
            item._isOneOfMessage = true;
            node.addOneOfMessage(item, null);
        }
    }
    this.readMessageBase(json, node);
}
Also used : AaiMessageTrait(io.apicurio.datamodels.asyncapi.models.AaiMessageTrait) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 8 with AaiMessage

use of io.apicurio.datamodels.asyncapi.models.AaiMessage 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);
}
Also used : AaiMessageBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageBindingsDefinition) AaiOperationBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiOperationBindingsDefinition) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage) AaiMessageTraitDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition) AaiParameter(io.apicurio.datamodels.asyncapi.models.AaiParameter) AaiChannelBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiChannelBindingsDefinition) AaiSecurityScheme(io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme) AaiServerBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiServerBindingsDefinition) AaiComponents(io.apicurio.datamodels.asyncapi.models.AaiComponents) AaiCorrelationId(io.apicurio.datamodels.asyncapi.models.AaiCorrelationId) AaiOperationTraitDefinition(io.apicurio.datamodels.asyncapi.models.AaiOperationTraitDefinition)

Example 9 with AaiMessage

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

the class RenameMessageDefinitionCommand method execute.

@Override
public void execute(Document document) {
    LoggerCompat.info("[RenameMessageDefinitionCommand] Executing.");
    this._references = new ArrayList<>();
    AaiDocument doc = (AaiDocument) document;
    if (renameMessageDefinition(doc, this._oldName, this._newName)) {
        String oldRef = nameToReference(this._oldName);
        String newRef = nameToReference(this._newName);
        MessageRefFinder finder = new MessageRefFinder(oldRef);
        List<AaiMessage> messages = finder.findIn(document);
        for (AaiMessage message : messages) {
            this._references.add(Library.createNodePath(message));
            message.$ref = newRef;
        }
    }
}
Also used : AaiDocument(io.apicurio.datamodels.asyncapi.models.AaiDocument) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Example 10 with AaiMessage

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

the class RenameSchemaDefinitionCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[RenameSchemaDefinitionCommand] Reverting.");
    if (this._renameSchemaDefinition(document, this._newName, this._oldName)) {
        String oldRef = this._nameToReference(this._oldName);
        if (ModelUtils.isDefined(this._references)) {
            this._references.forEach(ref -> {
                Schema schema = (Schema) ref.resolve(document);
                schema.$ref = oldRef;
            });
        }
        if (ModelUtils.isDefined(this._messageReferences)) {
            this._messageReferences.forEach(ref -> {
                AaiMessage aaiMessage = (AaiMessage) ref.resolve(document);
                JsonCompat.setPropertyString(aaiMessage.payload, "$ref", oldRef);
            });
        }
    }
}
Also used : Schema(io.apicurio.datamodels.core.models.common.Schema) Oas30OneOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema) Oas30NotSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30NotSchema) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema) IPropertySchema(io.apicurio.datamodels.core.models.common.IPropertySchema) OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) Oas30AnyOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage)

Aggregations

AaiMessage (io.apicurio.datamodels.asyncapi.models.AaiMessage)17 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)4 AaiOperation (io.apicurio.datamodels.asyncapi.models.AaiOperation)3 AaiSchema (io.apicurio.datamodels.asyncapi.models.AaiSchema)3 Aai20Message (io.apicurio.datamodels.asyncapi.v2.models.Aai20Message)2 Aai20NodeFactory (io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory)2 IPropertySchema (io.apicurio.datamodels.core.models.common.IPropertySchema)2 Schema (io.apicurio.datamodels.core.models.common.Schema)2 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)2 Oas30AnyOfSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema)2 Oas30NotSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30NotSchema)2 Oas30OneOfSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema)2 AaiChannelBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiChannelBindingsDefinition)1 AaiComponents (io.apicurio.datamodels.asyncapi.models.AaiComponents)1 AaiCorrelationId (io.apicurio.datamodels.asyncapi.models.AaiCorrelationId)1 AaiDocument (io.apicurio.datamodels.asyncapi.models.AaiDocument)1 AaiMessageBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiMessageBindingsDefinition)1 AaiMessageTrait (io.apicurio.datamodels.asyncapi.models.AaiMessageTrait)1 AaiMessageTraitDefinition (io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition)1 AaiOperationBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiOperationBindingsDefinition)1