Skip to content

Commit

Permalink
test(core): use wrapper class around generics (i.e. extends ArrayList) (
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback authored Nov 17, 2023
1 parent 167abbe commit 97db608
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -149,6 +161,9 @@ private static class DocumentedSimpleFoo {
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
private SimpleFoo f;

@Schema(description = "List without example")
private List<String> ls_plain;

@Schema(description = "Map with example", example = "{\"key1\": \"value1\"}")
private Map<String, String> mss;

Expand All @@ -169,6 +184,10 @@ private static class ArrayFoo {
private List<SimpleFoo> fList;
}

@Data
@NoArgsConstructor
private static class ListWrapper extends ArrayList<String> {}

@Data
@NoArgsConstructor
private static class FooWithEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -39,6 +47,7 @@
"b" : true,
"s" : "string"
},
"ls_plain" : [ "string" ],
"mss" : {
"key1" : "value1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ListWrapper" : {
"type" : "array",
"properties" : {
"empty" : {
"type" : "boolean"
}
},
"example" : [ "string" ],
"items" : {
"type" : "string"
}
}
}

0 comments on commit 97db608

Please sign in to comment.