gen icon indicating copy to clipboard operation
gen copied to clipboard

Generated Models for Java have Invalid code

Open jrshaffe opened this issue 2 years ago • 16 comments

When I run the generation for java I am getting code that doesn't compile. The errors all say

Non-static method 'getGson()' cannot be referenced from a static context

It looks like the following methods are being added to my all my models and

 /**
  * Create an instance of V1MyObject given an JSON string
  *
  * @param jsonString JSON string
  * @return An instance of V1MyObject
  * @throws IOException if the JSON string is invalid with respect to V1MyObject
  */
  public static V1MyObject fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, V1MyObject.class);
  }

 /**
  * Convert an instance of V1MyObject to an JSON string
  *
  * @return JSON string
  */
  public String toJson() {
    return JSON.getGson().toJson(this);
  }

JSON is referring toio.kubernetes.client.openapi.JSON

and that method is defined as follows:

  public JSON setGson(Gson gson) {
    this.gson = gson;
    return this;
  }

https://github.com/kubernetes-client/java/blob/master/kubernetes/src/main/java/io/kubernetes/client/openapi/JSON.java#L120-L122.

I noticed that the JSON.java file looks like it wasn't updated at the same time as the other files in there. All the other ones say there were Automated from openapi generation release 1.27. Not sure if that helps at all.

image

jrshaffe avatar Sep 26 '23 19:09 jrshaffe

Ah, this is due to https://github.com/kubernetes-client/java/blob/master/kubernetes/.openapi-generator-ignore#L10

I believe that hold is no longer necessary. Can you try removing that line?

brendandburns avatar Sep 27 '23 17:09 brendandburns

Ah, this is due to https://github.com/kubernetes-client/java/blob/master/kubernetes/.openapi-generator-ignore#L10

I believe that hold is no longer necessary. Can you try removing that line?

So that did fix my compilation issue. I commented out the line you mentioned and ran the generation as described here. I then did a mvn install on the java project and used the generated SNAPSHOT jar for client-java-extended in my project. I had to then add some additional dependencies but it did end up compiling.

Alot of the the other subprojects in java project are failing though. I attempted to fix the compilation issues and skip some of the test but then I got to a point where util subproject is complaining about missing classes and I wasn't sure what to do there.

If anyone wants to look at my fork it's here: https://github.com/jrshaffe/java/tree/jrshaffe/fixOpenAPIGeneration

jrshaffe avatar Oct 02 '23 17:10 jrshaffe

What version of the Kubernetes API are you using? The existing codebase is pointed at release-1.27 The Kubernetes release changes may cause missing class files.

I'm in the process of regenerating the common Java client, so I will probably run into these problems and debug.

You might also try regenerating at this commit: https://github.com/kubernetes-client/gen/commit/9701a7c9ae41c489c1839a10069e6b0c79803d72

Which is before we rev'd the openapi code generator from 4.x to 6.x

brendandburns avatar Oct 03 '23 21:10 brendandburns

What version of the Kubernetes API are you using?

I was using 1.27

You might also try regenerating at this commit: https://github.com/kubernetes-client/gen/commit/9701a7c9ae41c489c1839a10069e6b0c79803d72

Thanks! Using that commit worked for us.

jrshaffe avatar Oct 04 '23 21:10 jrshaffe

Hi 👋 I see the was a 19.0.0 release that updated .openapi-generator-ignore but the code for JSON class was not updated. I run https://github.com/kubernetes-client/java/wiki/4.-Development-and-Contributing to update them and fix most of the compilation errors (now the JSON class is correct). The fluent API modules failed because it expects some classes that are not generated, for example:

  • V1PodResourceClaim
  • V1beta3FlowSchemaStatus
  • V1alpha1IPAddressSpec
  • V1alpha1ParamRef

If anyone knows how to update the fluent modules, I can create a PR with the updated client.

abelsromero avatar Nov 29 '23 18:11 abelsromero

Ping @brendandburns back on this. There seems to be no way to use the generator right now until everything moves up a step and this JSON thing gets fixed.

dsyer avatar Feb 08 '24 18:02 dsyer

I was able to get something working just for my CRDs from master (84f2bc9e34129f92606a00fccb8c5c62204012b9) by discarding the io.kubernetes.client generated code and using the published API in version 20.0.0 from https://github.com/kubernetes-client/java. I also bumped the generator version by setting OPENAPI_GENERATOR_COMMIT=v7.3.0, but not sure if that was essential or not.

The issue still remains though in the published containers and docs, and probably the fluent modules issue that @abelsromero mentioned.

dsyer avatar Feb 09 '24 10:02 dsyer

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar May 09 '24 11:05 k8s-triage-robot

/remove-lifecycle stale

dsyer avatar May 09 '24 11:05 dsyer

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Aug 07 '24 12:08 k8s-triage-robot

/remove-lifecycle stale

dsyer avatar Aug 07 '24 12:08 dsyer

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Nov 05 '24 12:11 k8s-triage-robot

/remove-lifecycle stale

dsyer avatar Nov 05 '24 12:11 dsyer

/lifecycle-frozen

brendandburns avatar Jan 08 '25 15:01 brendandburns

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Apr 08 '25 16:04 k8s-triage-robot

/remove-lifecycle stale

dsyer avatar Apr 08 '25 16:04 dsyer

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jul 07 '25 17:07 k8s-triage-robot

/remove-lifecycle stale

dsyer avatar Jul 07 '25 19:07 dsyer

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Oct 05 '25 19:10 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Nov 04 '25 20:11 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Dec 04 '25 21:12 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Dec 04 '25 21:12 k8s-ci-robot