Skip to content

Refactor/rename to payload schema object #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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 @@ -5,6 +5,7 @@
import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
import io.github.springwolf.asyncapi.v3.model.components.Components;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -43,7 +44,7 @@ public void shouldAddJsonSchemaExtensionTest() throws JsonProcessingException {
// given
AsyncAPI asyncAPI = createAsyncApi();
SchemaObject schemaObject = new SchemaObject();
schemaObject.setType("object");
schemaObject.setType(SchemaType.OBJECT);
asyncAPI.getComponents().setSchemas(Map.of("schema", schemaObject));

when(jsonSchemaGenerator.fromSchema(any(), any())).thenReturn("mock-string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageReference;
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import io.github.springwolf.core.asyncapi.schemas.SwaggerSchemaUtil;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.media.ArraySchema;
Expand Down Expand Up @@ -50,14 +51,14 @@ public void validateJsonSchemaTest(String expectedJsonSchema, Supplier<Schema<?>

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

SchemaObject stringSchema = new SchemaObject();
stringSchema.setType("string");
stringSchema.setType(SchemaType.STRING);

Map<String, SchemaObject> definitions =
Map.of("StringRef", stringSchema, "PingSchema", pingSchema, "PongSchema", pongSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.springwolf.asyncapi.v3.model.operation.Operation;
import io.github.springwolf.asyncapi.v3.model.operation.OperationAction;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import io.github.springwolf.asyncapi.v3.model.server.Server;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -52,11 +53,11 @@ void shouldSerializeKafkaOperationBinding() throws IOException {
"kafka",
KafkaOperationBinding.builder()
.groupId(SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.enumValues(List.of("myGroupId"))
.build())
.clientId(SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.enumValues(List.of("myClientId"))
.build())
.build()))
Expand Down Expand Up @@ -140,7 +141,7 @@ void shouldSerializeKafkaMessage() throws IOException {
KafkaMessageBinding.builder()
.key(
SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.enumValues(List.of("myKey"))
.build())
.schemaIdLocation("payload")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.springwolf.asyncapi.v3.jackson.DefaultAsyncApiSerializerService;
import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import io.github.springwolf.asyncapi.v3.model.server.Server;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -58,12 +59,12 @@ void shouldSerializeMQTTServerExample2() throws IOException {
"mqtt",
MQTTServerBinding.builder()
.sessionExpiryInterval(SchemaObject.builder()
.type("integer")
.type(SchemaType.INTEGER)
.minimum(new BigDecimal("30"))
.maximum(new BigDecimal("1200"))
.build())
.maximumPacketSize(SchemaObject.builder()
.type("integer")
.type(SchemaType.INTEGER)
.minimum(new BigDecimal("256"))
.build())
.build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ private AsyncAPI getAsyncAPITestObject() {
"kafka",
KafkaMessageBinding.builder()
// FIXME: We should have a SchemaString (Schema<String>)
.key(SchemaObject.builder().type("string").build())
.key(SchemaObject.builder()
.type(SchemaType.STRING)
.build())
.build()))
.build();
Map<String, Message> messages = Map.of(message.getMessageId(), message);
Expand Down Expand Up @@ -100,9 +102,9 @@ private AsyncAPI getAsyncAPITestObject() {
.build();

SchemaObject examplePayloadSchema = new SchemaObject();
examplePayloadSchema.setType("object");
examplePayloadSchema.setType(SchemaType.OBJECT);
SchemaObject stringSchema = new SchemaObject();
stringSchema.setType("string");
stringSchema.setType(SchemaType.STRING);
examplePayloadSchema.setProperties(Map.of("s", stringSchema));
Map<String, SchemaObject> schemas = Map.of("ExamplePayload", examplePayloadSchema);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.springwolf.asyncapi.v3.model.operation.OperationTraits;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import io.github.springwolf.asyncapi.v3.model.security_scheme.SecurityScheme;
import io.github.springwolf.asyncapi.v3.model.security_scheme.SecurityType;
import io.github.springwolf.asyncapi.v3.model.server.Server;
Expand All @@ -40,16 +41,16 @@ void shouldCreateSimpleAsyncAPI() throws IOException {
var userSignUpMessage = MessageObject.builder()
.messageId("UserSignedUp")
.payload(MessagePayload.of(SchemaObject.builder()
.type("object")
.type(SchemaType.OBJECT)
.properties(Map.of(
"displayName",
SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.description("Name of the user")
.build(),
"email",
SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.format("email")
.description("Email of the user")
.build()))
Expand Down Expand Up @@ -284,11 +285,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
.schemas(Map.of(
"lightMeasuredPayload",
SchemaObject.builder()
.type("object")
.type(SchemaType.OBJECT)
.properties(Map.of(
"lumens",
SchemaObject.builder()
.type("integer")
.type(SchemaType.INTEGER)
.minimum(BigDecimal.ZERO)
.description("Light intensity measured in lumens.")
.build(),
Expand All @@ -297,11 +298,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
.build(),
"turnOnOffPayload",
SchemaObject.builder()
.type("object")
.type(SchemaType.OBJECT)
.properties(Map.of(
"command",
SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.enumValues(List.of("on", "off"))
.description("Whether to turn on or off the light.")
.build(),
Expand All @@ -310,11 +311,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
.build(),
"dimLightPayload",
SchemaObject.builder()
.type("object")
.type(SchemaType.OBJECT)
.properties(Map.of(
"percentage",
SchemaObject.builder()
.type("integer")
.type(SchemaType.INTEGER)
.description(
"Percentage to which the light should be dimmed to.")
.minimum(BigDecimal.ZERO)
Expand All @@ -325,7 +326,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
.build(),
"sentAt",
SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.format("date-time")
.description("Date and time when the message was sent.")
.build()))
Expand All @@ -349,11 +350,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
"commonHeaders",
MessageTrait.builder()
.headers(MessageHeaders.of(SchemaObject.builder()
.type("object")
.type(SchemaType.OBJECT)
.properties(Map.of(
"my-app-header",
SchemaObject.builder()
.type("integer")
.type(SchemaType.INTEGER)
.minimum(BigDecimal.ZERO)
.maximum(new BigDecimal("100"))
.build()))
Expand All @@ -366,7 +367,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
"kafka",
KafkaOperationBinding.builder()
.clientId(SchemaObject.builder()
.type("string")
.type(SchemaType.STRING)
.enumValues(List.of("my-app-id"))
.build())
.build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageTrait;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import org.junit.jupiter.api.Test;

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