Skip to content

Commit 405d02b

Browse files
authored
Merge pull request #3707 from swagger-api/ticket-3703
2 parents f77c625 + 72aeb24 commit 405d02b

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static AnnotatedType unwrapOptional(AnnotatedType type) {
4242
.name(type.getName())
4343
.parent(type.getParent())
4444
.jsonUnwrappedHandler(type.getJsonUnwrappedHandler())
45-
.skipOverride(true)
45+
.skipOverride(type.isSkipOverride())
4646
.schemaProperty(type.isSchemaProperty())
4747
.ctxAnnotations(type.getCtxAnnotations())
4848
.resolveAsRef(type.isResolveAsRef())
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package io.swagger.v3.core.resolving;
2+
3+
import io.swagger.v3.core.converter.AnnotatedType;
4+
import io.swagger.v3.core.converter.ModelConverterContextImpl;
5+
import io.swagger.v3.core.jackson.ModelResolver;
6+
import io.swagger.v3.core.matchers.SerializationMatchers;
7+
import io.swagger.v3.oas.models.media.Schema;
8+
import org.testng.annotations.Test;
9+
10+
import java.util.Optional;
11+
12+
public class Ticket3703Test extends SwaggerTestBase {
13+
14+
@Test
15+
public void testSelfReferencingOptional() throws Exception {
16+
17+
final ModelResolver modelResolver = new ModelResolver(mapper());
18+
19+
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
20+
21+
Schema model = context
22+
.resolve(new AnnotatedType(ModelContainer.class));
23+
24+
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "Model:\n" +
25+
" type: object\n" +
26+
" properties:\n" +
27+
" model:\n" +
28+
" $ref: '#/components/schemas/Model'\n" +
29+
"ModelContainer:\n" +
30+
" type: object\n" +
31+
" properties:\n" +
32+
" model:\n" +
33+
" $ref: '#/components/schemas/Model'\n" +
34+
" bytes:\n" +
35+
" type: string\n" +
36+
" format: byte");
37+
38+
}
39+
40+
static class ModelContainer {
41+
public Optional<Model> model;
42+
43+
@io.swagger.v3.oas.annotations.media.Schema(type = "string", format = "byte")
44+
public Optional<Bytes> getBytes() {
45+
return null;
46+
}
47+
48+
}
49+
50+
static class Model {
51+
public Optional<Model> model;
52+
}
53+
54+
static class Bytes {
55+
public String foo;
56+
public String bar;
57+
}
58+
59+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ public void testTicket3587() {
22482248
SerializationMatchers.assertEqualsToYamlExact(openAPI, yaml);
22492249
}
22502250

2251-
@Test(description = "Optional hanlding")
2251+
@Test(description = "Optional handling")
22522252
public void testTicket3624() {
22532253
Reader reader = new Reader(new OpenAPI());
22542254

0 commit comments

Comments
 (0)