|
| 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