TypeScript mapper core module


License

License

GroupId

GroupId

io.github.daniloarcidiacono.typescriptmapper
ArtifactId

ArtifactId

typescript-mapper-core
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

TypeScript mapper core module
TypeScript mapper core module

Download typescript-mapper-core

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.daniloarcidiacono.typescriptmapper/typescript-mapper-core/ -->
<dependency>
    <groupId>io.github.daniloarcidiacono.typescriptmapper</groupId>
    <artifactId>typescript-mapper-core</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.daniloarcidiacono.typescriptmapper/typescript-mapper-core/
implementation 'io.github.daniloarcidiacono.typescriptmapper:typescript-mapper-core:0.1.0'
// https://jarcasting.com/artifacts/io.github.daniloarcidiacono.typescriptmapper/typescript-mapper-core/
implementation ("io.github.daniloarcidiacono.typescriptmapper:typescript-mapper-core:0.1.0")
'io.github.daniloarcidiacono.typescriptmapper:typescript-mapper-core:jar:0.1.0'
<dependency org="io.github.daniloarcidiacono.typescriptmapper" name="typescript-mapper-core" rev="0.1.0">
  <artifact name="typescript-mapper-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.daniloarcidiacono.typescriptmapper', module='typescript-mapper-core', version='0.1.0')
)
libraryDependencies += "io.github.daniloarcidiacono.typescriptmapper" % "typescript-mapper-core" % "0.1.0"
[io.github.daniloarcidiacono.typescriptmapper/typescript-mapper-core "0.1.0"]

Dependencies

compile (4)

Group / Artifact Type Version
io.github.daniloarcidiacono : typescript-template jar 0.0.1
com.fasterxml.jackson.core : jackson-databind jar 2.9.5
org.reflections : reflections jar 0.9.11
org.slf4j : slf4j-api jar 1.7.25

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-engine jar

Project Modules

There are no modules declared in this project.

Maven Central codecov CircleCI License: MIT

What?

Typescript mapper is a tool for generating TypeScript .d.ts files from Java source code.

See the CHANGELOG for a more complete list of available features.

How?

Include the plugin in your Maven project:

src/pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <typescript-mapper.version>LATEST</typescript-mapper.version>
    </properties>

    <dependencies>
        <!-- For annotations -->
        <dependency>
            <groupId>io.github.daniloarcidiacono.typescriptmapper</groupId>
            <artifactId>typescript-mapper-core</artifactId>
            <version>${typescript-mapper.version}</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>io.github.daniloarcidiacono.typescriptmapper</groupId>
                <artifactId>typescript-mapper-maven-plugin</artifactId>
                <version>${typescript-mapper.version}</version>
                <configuration>
                    <basePackage>com.example.myapp</basePackage>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>map</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Consider the following classes:

src/main/java/com/example/myapp/domain/Person.java

package com.example.myapp.domain;

import com.example.myapp.info.Tag;
import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptComments;
import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptDTO;
import java.util.List;
import java.util.Map;

@TypescriptDTO
public class Person {
    @TypescriptComments("The name of the domain.")
    private String name;
    private int age;
    private boolean hasChildren;
    private List<Tag> tags;

    @TypescriptComments({
        "The emails of the domain.",
        "Key is provider, value is email."
    })
    private Map<String, String> emails;
    
    // ... rest of the code ...
}

src/main/java/com/example/myapp/info/Tag.java

package com.example.myapp.info;

import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptComments;
import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptDTO;
import io.github.daniloarcidiacono.typescriptmapper.core.annotation.TypescriptField;

@TypescriptDTO
@TypescriptComments("Colored tag.")
public class Tag {
    private String name;

    @TypescriptComments("Optional tag color")
    @TypescriptField(required = false)
    private Color color;
    
    // ... rest of the code ...
}

@TypescriptDTO
@TypescriptComments("Tag colors")
enum Color {
    RED,
    GREEN
}

Running mvn compile produces the following output:

target/mapped/com/example/myapp/domain.ts

/**
 * This file is automatically generated by TypescriptMapper.
 * Do not modify this file -- YOUR CHANGES WILL BE ERASED!
 */
import { Tag } from './info';
export interface Person {
	// The name of the domain.
	name: string;
	age: number;
	hasChildren: boolean;
	tags: Tag[];

	/**
	 * The emails of the domain.
	 * Key is provider, value is email.
	 */
	emails: { [ index: string ]: string };
}

target/mapped/com/example/myapp/info.ts

/**
 * This file is automatically generated by TypescriptMapper.
 * Do not modify this file -- YOUR CHANGES WILL BE ERASED!
 */
// Colored tag.
export interface Tag {
	name: string;

	// Optional tag color
	color?: Color;
}

// Tag colors
export enum Color {
	RED = 'RED',
	GREEN = 'GREEN'
}

The folder structure can be customized with any logic (the imports will be adjusted accordingly).

Why?

Type-safe DTOs exchanged by back-end and front-end components.

Where?

The latest version is available on Maven Central.

Versions

Version
0.1.0