|
1 | 1 |
|
2 | 2 | package cz.habarta.typescript.generator; |
3 | 3 |
|
| 4 | +import com.fasterxml.jackson.annotation.JsonTypeInfo; |
| 5 | +import cz.habarta.typescript.generator.compiler.ModelCompiler; |
| 6 | +import cz.habarta.typescript.generator.emitter.TsModel; |
| 7 | +import cz.habarta.typescript.generator.parser.Jackson2Parser; |
| 8 | +import cz.habarta.typescript.generator.parser.Model; |
4 | 9 | import java.lang.reflect.*; |
5 | 10 | import java.util.*; |
| 11 | +import org.hamcrest.CoreMatchers; |
6 | 12 | import org.junit.*; |
7 | 13 |
|
8 | 14 |
|
@@ -37,6 +43,46 @@ public void testExclusionPattern() throws Exception { |
37 | 43 | Assert.assertEquals("{ [index: string]: any }[]", TestUtils.compileType(settings, javaType).toString()); |
38 | 44 | } |
39 | 45 |
|
| 46 | + @Test |
| 47 | + public void testIntermediateInterfacesWithoutTypeParams() throws Exception { |
| 48 | + final Settings settings = TestUtils.settings(); |
| 49 | + |
| 50 | + final Jackson2Parser jacksonParser = new Jackson2Parser(settings, new DefaultTypeProcessor()); |
| 51 | + final Model model = jacksonParser.parseModel(Implementation.class); |
| 52 | + final ModelCompiler modelCompiler = new TypeScriptGenerator(settings).getModelCompiler(); |
| 53 | + |
| 54 | + final TsModel result = modelCompiler.javaToTypeScript(model); |
| 55 | + |
| 56 | + Assert.assertThat( |
| 57 | + result.getBean(WithoutTypeParam.class).getProperties().get(0).tsType, |
| 58 | + CoreMatchers.instanceOf(TsType.UnionType.class) |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testIntermediateInterfacesWithTypeParams() throws Exception { |
| 64 | + final Settings settings = TestUtils.settings(); |
| 65 | + |
| 66 | + final Jackson2Parser jacksonParser = new Jackson2Parser(settings, new DefaultTypeProcessor()); |
| 67 | + final Model model = jacksonParser.parseModel(Implementation.class); |
| 68 | + final ModelCompiler modelCompiler = new TypeScriptGenerator(settings).getModelCompiler(); |
| 69 | + |
| 70 | + final TsModel result = modelCompiler.javaToTypeScript(model); |
| 71 | + |
| 72 | + Assert.assertThat( |
| 73 | + result.getBean(WithTypeParam.class).getProperties().get(0).tsType, |
| 74 | + CoreMatchers.instanceOf(TsType.UnionType.class) |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) |
| 79 | + private static interface WithoutTypeParam {} |
| 80 | + |
| 81 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) |
| 82 | + private static interface WithTypeParam<T> {} |
| 83 | + |
| 84 | + private static class Implementation implements WithTypeParam<Integer>, WithoutTypeParam {} |
| 85 | + |
40 | 86 | private static Settings getTestSettings(String... excludedClassNames) { |
41 | 87 | final Settings settings = TestUtils.settings(); |
42 | 88 | settings.mapDate = DateMapping.asString; |
|
0 commit comments