diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java index da67423f1..d93fd0c61 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java @@ -12,6 +12,7 @@ import io.swagger.v3.core.converter.ModelConverters; import io.swagger.v3.oas.models.media.MapSchema; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -64,6 +65,11 @@ public String register(Class type) { Map schemas = converter.readAll(type); this.definitions.putAll(schemas); + if (schemas.size() == 0 && type.equals(String.class)) { + this.definitions.put("String", new StringSchema()); + return "String"; + } + if (schemas.size() == 1) { return new ArrayList<>(schemas.keySet()).get(0); } diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java index 1413134ab..702b832c1 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java @@ -17,6 +17,7 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; public class DefaultSchemasServiceTest { @@ -29,6 +30,16 @@ public class DefaultSchemasServiceTest { objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); } + @Test + public void string() throws IOException, JSONException { + String modelName = schemasService.register(String.class); + + assertThat(modelName) + .isEqualTo("String"); + + assertNotNull(schemasService.getDefinitions().get(modelName)); + } + @Test public void simpleObject() throws IOException, JSONException { String modelName = schemasService.register(SimpleFoo.class);