vojtechhabarta / typescript-generator

Generates TypeScript from Java - JSON declarations, REST service client
MIT License
1.15k stars 237 forks source link

Wildcard Configuration to scan package and import into multiple folders #268

Closed aronmgv closed 6 years ago

aronmgv commented 6 years ago

Nazdar,

I just recently come across your plugin, seems nice work! Anyway to the point what I want to achieve:

Generate Typescript interfaces from the POJOs in given package from the backend with minimal configuration:

ORRRRR: Outsource complete config to the Java annotation:

Can you please confirm how much abstraction can be achieved using your current version?

This is what I come up with, but I got stuck when I couldn't tell it how to create output files for each matched class..

<plugin>
    <groupId>cz.habarta.typescript-generator</groupId>
    <artifactId>typescript-generator-maven-plugin</artifactId>
    <version>2.6.433</version>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <jsonLibrary>jackson2</jsonLibrary>
                <classes>
                    <class>com.company.dc.module.arcs.dto.*.*DTO</class>
                </classes>
                <outputFile>src/main/frontend/src/app/modules/arcs/interfaces</outputFile>
                <outputKind>module</outputKind>
            </configuration>
        </execution>
    </executions>
</plugin>

Appreciate and many thanks, Michal

EDIT: Stupid me, used the old config snapshot.. anyway now the log pointed me to use: customTypeNaming and customTypeNamingFunction.. Anyway it would be much easier to configure this via annotation anyway..

aronmgv commented 6 years ago

So I advanced a little bit:

<plugin>
    <groupId>cz.habarta.typescript-generator</groupId>
    <artifactId>typescript-generator-maven-plugin</artifactId>
    <version>2.6.433</version>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <jsonLibrary>jackson2</jsonLibrary>
        <classes>
            <class>com.company.module.arcs.dto.domain.DomainDTO</class>
            <class>com.company.module.arcs.dto.device.DeviceDTO</class>
            <!--<class>com.company.module.arcs.dto.service.ServiceDTO</class>-->
            <!--<class>com.company.module.arcs.dto.network_object.NetworkObjectDTO</class>-->
            <!--<class>com.company.module.arcs.dto.rule.RuleDTO</class>-->
            <!--<class>com.company.module.arcs.dto.iface.InterfaceDTO</class>-->
        </classes>
        <optionalProperties>useLibraryDefinition</optionalProperties>

        <!--<classPatterns>-->
            <!--<pattern>com.company.module.arcs.dto.**DTO</pattern>-->
        <!--</classPatterns>-->
        <outputFile>src/main/frontend/src/app/applications/arcs/test/ArcsInterfaces.ts</outputFile>
        <customTypeNamingFunction>
            function(name, simpleName) {
                if (name.indexOf('com.company.module.arcs.') === 0) return 'IArcs' + simpleName;
            }
        </customTypeNamingFunction>
        <outputKind>module</outputKind>
        <outputFileType>implementationFile</outputFileType>
    </configuration>
</plugin>

What I am stuck now are the following 3 things:

  1. cannot figure out how to configure to generate separate file for each class
  2. our standard is to declare interfaces as export default interface. I think new <outputKind> needs to be introduced to something like moduleDefault
  3. with this configuration not everytime change on the POJO is reflected to the frontend: @JsonProperty(value = "description", required = true) changed required to true didnt catch the change.. and is still optional in typescript interface.. Is there a way to force complete recheck for this? So it will do a deep scan or something like that?

Thanks, Michal

vojtechhabarta commented 6 years ago

Hello / Ahoj Michale,

Unfortunately typescript-generator can only generate single file with all declarations so it's not possible to achieve what you wanted. But I would like to convince you that single file is sufficient.

You said that you have some standard how to declare interfaces. That's good. But it's a standard for your (manually written) interfaces. Try to consider generated interfaces as not yours and treat them as other dependencies. If you depend for example on some npm package you also don't have influence how it is organized, what code style it uses, etc.

Currently generating multiple files is not a goal for typescript-generator. Or do you have reasons for generating multiple files other than organizing generated code consistently with your style?

Other notes:

vojtechhabarta commented 6 years ago

Hopefully typescript-generator somehow works for you now.

hortizgarrido commented 1 year ago

Is it still not possible to export to various files? i ask because my project is massive and this file alone will be gigantic.