|
| 1 | +package io.swagger.v3.core.resolving; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonSubTypes; |
| 4 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
| 5 | +import com.fasterxml.jackson.annotation.JsonView; |
| 6 | +import io.swagger.v3.core.converter.AnnotatedType; |
| 7 | +import io.swagger.v3.core.converter.ModelConverterContextImpl; |
| 8 | +import io.swagger.v3.core.jackson.ModelResolver; |
| 9 | +import io.swagger.v3.core.matchers.SerializationMatchers; |
| 10 | +import org.testng.annotations.Test; |
| 11 | + |
| 12 | +import java.lang.annotation.Annotation; |
| 13 | + |
| 14 | +import static com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME; |
| 15 | + |
| 16 | +public class Ticket4239Test extends SwaggerTestBase { |
| 17 | + |
| 18 | + public interface Input {} |
| 19 | + |
| 20 | + public interface Output {} |
| 21 | + |
| 22 | + @JsonTypeInfo(use = NAME) |
| 23 | + @JsonSubTypes({ |
| 24 | + @JsonSubTypes.Type(value = A1.class), |
| 25 | + }) |
| 26 | + public static abstract class A { |
| 27 | + @JsonView(Input.class) |
| 28 | + public String a_in; |
| 29 | + @JsonView(Output.class) |
| 30 | + public String a_out; |
| 31 | + } |
| 32 | + |
| 33 | + public static class A1 extends A { |
| 34 | + @JsonView(Input.class) |
| 35 | + public String a1_in; |
| 36 | + @JsonView(Output.class) |
| 37 | + public String a1_out; |
| 38 | + } |
| 39 | + |
| 40 | + private static final JsonView VIEW_OUTPUT = new JsonView() { |
| 41 | + public Class<? extends Annotation> annotationType() { |
| 42 | + return JsonView.class; |
| 43 | + } |
| 44 | + public Class<?>[] value() { |
| 45 | + return new Class[] {Output.class}; |
| 46 | + } |
| 47 | + }; |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testJsonValueSchemaAnnotation() { |
| 51 | + |
| 52 | + final ModelResolver modelResolver = new ModelResolver(mapper()); |
| 53 | + |
| 54 | + ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver); |
| 55 | + |
| 56 | + AnnotatedType type = new AnnotatedType(Ticket4239Test.A.class).jsonViewAnnotation(VIEW_OUTPUT); |
| 57 | + |
| 58 | + context.resolve(type); |
| 59 | + |
| 60 | + SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "A1_Output:\n" + |
| 61 | + " type: object\n" + |
| 62 | + " allOf:\n" + |
| 63 | + " - $ref: '#/components/schemas/A_Output'\n" + |
| 64 | + " - type: object\n" + |
| 65 | + " properties:\n" + |
| 66 | + " a1_out:\n" + |
| 67 | + " type: string\n" + |
| 68 | + "A_Output:\n" + |
| 69 | + " type: object\n" + |
| 70 | + " properties:\n" + |
| 71 | + " a_out:\n" + |
| 72 | + " type: string\n"); |
| 73 | + |
| 74 | + } |
| 75 | +} |
0 commit comments