Skip to content

Commit

Permalink
feat(AsyncAPI 2.6.0): Channel - Operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Feb 11, 2023
1 parent 3100101 commit 7708420
Show file tree
Hide file tree
Showing 49 changed files with 4,228 additions and 178 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.asyncapi.v2._6_0.jackson.binding.message;

import com.asyncapi.v2._6_0.binding.message.amqp.AMQPMessageBinding;
import com.asyncapi.v2._6_0.binding.message.amqp1.AMQP1MessageBinding;
import com.asyncapi.v2._6_0.binding.message.anypointmq.AnypointMQMessageBinding;
import com.asyncapi.v2._6_0.binding.message.googlepubsub.GooglePubSubMessageBinding;
import com.asyncapi.v2._6_0.binding.message.http.HTTPMessageBinding;
import com.asyncapi.v2._6_0.binding.message.ibmmq.IBMMQMessageBinding;
import com.asyncapi.v2._6_0.binding.message.jms.JMSMessageBinding;
import com.asyncapi.v2._6_0.binding.message.kafka.KafkaMessageBinding;
import com.asyncapi.v2._6_0.binding.message.mercure.MercureMessageBinding;
import com.asyncapi.v2._6_0.binding.message.mqtt.MQTTMessageBinding;
import com.asyncapi.v2._6_0.binding.message.mqtt5.MQTT5MessageBinding;
import com.asyncapi.v2._6_0.binding.message.nats.NATSMessageBinding;
import com.asyncapi.v2._6_0.binding.message.pulsar.PulsarMessageBinding;
import com.asyncapi.v2._6_0.binding.message.redis.RedisMessageBinding;
import com.asyncapi.v2._6_0.binding.message.sns.SNSMessageBinding;
import com.asyncapi.v2._6_0.binding.message.solace.SolaceMessageBinding;
import com.asyncapi.v2._6_0.binding.message.sqs.SQSMessageBinding;
import com.asyncapi.v2._6_0.binding.message.stomp.STOMPMessageBinding;
import com.asyncapi.v2._6_0.binding.message.ws.WebSocketsMessageBinding;
import com.asyncapi.v2._6_0.model.Reference;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* Serializes message bindings map.
*
* @author Pavel Bodiachevskii
*/
public class MessageBindingsDeserializer extends JsonDeserializer<Map<String, Object>> {

private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public Map<String, Object> deserialize(
JsonParser p,
DeserializationContext ctxt
) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = p.getCodec();
JsonNode node = objectCodec.readTree(p);

Map<String, Object> bindings = new HashMap<>();

node.fieldNames().forEachRemaining(
fieldName -> {
try {
bindings.put(fieldName, chooseKnownPojo(fieldName, node.get(fieldName)));
} catch (IOException e) {
e.printStackTrace();
}
}
);

return bindings;
}

private Object chooseKnownPojo(String bindingKey, JsonNode binding) throws IOException {
if (binding.get("$ref" ) != null) {
return objectMapper.readValue(binding.toString(), Reference.class);
}

switch (bindingKey) {
case "amqp": return objectMapper.readValue(binding.toString(), AMQPMessageBinding.class);
case "amqp1": return objectMapper.readValue(binding.toString(), AMQP1MessageBinding.class);
case "anypointmq": return objectMapper.readValue(binding.toString(), AnypointMQMessageBinding.class);
case "googlepubsub": return objectMapper.readValue(binding.toString(), GooglePubSubMessageBinding.class);
case "http": return objectMapper.readValue(binding.toString(), HTTPMessageBinding.class);
case "ibmmq": return objectMapper.readValue(binding.toString(), IBMMQMessageBinding.class);
case "jms": return objectMapper.readValue(binding.toString(), JMSMessageBinding.class);
case "kafka": return objectMapper.readValue(binding.toString(), KafkaMessageBinding.class);
case "mercure": return objectMapper.readValue(binding.toString(), MercureMessageBinding.class);
case "mqtt": return objectMapper.readValue(binding.toString(), MQTTMessageBinding.class);
case "mqtt5": return objectMapper.readValue(binding.toString(), MQTT5MessageBinding.class);
case "nats": return objectMapper.readValue(binding.toString(), NATSMessageBinding.class);
case "pulsar": return objectMapper.readValue(binding.toString(), PulsarMessageBinding.class);
case "redis": return objectMapper.readValue(binding.toString(), RedisMessageBinding.class);
case "sns": return objectMapper.readValue(binding.toString(), SNSMessageBinding.class);
case "solace": return objectMapper.readValue(binding.toString(), SolaceMessageBinding.class);
case "sqs": return objectMapper.readValue(binding.toString(), SQSMessageBinding.class);
case "stomp": return objectMapper.readValue(binding.toString(), STOMPMessageBinding.class);
case "ws": return objectMapper.readValue(binding.toString(), WebSocketsMessageBinding.class);
default: return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.asyncapi.v2._6_0.jackson.binding.operation;

import com.asyncapi.v2._6_0.binding.operation.amqp.AMQPOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.amqp1.AMQP1OperationBinding;
import com.asyncapi.v2._6_0.binding.operation.anypointmq.AnypointMQOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.googlepubsub.GooglePubSubOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.http.HTTPOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.ibmmq.IBMMQOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.jms.JMSOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.kafka.KafkaOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.mercure.MercureOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.mqtt.MQTTOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.mqtt5.MQTT5OperationBinding;
import com.asyncapi.v2._6_0.binding.operation.nats.NATSOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.pulsar.PulsarOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.redis.RedisOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.sns.SNSOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.solace.SolaceOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.sqs.SQSOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.stomp.STOMPOperationBinding;
import com.asyncapi.v2._6_0.binding.operation.ws.WebSocketsOperationBinding;
import com.asyncapi.v2._6_0.model.Reference;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* Serializes operation bindings map.
*
* @version 2.6.0
* @author Pavel Bodiachevskii
*/
public class OperationBindingsDeserializer extends JsonDeserializer<Map<String, Object>> {

private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public Map<String, Object> deserialize(
JsonParser p,
DeserializationContext ctxt
) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = p.getCodec();
JsonNode node = objectCodec.readTree(p);

Map<String, Object> bindings = new HashMap<>();

node.fieldNames().forEachRemaining(
fieldName -> {
try {
bindings.put(fieldName, chooseKnownPojo(fieldName, node.get(fieldName)));
} catch (IOException e) {
e.printStackTrace();
}
}
);

return bindings;
}

private Object chooseKnownPojo(String bindingKey, JsonNode binding) throws IOException {
if (binding.get("$ref" ) != null) {
return objectMapper.readValue(binding.toString(), Reference.class);
}

switch (bindingKey) {
case "amqp": return objectMapper.readValue(binding.toString(), AMQPOperationBinding.class);
case "amqp1": return objectMapper.readValue(binding.toString(), AMQP1OperationBinding.class);
case "anypointmq": return objectMapper.readValue(binding.toString(), AnypointMQOperationBinding.class);
case "googlepubsub": return objectMapper.readValue(binding.toString(), GooglePubSubOperationBinding.class);
case "http": return objectMapper.readValue(binding.toString(), HTTPOperationBinding.class);
case "ibmmq": return objectMapper.readValue(binding.toString(), IBMMQOperationBinding.class);
case "jms": return objectMapper.readValue(binding.toString(), JMSOperationBinding.class);
case "kafka": return objectMapper.readValue(binding.toString(), KafkaOperationBinding.class);
case "mercure": return objectMapper.readValue(binding.toString(), MercureOperationBinding.class);
case "mqtt": return objectMapper.readValue(binding.toString(), MQTTOperationBinding.class);
case "mqtt5": return objectMapper.readValue(binding.toString(), MQTT5OperationBinding.class);
case "nats": return objectMapper.readValue(binding.toString(), NATSOperationBinding.class);
case "pulsar": return objectMapper.readValue(binding.toString(), PulsarOperationBinding.class);
case "redis": return objectMapper.readValue(binding.toString(), RedisOperationBinding.class);
case "sns": return objectMapper.readValue(binding.toString(), SNSOperationBinding.class);
case "solace": return objectMapper.readValue(binding.toString(), SolaceOperationBinding.class);
case "sqs": return objectMapper.readValue(binding.toString(), SQSOperationBinding.class);
case "stomp": return objectMapper.readValue(binding.toString(), STOMPOperationBinding.class);
case "ws": return objectMapper.readValue(binding.toString(), WebSocketsOperationBinding.class);
default: return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.asyncapi.v2._6_0.jackson.model.channel.message;

import com.asyncapi.v2._6_0.model.Reference;
import com.asyncapi.v2._6_0.model.channel.message.CorrelationId;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
* Serializes message correlation id.
*
* @author Pavel Bodiachevskii
*/
public class MessageCorrelationIdDeserializer extends JsonDeserializer<Object> {

private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = p.getCodec();
JsonNode node = objectCodec.readTree(p);

return chooseKnownPojo(node);
}

private Object chooseKnownPojo(JsonNode correlationId) throws IOException {
if (correlationId.get("$ref") != null) {
return objectMapper.readValue(correlationId.toString(), Reference.class);
} else {
return objectMapper.readValue(correlationId.toString(), CorrelationId.class);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.asyncapi.v2._6_0.jackson.model.channel.message;

import com.asyncapi.v2._6_0.model.Reference;
import com.asyncapi.v2._6_0.model.schema.Schema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
* Serializes message traits list.
*
* @author Pavel Bodiachevskii
*/
public class MessageHeadersDeserializer extends JsonDeserializer<Object> {

private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = p.getCodec();
JsonNode node = objectCodec.readTree(p);

return chooseKnownPojo(node);
}

private Object chooseKnownPojo(JsonNode traitsValue) throws IOException {
if (traitsValue.get("$ref") != null) {
return objectMapper.readValue(traitsValue.toString(), Reference.class);
} else {
return objectMapper.readValue(traitsValue.toString(), Schema.class);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.asyncapi.v2._6_0.jackson.model.channel.message;

import com.asyncapi.v2._6_0.model.schema.Schema;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
* Serializes message traits list.
*
* @author Pavel Bodiachevskii
*/
public class MessagePayloadDeserializer extends JsonDeserializer<Object> {

private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = p.getCodec();
JsonNode node = objectCodec.readTree(p);

return chooseKnownPojo(node);
}

private Object chooseKnownPojo(JsonNode traitsValue) {
try {
return objectMapper.readValue(traitsValue.toString(), Schema.class);
} catch (Exception e) {
return traitsValue;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.asyncapi.v2._6_0.jackson.model.channel.message;

import com.asyncapi.v2._6_0.model.Reference;
import com.asyncapi.v2._6_0.model.channel.message.MessageTrait;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Serializes message traits list.
*
* @author Pavel Bodiachevskii
*/
public class MessageTraitsDeserializer extends JsonDeserializer<List<Object>> {

private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public List<Object> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = p.getCodec();
JsonNode node = objectCodec.readTree(p);

List<Object> traits = new ArrayList<>();

node.forEach(
traitsValue -> {
try {
traits.add(chooseKnownPojo(traitsValue));
} catch (IOException e) {
e.printStackTrace();
}
}
);

return traits;
}

private Object chooseKnownPojo(JsonNode traitsValue) throws IOException {
if (traitsValue.get("$ref") != null) {
return objectMapper.readValue(traitsValue.toString(), Reference.class);
} else {
return objectMapper.readValue(traitsValue.toString(), MessageTrait.class);
}
}

}
Loading

0 comments on commit 7708420

Please sign in to comment.