Closed aronmgv closed 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:
export default interface
. I think new <outputKind>
needs to be introduced to something like moduleDefault
@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
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:
implementationFile
if you are only generating interfaces. If you want classes or generate whole client than yes.classPatterns
and customTypeNamingFunction
seems ok. You could use addTypeNamePrefix
parameter if you just wanted to add I
prefix to all interfaces.@JsonProperty.required
to true
it should not be optional). Typescript-generator doesn't have any cache, each invocation does everything from scratch. Could you check that typescript-generator really runs after your changes?Hopefully typescript-generator somehow works for you now.
Is it still not possible to export to various files? i ask because my project is massive and this file alone will be gigantic.
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:
com.company.dc.module.arcs.dto.*.*DTO
(so it will grab only*DTO.java
from this given java package)src/main/frontend/src/app/module/arcs/interfaces/___interface-file-name.ts___
___interface-file-name.ts___
would be defined via@Annotation
over the Class - something like@TypescriptInterface(filename = "IArcsDevice.ts")
com.company.dc.module.ciscoasi.dto.*.*DTO
ORRRRR: Outsource complete config to the Java annotation:
@Annotation
would be sufficient to achieve this core logic. Exmaple:@TypescriptInterface(location= "src/main/frontend/src/app/module/arcs/interfaces/IArcsDevice.ts")
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..
Appreciate and many thanks, Michal
EDIT: Stupid me, used the old config snapshot.. anyway now the log pointed me to use:
customTypeNaming
andcustomTypeNamingFunction
.. Anyway it would be much easier to configure this via annotation anyway..