vojtechhabarta/typescript-generator

Generation of BeanPropertyPathExtension lacks support for moduleDependencies

Opened this issue · 0 comments

In my project i use the moduleDependencies feature to generate multiple generated files of Java types in the different frontend projects. In addition i use the extension cz.habarta.typescript.generator.ext.BeanPropertyPathExtension

Full configuration of the plugin:

        <plugin>
	        <groupId>cz.habarta.typescript-generator</groupId>
		<artifactId>typescript-generator-maven-plugin</artifactId>
		<executions>
			<execution>
				<id>generate-common</id>
				<configuration>
					<classPatterns>
						<!-- Common model -->
						<classPattern>com.test.common.model.**</classPattern>
					</classPatterns>
					<outputFile>../../frontend/common/src/generated/api-interfaces.ts
					</outputFile>
				</configuration>
			</execution>
			<execution>
				<id>generate-app</id>
				<configuration>
					<classPatterns>
						<!-- Contract model -->
						<classPattern>com.test.app.core.model.**</classPattern>
					</classPatterns>
					<outputFile>
						../../frontend/app/src/generated/api-interfaces.ts
					</outputFile>
					<moduleDependencies>
						<moduleDependency>
							<importFrom>common</importFrom>
							<importAs>common</importAs>
							<infoJson>
								../../frontend/common/src/generated/typescript-generator-info.json
							</infoJson>
						</moduleDependency>
					</moduleDependencies>
				</configuration>
			</execution>
		</executions>
		<configuration>
			<skip>false</skip>
			<jsonLibrary>jackson2</jsonLibrary>
			<classes/>
			<customTypeMappings>
				<mapping>java.time.LocalDate:string</mapping>
				<mapping>java.time.LocalDateTime:string</mapping>
				<mapping>java.util.Map[K,V]:Record[K,V]</mapping>
			</customTypeMappings>
			<optionalAnnotations>
				<optionalAnnotation>jakarta.annotation.Nullable</optionalAnnotation>
				<annotation>jakarta.annotation.Nullable</annotation>
			</optionalAnnotations>
			<generateInfoJson>true</generateInfoJson>
			<mapEnum>asEnum</mapEnum>
			<nonConstEnums>true</nonConstEnums>
			<indentString xml:space="preserve"/>
			<outputKind>module</outputKind>
			<outputFileType>implementationFile</outputFileType>
			<sortDeclarations>true</sortDeclarations>
			<sortTypeDeclarations>true</sortTypeDeclarations>
			<noFileComment>true</noFileComment>
			<tsNoCheck>true</tsNoCheck>
			<extensions>
				<extension>
					cz.habarta.typescript.generator.ext.BeanPropertyPathExtension
				</extension>
			</extensions>
		</configuration>
	</plugin>

The problem is, that every generated api-interfaces.ts file includes a decleration for the Fields class:

export class Fields {
    protected $$parent: Fields | undefined;
    protected $$name: string;
    constructor(parent?: Fields, name?: string) {
        this.$$parent = parent;
        this.$$name = name || '';
    };
    get(): string {
        if (this.$$parent && this.$$parent.get().length > 0) {
            return this.$$parent.get() + "." + this.$$name;
        } else {
            return this.$$name;
        }
    }
}

There should be a way to generate only one Fields class in a parent file and use this for all others. So the content the plugin generates in my api-interface.ts in app should look like this:

// Added by 'BeanPropertyPathExtension' extension

class HelloWorldMessageFields extends common.Fields {
    constructor(parent?: common.Fields, name?: string) { super(parent, name); }
    message = new Fields(this, "message");
}

Is this already a feature i don't know of, or is this a feature request?