@@ -69,6 +69,31 @@ private static class CCircle2 implements IShape2 {
6969 public double radius ;
7070 }
7171
72+ @ JsonTypeInfo (use = JsonTypeInfo .Id .NAME , property = "kind" )
73+ @ JsonSubTypes ({
74+ @ JsonSubTypes .Type (DiamondB1 .class ),
75+ @ JsonSubTypes .Type (DiamondB2 .class ),
76+ @ JsonSubTypes .Type (DiamondC .class ),
77+ })
78+ private static interface DiamondA {
79+ public String getA ();
80+ }
81+
82+ @ JsonTypeName ("b1" )
83+ private static interface DiamondB1 extends DiamondA {
84+ public String getB1 ();
85+ }
86+
87+ @ JsonTypeName ("b2" )
88+ private static interface DiamondB2 extends DiamondA {
89+ public String getB2 ();
90+ }
91+
92+ @ JsonTypeName ("c" )
93+ private static interface DiamondC extends DiamondB1 , DiamondB2 {
94+ public String getC ();
95+ }
96+
7297 @ Test
7398 public void testTaggedUnions () {
7499 final Settings settings = TestUtils .settings ();
@@ -176,4 +201,37 @@ public void testTaggedUnionsDisabled() {
176201 Assert .assertEquals (expected , output );
177202 }
178203
204+ @ Test
205+ public void testTaggedUnionsWithDiamond () {
206+ final Settings settings = TestUtils .settings ();
207+ final String output = new TypeScriptGenerator (settings ).generateTypeScript (Input .from (DiamondA .class ));
208+ System .out .println (output );
209+ final String expected = (
210+ "\n " +
211+ "interface DiamondA {\n " +
212+ " kind: 'b1' | 'c' | 'b2';\n " +
213+ " a: string;\n " +
214+ "}\n " +
215+ "\n " +
216+ "interface DiamondB1 extends DiamondA {\n " +
217+ " kind: 'b1' | 'c';\n " +
218+ " b1: string;\n " +
219+ "}\n " +
220+ "\n " +
221+ "interface DiamondB2 extends DiamondA {\n " +
222+ " kind: 'b2' | 'c';\n " +
223+ " b2: string;\n " +
224+ "}\n " +
225+ "\n " +
226+ "interface DiamondC extends DiamondB1, DiamondB2 {\n " +
227+ " kind: 'c';\n " +
228+ " c: string;\n " +
229+ "}\n " +
230+ "\n " +
231+ "type DiamondAUnion = DiamondB1 | DiamondB2 | DiamondC;\n " +
232+ ""
233+ ).replace ('\'' , '"' );
234+ Assert .assertEquals (expected , output );
235+ }
236+
179237}
0 commit comments