diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java index ca31f7ed4..f10285c76 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/schemas/SwaggerSchemaMapper.java @@ -207,7 +207,7 @@ private static void assignType(Schema swaggerSchema, SchemaObject.SchemaObjectBu String schemaType = swaggerSchema.getType(); if (!types.contains(schemaType)) { // required while swagger v2 does not populate types - builder.type(Set.of(schemaType)); + builder.type(schemaType == null ? Set.of() : Set.of(schemaType)); return; } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java index 74b856717..1822cb32b 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/components/SwaggerSchemaMapperTest.java @@ -223,6 +223,21 @@ void mapType() { assertThat(componentSchema.getSchema().getType()).containsExactly(schema.getType()); } + @Test + void mapNullTypeForComposedSchema() { + // given + Schema schema = new Schema<>(); + // no type set - simulates a composed schema (allOf/oneOf/anyOf) with null type + schema.addAllOfItem(new Schema<>()); + + // when + ComponentSchema componentSchema = swaggerSchemaMapper.mapSchema(schema); + + // then - should not throw NPE, type should be empty + assertThat(componentSchema.getSchema()).isNotNull(); + assertThat(componentSchema.getSchema().getType()).isNullOrEmpty(); + } + @Test void mapProperties() { // given @@ -639,6 +654,7 @@ void mapMaxItems() { @Nested class MapToSwagger { + @Test void mapNameAndTitle() { // given