Skip to content

Commit 5a92e3a

Browse files
authored
Merge pull request #4720 from swagger-api/Issue-4679-OAS31-schema-implementation-support
refs #4679 - fix @Schema#implementation resolving for OAS 3.1
2 parents e6d3fa3 + c37b72c commit 5a92e3a

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,9 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
683683
!(a instanceof io.swagger.v3.oas.annotations.media.ArraySchema)) {
684684
ctxAnnotations31List.add(a);
685685
}
686+
if ((ctxSchema != null) && (!ctxSchema.implementation().equals(Void.class) || StringUtils.isNotEmpty(ctxSchema.type()))) {
687+
ctxAnnotations31List.add(a);
688+
}
686689
}
687690
ctxAnnotation31 = ctxAnnotations31List.toArray(new Annotation[ctxAnnotations31List.size()]);
688691
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.swagger.v3.core.resolving;
2+
3+
import io.swagger.v3.core.converter.ModelConverters;
4+
import io.swagger.v3.core.matchers.SerializationMatchers;
5+
import io.swagger.v3.core.util.Yaml;
6+
import io.swagger.v3.core.util.Yaml31;
7+
import io.swagger.v3.oas.annotations.media.Schema;
8+
import org.testng.annotations.Test;
9+
10+
import java.util.Map;
11+
12+
public class Ticket4679Test extends SwaggerTestBase{
13+
14+
@Test(description = "Custom schema implementation in property overrides type value")
15+
public void testCustomSchemaImplementation() {
16+
17+
String expectedYaml = "ModelWithCustomSchemaImplementationInProperty:\n" +
18+
" properties:\n" +
19+
" exampleField:\n" +
20+
" type: integer\n" +
21+
" format: int32\n" +
22+
" secondExampleField:\n" +
23+
" type: string\n";
24+
25+
Map<String, io.swagger.v3.oas.models.media.Schema> stringSchemaMap = ModelConverters.getInstance(true).readAll(ModelWithCustomSchemaImplementationInProperty.class);
26+
SerializationMatchers.assertEqualsToYaml31(stringSchemaMap, expectedYaml);
27+
}
28+
29+
static class ModelWithCustomSchemaImplementationInProperty {
30+
31+
@Schema(implementation = Integer.class)
32+
private String exampleField;
33+
34+
@Schema(type = "string")
35+
private Integer secondExampleField;
36+
37+
public String getExampleField() {
38+
return exampleField;
39+
}
40+
41+
public void setExampleField(String exampleField) {
42+
this.exampleField = exampleField;
43+
}
44+
45+
public Integer getSecondExampleField() {
46+
return secondExampleField;
47+
}
48+
49+
public void setSecondExampleField(Integer secondExampleField) {
50+
this.secondExampleField = secondExampleField;
51+
}
52+
53+
54+
}
55+
}

0 commit comments

Comments
 (0)