Skip to content

Commit

Permalink
chore: Improved AsyncAPI interface (#515)
Browse files Browse the repository at this point in the history
* chore: Improved AsyncAPI interface

Improved the creation of Messages.

A 'Message' is now an interface that's implemented by
'MessageObject' and 'MessageReference'. This change
allows to properly define a 'Message' and use it in a more
transparent way.

Added also different builders

* chore: Improved AsyncAPI interface

Improved the creation of Schemas.

A 'Schemas' is now an interface that's implemented by
'SchemasObject' and 'SchemasReference'. This change
allows to properly define a 'Schemas' and use it in a more
transparent way.

Added also different builders

* chore: Improved AsyncAPI interface

Improved the creation of Messages.

A 'Message' is now an interface that's implemented by
'MessageObject' and 'MessageReference'. This change
allows to properly define a 'Message' and use it in a more
transparent way.

Added also different builders

* chore: Move 'net.javacrumbs.json-unit:json-unit-assertj' version to dependencies.gradle

* chore: Improved AsyncAPI enums

Added convenient methods to properly create the enums from their
String representations.

* fix: MessageBinding should be abstract

* feat: Added missing SNS Binding Operation

feat: Added missing SNS Binding Operation

* fix: Fixed Operation Bindings

fix: Fixed spotless
  • Loading branch information
ctasada authored Jan 2, 2024
1 parent 95d63a9 commit 73f6db9
Show file tree
Hide file tree
Showing 63 changed files with 1,713 additions and 694 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ext {
moneyApiVersion = '1.1'

junitJupiterVersion = '5.10.1'
jsonUnitAssertJVersion = '3.2.2'

lombokVersion = '1.18.30'

Expand Down
2 changes: 1 addition & 1 deletion springwolf-asyncapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
testImplementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
testImplementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
testImplementation "io.swagger.core.v3:swagger-core-jakarta:${swaggerVersion}"
testImplementation "net.javacrumbs.json-unit:json-unit-assertj:3.2.2"
testImplementation "net.javacrumbs.json-unit:json-unit-assertj:${jsonUnitAssertJVersion}"

testRuntimeOnly "org.junit.jupiter:junit-jupiter:${junitJupiterVersion}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
public class MessageBinding extends ExtendableObject {}
public abstract class MessageBinding extends ExtendableObject {}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.amqp;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum AMQPChannelExchangeType {
@JsonProperty("topic")
TOPIC,
TOPIC("topic"),
DIRECT("direct"),
FANOUT("fanout"),
DEFAULT("default"),
HEADERS("headers");

@JsonProperty("direct")
DIRECT,
public final String type;

@JsonProperty("fanout")
FANOUT,
AMQPChannelExchangeType(String type) {
this.type = type;
}

@JsonProperty("default")
DEFAULT,
public static AMQPChannelExchangeType fromString(String type) {
return valueOf(type.toUpperCase());
}

@JsonProperty("headers")
HEADERS
@Override
public String toString() {
return this.type;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.amqp;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum AMQPChannelType {
@JsonProperty("queue")
QUEUE,
QUEUE("queue"),
ROUTING_KEY("routingKey");

public final String type;

AMQPChannelType(String type) {
this.type = type;
}

public static AMQPChannelType fromString(String type) {
return valueOf(type.toUpperCase());
}

@JsonProperty("routingKey")
ROUTING_KEY
@Override
public String toString() {
return this.type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public class AMQPOperationBinding extends OperationBinding {
* </p>
* Applies to: receive, send
*/
@Builder.Default
@PositiveOrZero
@JsonProperty("expiration")
private Integer expiration;
private Integer expiration = 0;

/**
* Identifies the user who has sent the message.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.googlepubsub;

import io.github.stavshamir.springwolf.asyncapi.v3.bindings.ChannelBinding;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.OperationBinding;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -16,4 +16,4 @@
@Builder
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class GooglePubSubOperationBinding extends ChannelBinding {}
public class GooglePubSubOperationBinding extends OperationBinding {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.jms;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum JMSChannelBindingDestinationType {
@JsonProperty("queue")
QUEUE,
QUEUE("queue"),
FIFO_QUEUE("fifo-queue");

public final String type;

JMSChannelBindingDestinationType(String type) {
this.type = type;
}

public static JMSChannelBindingDestinationType fromString(String type) {
return valueOf(type.toUpperCase());
}

@JsonProperty("fifo-queue")
FIFO_QUEUE
@Override
public String toString() {
return this.type;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.kafka;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum KafkaChannelTopicCleanupPolicy {
@JsonProperty("compact")
COMPACT,
COMPACT("compact"),
DELETE("delete");

public final String type;

KafkaChannelTopicCleanupPolicy(String type) {
this.type = type;
}

public static KafkaChannelTopicCleanupPolicy fromString(String type) {
return valueOf(type.toUpperCase());
}

@JsonProperty("delete")
DELETE
@Override
public String toString() {
return this.type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.ChannelBinding;
import io.github.stavshamir.springwolf.asyncapi.v3.model.Reference;
import io.github.stavshamir.springwolf.asyncapi.v3.model.schema.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
Expand Down Expand Up @@ -38,7 +37,7 @@ public class MQTTMessageBinding extends ChannelBinding {
* for when it is received.
*/
@JsonProperty("correlationData")
private Object correlationData;
private Schema correlationData;

/**
* String describing the content type of the message payload. This should not conflict with the contentType field
Expand Down Expand Up @@ -67,29 +66,13 @@ public static MQTTMessageBindingBuilder builder() {
}

public static class CustomMQTTMessageBinding extends MQTTMessageBindingBuilder {
private Object correlationData;
private Object responseTopic;

public MQTTMessageBindingBuilder correlationData(Schema schema) {
this.correlationData = schema;
return this;
}

public MQTTMessageBindingBuilder correlationData(Reference reference) {
this.correlationData = reference;
return this;
}

public MQTTMessageBindingBuilder responseTopic(Schema schema) {
this.responseTopic = schema;
return this;
}

public MQTTMessageBindingBuilder responseTopic(Reference reference) {
this.responseTopic = reference;
return this;
}

public MQTTMessageBindingBuilder responseTopic(String uriString) {
this.responseTopic = uriString;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.mqtt;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.ChannelBinding;
import io.github.stavshamir.springwolf.asyncapi.v3.model.Reference;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.OperationBinding;
import io.github.stavshamir.springwolf.asyncapi.v3.model.schema.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
Expand All @@ -23,7 +22,7 @@
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class MQTTOperationBinding extends ChannelBinding {
public class MQTTOperationBinding extends OperationBinding {
/**
* Defines the Quality of Service (QoS) levels for the message flow between client and server.
* Its value MUST be either 0 (At most once delivery), 1 (At least once delivery), or 2 (Exactly once delivery).
Expand Down Expand Up @@ -76,10 +75,5 @@ public MQTTOperationBindingBuilder messageExpiryInterval(Schema schema) {
this.messageExpiryInterval = schema;
return this;
}

public MQTTOperationBindingBuilder messageExpiryInterval(Reference reference) {
this.messageExpiryInterval = reference;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.ServerBinding;
import io.github.stavshamir.springwolf.asyncapi.v3.model.Reference;
import io.github.stavshamir.springwolf.asyncapi.v3.model.schema.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -87,11 +86,6 @@ public MQTTServerBindingBuilder sessionExpiryInterval(Schema schema) {
return this;
}

public MQTTServerBindingBuilder sessionExpiryInterval(Reference reference) {
this.sessionExpiryInterval = reference;
return this;
}

public MQTTServerBindingBuilder maximumPacketSize(Integer integer) {
this.maximumPacketSize = integer;
return this;
Expand All @@ -101,10 +95,5 @@ public MQTTServerBindingBuilder maximumPacketSize(Schema schema) {
this.maximumPacketSize = schema;
return this;
}

public MQTTServerBindingBuilder maximumPacketSize(Reference reference) {
this.maximumPacketSize = reference;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.nats;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.ChannelBinding;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.OperationBinding;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -17,7 +17,7 @@
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class NATSOperationBinding extends ChannelBinding {
public class NATSOperationBinding extends OperationBinding {
/**
* Defines the name of the queue to use. It MUST NOT exceed 255 characters.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,22 @@ public class PulsarChannelBinding extends ChannelBinding {
private String bindingVersion = "0.1.0";

public enum PulsarPesistenceType {
@JsonProperty("persistent")
PERSISTENCE,
PERSISTENCE("persistent"),
NON_PERSISTENCE("non-persistent");

@JsonProperty("non-persistent")
NON_PERSISTENCE
public final String type;

PulsarPesistenceType(String type) {
this.type = type;
}

public static PulsarPesistenceType fromString(String type) {
return valueOf(type.toUpperCase());
}

@Override
public String toString() {
return this.type;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.pulsar;

import io.github.stavshamir.springwolf.asyncapi.v3.bindings.ChannelBinding;
import io.github.stavshamir.springwolf.asyncapi.v3.bindings.OperationBinding;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -16,4 +16,4 @@
@Builder
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class PulsarOperationBinding extends ChannelBinding {}
public class PulsarOperationBinding extends OperationBinding {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.asyncapi.v3.bindings.sns;

import com.fasterxml.jackson.annotation.JsonProperty;

public enum SNSChannelBindingEffect {
@JsonProperty("Allow")
ALLOW,
@JsonProperty("Deny")
DENY
ALLOW("Allow"),
DENY("Deny");

public final String type;

SNSChannelBindingEffect(String type) {
this.type = type;
}

public static SNSChannelBindingEffect fromString(String type) {
return valueOf(type.toUpperCase());
}

@Override
public String toString() {
return this.type;
}
}
Loading

0 comments on commit 73f6db9

Please sign in to comment.