Skip to content

Commit 13e287a

Browse files
committed
fix: StackOverflowError with recursive data model #4852
1 parent 8ee4735 commit 13e287a

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/util/PrimitiveType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public DateSchema createProperty() {
198198
}
199199
@Override
200200
public Schema createProperty31() {
201-
return new JsonSchema().typesItem("object").type("object").format("date");
201+
return new JsonSchema().typesItem("string").type("string").format("date");
202202
}
203203
},
204204
DATE_TIME(java.util.Date.class, "date-time") {
@@ -208,7 +208,7 @@ public DateTimeSchema createProperty() {
208208
}
209209
@Override
210210
public Schema createProperty31() {
211-
return new JsonSchema().typesItem("object").type("object").format("date-time");
211+
return new JsonSchema().typesItem("string").type("string").format("date-time");
212212
}
213213
},
214214
PARTIAL_TIME(java.time.LocalTime.class, "partial-time") {
@@ -218,7 +218,7 @@ public Schema createProperty() {
218218
}
219219
@Override
220220
public Schema createProperty31() {
221-
return new JsonSchema().typesItem("object").type("object").format("partial-time");
221+
return new JsonSchema().typesItem("string").type("string").format("partial-time");
222222
}
223223
},
224224
FILE(java.io.File.class, "file") {
@@ -572,7 +572,7 @@ private static <K> void addMultiKeys(Map<K, Collection<PrimitiveType>> map, Prim
572572
}
573573
}
574574

575-
public static class DateStub {
575+
private static class DateStub {
576576
private DateStub() {
577577
}
578578
}

modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/Ticket2992Test.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@ public void testLocalTime() throws Exception {
1818

1919
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
2020

21+
Schema model = context
22+
.resolve(new AnnotatedType(TestObject2992.class));
23+
24+
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "LocalTime:\n" +
25+
" type: object\n" +
26+
" properties:\n" +
27+
" hour:\n" +
28+
" type: integer\n" +
29+
" format: int32\n" +
30+
" minute:\n" +
31+
" type: integer\n" +
32+
" format: int32\n" +
33+
" second:\n" +
34+
" type: integer\n" +
35+
" format: int32\n" +
36+
" nano:\n" +
37+
" type: integer\n" +
38+
" format: int32\n" +
39+
"TestObject2992:\n" +
40+
" type: object\n" +
41+
" properties:\n" +
42+
" name:\n" +
43+
" type: string\n" +
44+
" a:\n" +
45+
" $ref: \"#/components/schemas/LocalTime\"\n" +
46+
" b:\n" +
47+
" $ref: \"#/components/schemas/LocalTime\"\n" +
48+
" c:\n" +
49+
" $ref: \"#/components/schemas/LocalTime\"\n" +
50+
" d:\n" +
51+
" type: string\n" +
52+
" format: date-time\n" +
53+
" e:\n" +
54+
" type: string\n" +
55+
" format: date-time\n" +
56+
" f:\n" +
57+
" type: string\n" +
58+
" format: date-time");
59+
60+
PrimitiveType.enablePartialTime();
61+
context = new ModelConverterContextImpl(modelResolver);
62+
2163
context
2264
.resolve(new AnnotatedType(TestObject2992.class));
2365

modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/APIResponsesResourceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ private Schema getResponseSchema(String path) {
5555
public void testSchemaAPIResource31(String schema) {
5656
Schema responseSchema = getResponseSchema(schema);
5757

58+
// Debug output for type and types
59+
System.out.println("Schema path: " + schema);
60+
System.out.println("type: " + responseSchema.getType());
61+
System.out.println("types: " + responseSchema.getTypes());
62+
5863
// Value of field "type" must equal value of field "types"
5964
assertEquals(responseSchema.getType(), responseSchema.getTypes().iterator().next());
6065
}

modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/resources/APIResponsesResource.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.v3.jaxrs2.resources;
22

3-
import io.swagger.v3.core.util.PrimitiveType;
43
import io.swagger.v3.oas.annotations.media.Content;
54
import io.swagger.v3.oas.annotations.media.Schema;
65
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -148,16 +147,6 @@ public void postBigDecimalSchemaContent() { }
148147
})
149148
public void postNumberSchemaContent() { }
150149

151-
@POST
152-
@Path("postDateStubSchemaContent")
153-
@ApiResponses({
154-
@ApiResponse(
155-
responseCode = "200",
156-
content = @Content(schema = @Schema(implementation = PrimitiveType.DateStub.class))
157-
)
158-
})
159-
public void postDateStubSchemaContent() { }
160-
161150
@POST
162151
@Path("postDateSchemaContent")
163152
@ApiResponses({

0 commit comments

Comments
 (0)