From 97db608c504b13e07397363a80e8c0dc4ef463a5 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Fri, 17 Nov 2023 14:03:29 +0100 Subject: [PATCH] test(core): use wrapper class around generics (i.e. extends ArrayList) (#451) --- .../schemas/DefaultSchemasServiceTest.java | 19 +++++++++++++++++++ .../schemas/documented-definitions.json | 9 +++++++++ .../schemas/generics-wrapper-definitions.json | 14 ++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 springwolf-core/src/test/resources/schemas/generics-wrapper-definitions.json 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 5bc2fa108..604c132f4 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 @@ -22,6 +22,7 @@ import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.time.OffsetDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; @@ -86,6 +87,17 @@ void getComplexDefinitions() throws IOException { assertEquals(expected, actualDefinitions); } + @Test + void getListWrapperDefinitions() throws IOException { + schemasService.register(ListWrapper.class); + + String actualDefinitions = objectMapper.writer(printer).writeValueAsString(schemasService.getDefinitions()); + String expected = jsonResource("/schemas/generics-wrapper-definitions.json"); + + System.out.println("Got: " + actualDefinitions); + assertEquals(expected, actualDefinitions); + } + @Test void classWithSchemaAnnotation() { String modelName = schemasService.register(ClassWithSchemaAnnotation.class); @@ -149,6 +161,9 @@ private static class DocumentedSimpleFoo { @Schema(requiredMode = Schema.RequiredMode.REQUIRED) private SimpleFoo f; + @Schema(description = "List without example") + private List ls_plain; + @Schema(description = "Map with example", example = "{\"key1\": \"value1\"}") private Map mss; @@ -169,6 +184,10 @@ private static class ArrayFoo { private List fList; } + @Data + @NoArgsConstructor + private static class ListWrapper extends ArrayList {} + @Data @NoArgsConstructor private static class FooWithEnum { diff --git a/springwolf-core/src/test/resources/schemas/documented-definitions.json b/springwolf-core/src/test/resources/schemas/documented-definitions.json index 952ff5b0f..399f473be 100644 --- a/springwolf-core/src/test/resources/schemas/documented-definitions.json +++ b/springwolf-core/src/test/resources/schemas/documented-definitions.json @@ -14,6 +14,14 @@ "f" : { "$ref" : "#/components/schemas/SimpleFoo" }, + "ls_plain" : { + "type" : "array", + "description" : "List without example", + "items" : { + "type" : "string", + "description" : "List without example" + } + }, "mss" : { "type" : "object", "description" : "Map with example", @@ -39,6 +47,7 @@ "b" : true, "s" : "string" }, + "ls_plain" : [ "string" ], "mss" : { "key1" : "value1" }, diff --git a/springwolf-core/src/test/resources/schemas/generics-wrapper-definitions.json b/springwolf-core/src/test/resources/schemas/generics-wrapper-definitions.json new file mode 100644 index 000000000..32d7caa2a --- /dev/null +++ b/springwolf-core/src/test/resources/schemas/generics-wrapper-definitions.json @@ -0,0 +1,14 @@ +{ + "ListWrapper" : { + "type" : "array", + "properties" : { + "empty" : { + "type" : "boolean" + } + }, + "example" : [ "string" ], + "items" : { + "type" : "string" + } + } +} \ No newline at end of file