-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Class name generation fails for fields with special characters using java-generator-maven-plugin #5968
Comments
I wasn't able to reproduce this using this file:
|
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.15</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.mycompany.app</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>myapp</name>
<description>an operation gateway for middleware</description>
<properties>
<java.version>17</java.version>
<io.fabric8.version>6.9.2</io.fabric8.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>generator-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
<version>0.101.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${io.fabric8.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>generator-annotations</artifactId>
<version>${io.fabric8.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>java-generator-maven-plugin</artifactId>
<version>6.12.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<source>src/main/resources/kubernetes</source>
<alwaysPreserveUnknown>true</alwaysPreserveUnknown>
<generatedAnnotations>true</generatedAnnotations>
<extraAnnotations>true</extraAnnotations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> that's my pom.xml , I changed |
Sundrio was bumped on #5621 v6.10.0 of the client provides the BOM with the right sundrio version. |
Describe the bug
Environment:
Fabric8 Kubernetes Client Version: 6.12.0
Maven Version: 3.9.6
Java Version: 17.0.10
Kubernetes Version: 1.20.1
Plugin Used:
io.fabric8:java-generator-maven-plugin:6.12.0
Issue Summary:
When using io.fabric8:java-generator-maven-plugin to generate Java POJOs from CRDs, the plugin fails to generate valid Java class names for fields that start with special characters such as -. Specifically, fields named -XX result in generated classes with invalid Java identifiers.
Steps to Reproduce:
Define a CRD with a property named -XX under any object.
Configure the java-generator-maven-plugin in a Maven project.
Run Maven generate-sources goal.
Expected Result:
The plugin should generate a valid Java class name or provide a mechanism to specify a valid Java identifier for properties with names that are not valid Java identifiers.
Actual Result:
The generated Java class contains an invalid name, like this, the class name is empty:
Proposed Solution:
It would be helpful if the plugin could either:
Automatically convert invalid identifiers into valid Java class names.
Provide a configuration option in the Maven plugin to manually specify replacements or mappings for invalid identifiers.
Example CRD Snippet:
Additional Context:
This issue prevents us from automatically generating client libraries for our custom Kubernetes resources, requiring manual intervention or post-generation scripts to correct the class names.
Fabric8 Kubernetes Client version
6.12.1
Steps to reproduce
Expected behavior
The plugin should generate a valid Java class name or provide a mechanism to specify a valid Java identifier for properties with names that are not valid Java identifiers.
Runtime
Kubernetes (vanilla)
Kubernetes API Server version
1.23
Environment
macOS
Fabric8 Kubernetes Client Logs
No response
Additional context
This issue prevents us from automatically generating client libraries for our custom Kubernetes resources, requiring manual intervention or post-generation scripts to correct the class names.
The text was updated successfully, but these errors were encountered: