Search in sources :

Example 1 with AaiHeaderItem

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

the class ChangeHeadersRefCommand_Aai20 method execute.

@Override
public void execute(Document document) {
    LoggerCompat.info("[ChangeHeadersRefCommand_Aai20] Executing.");
    AaiOperation operation = (AaiOperation) this._operationPath.resolve(document);
    this._changed = false;
    if (this.isNullOrUndefined(operation) || this.isNullOrUndefined(operation.message) || !isValidRef(this._headersRef)) {
        return;
    }
    AaiHeaderItem headerItem = operation.message.headers;
    if (headerItem == null) {
        Aai20NodeFactory nodeFactory = new Aai20NodeFactory();
        headerItem = nodeFactory.createHeaderItem(operation.message);
        operation.message.headers = headerItem;
    }
    if (headerItem.$ref != null) {
        this._oldHeadersRef = headerItem.$ref;
    }
    headerItem.$ref = this._headersRef;
    this._changed = true;
}
Also used : AaiOperation(io.apicurio.datamodels.asyncapi.models.AaiOperation) AaiHeaderItem(io.apicurio.datamodels.asyncapi.models.AaiHeaderItem) Aai20NodeFactory(io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory)

Example 2 with AaiHeaderItem

use of io.apicurio.datamodels.asyncapi.models.AaiHeaderItem 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);
}
Also used : AaiExternalDocumentation(io.apicurio.datamodels.asyncapi.models.AaiExternalDocumentation) AaiTag(io.apicurio.datamodels.asyncapi.models.AaiTag) AaiHeaderItem(io.apicurio.datamodels.asyncapi.models.AaiHeaderItem) AaiMessageBindings(io.apicurio.datamodels.asyncapi.models.AaiMessageBindings) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) AaiCorrelationId(io.apicurio.datamodels.asyncapi.models.AaiCorrelationId)

Example 3 with AaiHeaderItem

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

the class ChangeHeadersRefCommand_Aai20 method undo.

@Override
public void undo(Document document) {
    LoggerCompat.info("[ChangeHeadersRefCommand_Aai20] Reverting.");
    AaiOperation operation = (AaiOperation) this._operationPath.resolve(document);
    if (!this._changed || this.isNullOrUndefined(operation) || this.isNullOrUndefined(operation.message)) {
        return;
    }
    AaiHeaderItem headerItem = operation.message.headers;
    if (this._oldHeadersRef != null) {
        headerItem.$ref = this._oldHeadersRef;
    } else {
        headerItem.$ref = null;
    }
}
Also used : AaiOperation(io.apicurio.datamodels.asyncapi.models.AaiOperation) AaiHeaderItem(io.apicurio.datamodels.asyncapi.models.AaiHeaderItem)

Aggregations

AaiHeaderItem (io.apicurio.datamodels.asyncapi.models.AaiHeaderItem)3 AaiOperation (io.apicurio.datamodels.asyncapi.models.AaiOperation)2 AaiCorrelationId (io.apicurio.datamodels.asyncapi.models.AaiCorrelationId)1 AaiExternalDocumentation (io.apicurio.datamodels.asyncapi.models.AaiExternalDocumentation)1 AaiMessageBindings (io.apicurio.datamodels.asyncapi.models.AaiMessageBindings)1 AaiTag (io.apicurio.datamodels.asyncapi.models.AaiTag)1 Aai20NodeFactory (io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1