Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generation of BeanPropertyPathExtension lacks support for moduleDependencies #1068

Open
ChristianKernDev opened this issue Sep 13, 2024 · 0 comments

Comments

@ChristianKernDev
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant