Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;

import java.util.Map;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -44,7 +45,7 @@ void shouldAddJsonSchemaExtensionTest() throws Exception {
// given
AsyncAPI asyncAPI = createAsyncApi();
SchemaObject schemaObject = new SchemaObject();
schemaObject.setType(SchemaType.OBJECT);
schemaObject.setType(Set.of(SchemaType.OBJECT));
asyncAPI.getComponents().setSchemas(Map.of("schema", ComponentSchema.of(schemaObject)));

when(jsonSchemaGenerator.fromSchema(any(), any())).thenReturn("mock-string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Supplier;
import java.util.stream.Stream;
Expand All @@ -54,14 +55,14 @@ void validateJsonSchemaTest(String expectedJsonSchema, Supplier<Schema<?>> async

// ref cycle ping -> pingField -> pong -> pongField -> ping (repeat)
SchemaObject pingSchema = new SchemaObject();
pingSchema.setType(SchemaType.OBJECT);
pingSchema.setType(Set.of(SchemaType.OBJECT));
pingSchema.setProperties(Map.of("pingfield", ComponentSchema.of(SchemaReference.toSchema("PongSchema"))));
SchemaObject pongSchema = new SchemaObject();
pongSchema.setType(SchemaType.OBJECT);
pongSchema.setType(Set.of(SchemaType.OBJECT));
pongSchema.setProperties(Map.of("pongField", ComponentSchema.of(SchemaReference.toSchema("PingSchema"))));

SchemaObject stringSchema = new SchemaObject();
stringSchema.setType(SchemaType.STRING);
stringSchema.setType(Set.of(SchemaType.STRING));

Map<String, ComponentSchema> definitions = Map.of(
"StringRef",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.ToString;

/**
* Container class representing a schema in the 'components' block of an AsnycApi document. Contains either
* Container class representing a schema in the 'components' block of an AsyncAPI document. Contains either
* <ul>
* <li>a {@link SchemaObject} instance, which represents an schema formatted with the default asyncapi schema format</li>
* <li>a {@link SchemaReference}} instance, pointing to an other schema </li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,4 @@ public class SchemaObject extends ExtendableObject implements Schema {

@JsonProperty(value = "maxItems")
private Integer maxItems;

public void setType(String type) {
// maintainer note: review with OpenAPI 3.1
this.type = Set.of(type);
}

public void setTypes(Set<String> types) {
// maintainer note: review with OpenAPI 3.1
this.type = types;
}

public static class SchemaObjectBuilder {
// maintainer note: remove custom builder in next major release and use Lomboks provided version

public SchemaObjectBuilder type(Set<String> type) {
this.type = type;
return this;
}

public SchemaObjectBuilder type(String type) {
if (type != null) {
this.type = Set.of(type);
}
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;

Expand Down Expand Up @@ -52,11 +53,11 @@ void shouldSerializeKafkaOperationBinding() throws Exception {
"kafka",
KafkaOperationBinding.builder()
.groupId(SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.enumValues(List.of("myGroupId"))
.build())
.clientId(SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.enumValues(List.of("myClientId"))
.build())
.build()))
Expand Down Expand Up @@ -140,7 +141,7 @@ void shouldSerializeKafkaMessage() throws Exception {
KafkaMessageBinding.builder()
.key(
SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.enumValues(List.of("myKey"))
.build())
.schemaIdLocation("payload")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.math.BigDecimal;
import java.util.Map;
import java.util.Set;

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;

Expand Down Expand Up @@ -58,12 +59,12 @@ void shouldSerializeMQTTServerExample2() throws Exception {
"mqtt",
MQTTServerBinding.builder()
.sessionExpiryInterval(SchemaObject.builder()
.type(SchemaType.INTEGER)
.type(Set.of(SchemaType.INTEGER))
.minimum(new BigDecimal("30"))
.maximum(new BigDecimal("1200"))
.build())
.maximumPacketSize(SchemaObject.builder()
.type(SchemaType.INTEGER)
.type(Set.of(SchemaType.INTEGER))
.minimum(new BigDecimal("256"))
.build())
.build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
Expand Down Expand Up @@ -80,15 +81,15 @@ private AsyncAPI getAsyncAPITestObject(SchemaFormat schemaFormat) {
KafkaMessageBinding.builder()
// FIXME: We should have a SchemaString (Schema<String>)
.key(SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.build())
.build()))
.build();
Map<String, Message> messages = Map.of(message.getMessageId(), message);

SchemaObject groupId = new SchemaObject();
groupId.setEnumValues(List.of("myGroupId"));
groupId.setType(SchemaType.STRING);
groupId.setType(Set.of(SchemaType.STRING));

OperationBinding operationBinding =
KafkaOperationBinding.builder().groupId(groupId).build();
Expand Down Expand Up @@ -126,9 +127,9 @@ private Map<String, ComponentSchema> createPayloadSchema(SchemaFormat schemaForm
switch (schemaFormat) {
case DEFAULT: {
SchemaObject examplePayloadSchema = new SchemaObject();
examplePayloadSchema.setType(SchemaType.OBJECT);
examplePayloadSchema.setType(Set.of(SchemaType.OBJECT));
SchemaObject stringSchema = new SchemaObject();
stringSchema.setType(SchemaType.STRING);
stringSchema.setType(Set.of(SchemaType.STRING));
examplePayloadSchema.setProperties(Map.of("s", stringSchema));
return Map.of("ExamplePayload", ComponentSchema.of(examplePayloadSchema));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;

Expand All @@ -41,16 +42,16 @@ void shouldCreateSimpleAsyncAPI() throws Exception {
var userSignUpMessage = MessageObject.builder()
.messageId("UserSignedUp")
.payload(MessagePayload.of(SchemaObject.builder()
.type(SchemaType.OBJECT)
.type(Set.of(SchemaType.OBJECT))
.properties(Map.of(
"displayName",
SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.description("Name of the user")
.build(),
"email",
SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.format("email")
.description("Email of the user")
.build()))
Expand Down Expand Up @@ -285,11 +286,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws Exception {
.schemas(Map.of(
"lightMeasuredPayload",
ComponentSchema.of(SchemaObject.builder()
.type(SchemaType.OBJECT)
.type(Set.of(SchemaType.OBJECT))
.properties(Map.of(
"lumens",
SchemaObject.builder()
.type(SchemaType.INTEGER)
.type(Set.of(SchemaType.INTEGER))
.minimum(BigDecimal.ZERO)
.description("Light intensity measured in lumens.")
.build(),
Expand All @@ -298,11 +299,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws Exception {
.build()),
"turnOnOffPayload",
ComponentSchema.of(SchemaObject.builder()
.type(SchemaType.OBJECT)
.type(Set.of(SchemaType.OBJECT))
.properties(Map.of(
"command",
SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.enumValues(List.of("on", "off"))
.description("Whether to turn on or off the light.")
.build(),
Expand All @@ -311,11 +312,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws Exception {
.build()),
"dimLightPayload",
ComponentSchema.of(SchemaObject.builder()
.type(SchemaType.OBJECT)
.type(Set.of(SchemaType.OBJECT))
.properties(Map.of(
"percentage",
SchemaObject.builder()
.type(SchemaType.INTEGER)
.type(Set.of(SchemaType.INTEGER))
.description(
"Percentage to which the light should be dimmed to.")
.minimum(BigDecimal.ZERO)
Expand All @@ -326,7 +327,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws Exception {
.build()),
"sentAt",
ComponentSchema.of(SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.format("date-time")
.description("Date and time when the message was sent.")
.build())))
Expand All @@ -350,11 +351,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws Exception {
"commonHeaders",
MessageTrait.builder()
.headers(MessageHeaders.of(SchemaObject.builder()
.type(SchemaType.OBJECT)
.type(Set.of(SchemaType.OBJECT))
.properties(Map.of(
"my-app-header",
SchemaObject.builder()
.type(SchemaType.INTEGER)
.type(Set.of(SchemaType.INTEGER))
.minimum(BigDecimal.ZERO)
.maximum(new BigDecimal("100"))
.build()))
Expand All @@ -367,7 +368,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws Exception {
"kafka",
KafkaOperationBinding.builder()
.clientId(SchemaObject.builder()
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.enumValues(List.of("my-app-id"))
.build())
.build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;

Expand All @@ -35,22 +36,22 @@ void shouldSerializeMessage() throws Exception {
Tag.builder().name("signup").build(),
Tag.builder().name("register").build()))
.headers(MessageHeaders.of(SchemaObject.builder()
.type(SchemaType.OBJECT)
.type(Set.of(SchemaType.OBJECT))
.properties(Map.of(
"correlationId",
SchemaObject.builder()
.description("Correlation ID set by application")
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.build(),
"applicationInstanceId",
SchemaObject.builder()
.description(
"Unique identifier for a given instance of the publishing application")
.type(SchemaType.STRING)
.type(Set.of(SchemaType.STRING))
.build()))
.build()))
.payload(MessagePayload.of(SchemaObject.builder()
.type(SchemaType.OBJECT)
.type(Set.of(SchemaType.OBJECT))
.properties(Map.of(
"user", SchemaReference.toSchema("userCreate"),
"signup", SchemaReference.toSchema("signup")))
Expand Down
Loading
Loading