Skip to content

Commit fec5b2f

Browse files
sam0r040timonback
andauthored
fix(core): SchemaObjectBuilder.type(String) is null safe (#1507)
* fix(core): SchemaObjectBuilder.type(String) is null safe Co-authored-by: Timon Back <[email protected]> * test(core): Add `@Schema` annotation in combination with `@JsonSubTypes` --------- Co-authored-by: Timon Back <[email protected]>
1 parent e7fd6a0 commit fec5b2f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/schema/SchemaObject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ public SchemaObjectBuilder type(Set<String> type) {
162162
}
163163

164164
public SchemaObjectBuilder type(String type) {
165-
this.type = Set.of(type);
165+
if (type != null) {
166+
this.type = Set.of(type);
167+
}
166168
return this;
167169
}
168170
}

springwolf-core/src/test/java/io/github/springwolf/core/integrationtests/application/polymorphic/PolymorphicPayloadApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.annotation.JsonTypeInfo;
66
import io.github.springwolf.core.asyncapi.annotations.AsyncListener;
77
import io.github.springwolf.core.asyncapi.annotations.AsyncOperation;
8+
import io.swagger.v3.oas.annotations.media.Schema;
89
import org.springframework.boot.autoconfigure.SpringBootApplication;
910
import org.springframework.context.annotation.Bean;
1011

@@ -28,6 +29,7 @@ public record Payload(Pet pet) {}
2829
@JsonSubTypes.Type(value = Dog.class, name = "dog"),
2930
@JsonSubTypes.Type(value = Cat.class, name = "cat"),
3031
})
32+
@Schema(oneOf = {Dog.class, Cat.class})
3133
public interface Pet {
3234
String getType();
3335
}

0 commit comments

Comments
 (0)