-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Possibility to map Java Map as TypeScript Record (#706)
- Loading branch information
1 parent
0188fd0
commit c19d407
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
typescript-generator-core/src/main/java/cz/habarta/typescript/generator/MapMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
package cz.habarta.typescript.generator; | ||
|
||
|
||
public enum MapMapping { | ||
asIndexedArray, asRecord | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
typescript-generator-core/src/test/java/cz/habarta/typescript/generator/MapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
package cz.habarta.typescript.generator; | ||
|
||
import java.util.Map; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
public class MapTest { | ||
|
||
public static class ClassWithMap { | ||
public Map<String, Person> people; | ||
} | ||
|
||
@Test | ||
public void testDefault() { | ||
final Settings settings = TestUtils.settings(); | ||
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(ClassWithMap.class)); | ||
Assertions.assertTrue(output.contains("people: { [index: string]: Person }")); | ||
} | ||
|
||
@Test | ||
public void testIndexedArray() { | ||
final Settings settings = TestUtils.settings(); | ||
settings.mapMap = MapMapping.asIndexedArray; | ||
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(ClassWithMap.class)); | ||
Assertions.assertTrue(output.contains("people: { [index: string]: Person }")); | ||
} | ||
|
||
@Test | ||
public void testRecord() { | ||
final Settings settings = TestUtils.settings(); | ||
settings.mapMap = MapMapping.asRecord; | ||
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(ClassWithMap.class)); | ||
Assertions.assertTrue(output.contains("people: Record<string, Person>")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters