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

[java-generator] "package" is not handled as keyword #5380

Closed
Obirah opened this issue Aug 10, 2023 · 4 comments · Fixed by #5381
Closed

[java-generator] "package" is not handled as keyword #5380

Obirah opened this issue Aug 10, 2023 · 4 comments · Fixed by #5381

Comments

@Obirah
Copy link

Obirah commented Aug 10, 2023

Describe the bug

When using io.fabric8.java-generator to genreate Java code from a CRD which contains an object that is named package package and has objects underneath it, the generator simply uses the name package as package name even though it is a Java keyword which results in broken code.

Fabric8 Kubernetes Client version

6.8.0

Steps to reproduce

Create a CRD which contains an object named package anywhere in the Spec or Status.

Example for such an object:

package:
  description: Package to be used.
  properties:
    appPath:
      description: AppPath of the app relative to the package's root.
      type: string
    name:
      description: Name of the package.
      type: string
    repository:
      description: Repository to be used to obtain the package.
      properties:
        secretName:
          description: SecretName to be used to access the registry
            (must be in the same namespace).
          type: string
        type:
          description: Type of the Repository.
          enum:
          - git
          - npm
          type: string
        uri:
          description: URI for the registry.
          pattern: ^\w+:(\/?\/?)[^\s]+$
          type: string
      required:
      - type
      - uri
      type: object
    version:
      description: Version of the package.
      type: string
  required:
  - repository
  - version
  type: object

Generate code for your CRD and you will see that the package name for the nested object repository will look something like this: com.acme.mycr.package which will not be compilable.

Expected behavior

Expected behavior would be to have compilable Java code even when an object is called package.

In my mind, one possible solution would be to prepend the name of the parent package to the package name if a package is called package, e.g. instead of com.acme.mycr.package the generator produces com.acme.mycr.mycrpackage.

Another solution would be to throw an error if a keyword occurs and make the users specify keywordOverrides similar to the packageOverrides.

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.25.3@latest

Environment

Linux

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

@Obirah Obirah changed the title [java-generator] word "package" is not handled as keyword [java-generator] "package" is not handled as keyword Aug 10, 2023
@andreaTP
Copy link
Member

andreaTP commented Aug 10, 2023

Thanks a lot for taking the time to file this issue!

I'm actually surprised as we are already sanitizing strings and excluding keywords, but I can reproduce the issue with a CRD like:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: dummies.example.com
spec:
  group: example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                package:
                  type: object
                  properties:
                    foo:
                      type: object
                      properties:
                        bar:
                          type: string
  scope: Namespaced
  names:
    plural: dummies
    singular: dummy
    kind: Dummy

@andreaTP
Copy link
Member

@Obirah thanks again for reporting, I submitted a fix in #5381 let me know if you have any comment.

@Obirah
Copy link
Author

Obirah commented Aug 10, 2023

@Obirah thanks again for reporting, I submitted a fix in #5381 let me know if you have any comment.

You're welcome. :) LGTM, thanks for providing a fix so quickly! If I knew this before, I wouldn't have implemented a post-processor that fixes this in Gradle. :D

@andreaTP
Copy link
Member

I wouldn't have implemented a post-processor that fixes this in Gradle. :D

Next time I'll assign the issue to you 😜 😄 !

@manusa manusa added this to the 6.8.1 milestone Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants