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

Generated java code does not compile #100

Closed
dickerpulli opened this issue May 13, 2020 · 15 comments · Fixed by #101 or #103
Closed

Generated java code does not compile #100

dickerpulli opened this issue May 13, 2020 · 15 comments · Fixed by #101 or #103

Comments

@dickerpulli
Copy link

dickerpulli commented May 13, 2020

When I generate java code with java -jar openapi-generator-cli-4.2.3.jar generate -g jaxrs-resteasy -i ../src/main/resources/git-icar/url-schemes/exampleUrlScheme.json -o output the resulting code does not compile.

The Collections (i.e. IcarAnimalCoreCollection) extends IcarResourceCollection that has a member of type List, but i.e. has the same field member of type List.

This does not compile

 .../target/generated-sources/openapi/src/main/java/org/openapitools/model/IcarAnimalCoreCollection.java:[54,15]
 name clash: setMember(java.util.List<org.openapitools.model.IcarAnimalCoreResource>) in org.openapitools.model.IcarAnimalCoreCollection 
and setMember(java.util.List<java.lang.Object>) in org.openapitools.model.IcarResourceCollection have the same erasure, yet neither overrides the other

Do I missed a parameter? Is it a problem of the OpenAPI-Generator? What tool do you use to generate compilable java code (> Java 8)?

@ahokkonen
Copy link
Contributor

@dickerpulli ,with generating .net code I've been using openapi-generator v4.3.0 and it compiled well. I guess @alamers also has used same version for Java generation. Seems like you are using 4.2.3, so at least you could try to update generator.

I would recommend to avoid (at least for now) using latest version of openapi-generation (v4.3.1) as it contains some breaking changes for handling discriminators in schemes.

@alamers
Copy link
Collaborator

alamers commented May 13, 2020

Hi, I think I did something similar to you when testing this (see #84) and did not run into this problem. I used the default OkHttp generation instead of JAX-RS but I don't think that should completely change the generated code. Also I did use the latest version. Unfortunately, I seem to have done a bit of spring cleaning on my laptop so I don't have the workspace anymore. Let me know if 4.3.1 fixes it for you, otherwise I'll try and reconstruct my previous setup.

@ahokkonen
Copy link
Contributor

@alamers
in 4.3.1 it seems to be some global changes for "discriminator" handling (one we are using for proper inheritance). Please refer to this PR on openapi-generator.

I would recommend to use 4.3.0 instead for now.

@dickerpulli
Copy link
Author

I can confirm that currently 4.3.1 does not work at all. But with 4.3.0, 4.2.3, 4.2.2 (that's what i've tested so far) the code is generated but no compileable java code.

When I execute java -jar openapi-generator-cli-4.3.0.jar generate -g java -i ICAR-ADE-1/url-schemes/exampleUrlScheme.json -o output I get the generated code like attached in the output.zip. The same problem i.e. IcarAnimalCoreCollection extends IcarResourceCollection and overrides setMember method incorrectly.

java.util.List<org.openapitools.model.IcarMovementBirthEventResource> is not compatible with java.util.List<java.lang.Object>

output.zip

@dickerpulli
Copy link
Author

dickerpulli commented May 14, 2020

When I remove the following block from icanResourceCollection.json everythings compiles

    "member": {
      "type": "array",
      "items": {}
    }

As I understand IcarResourceCollection is more or less an abstract Class that holds the view (IcarResourceCollectionView) and is implemented by all collections like IcarAnimalCoreCollection. This implementing collections all have this member property. So I think the member property in their parent class is not neccessary.

What do you think? Does this work with your .NET code? @ahokkonen

@cookeac
Copy link
Collaborator

cookeac commented May 14, 2020

I agree @dickerpulli @ahokkonen the member property of icarResourceCollection was principally added for documentation of the intent for derived classes. The documentation could be retained in the Wiki while the definition in the JSON Schema could be removed to improve code generation.
This should not be a breaking change for ADE-1 as the member property will still be defined in all concrete collections.

@ahokkonen
Copy link
Contributor

ahokkonen commented May 14, 2020

When I remove the following block from icanResourceCollection.json everythings compiles

    "member": {
      "type": "array",
      "items": {}
    }

As I understand IcarResourceCollection is more or less an abstract Class that holds the view (IcarResourceCollectionView) and is implemented by all collections like IcarAnimalCoreCollection. This implementing collections all have this member property. So I think the member property in their parent class is not neccessary.

What do you think? Does this work with your .NET code? @ahokkonen

@dickerpulli I was about to suggest same solution you have already found (removing "member" from base class). In .NET sub-class just override "member" property from parent and compiles well.

I agree that we can remove this property in parent as a quick and simple solution. Maybe later we can see if this is somehow solvable as a generic/abstract parent-property. (probably requires generator improvements etc.)

@ahokkonen
Copy link
Contributor

I agree @dickerpulli @ahokkonen the member property of icarResourceCollection was principally added for documentation of the intent for derived classes. The documentation could be retained in the Wiki while the definition in the JSON Schema could be removed to improve code generation.
This should not be a breaking change for ADE-1 as the member property will still be defined in all concrete collections.

@cookeac I will do this correction today and will send a PR. Also minor fix for empty inline schema which cases errors in 4.3.1 generator release.

@alamers
Copy link
Collaborator

alamers commented May 14, 2020

I just checked @ahokkonen's pull request with Java and this version works fine for me. I generated a spring client:
java -jar ~/local/openapi-generator-cli-4.3.1.jar generate -g spring -i ~/tmp/ICAR/url-schemes/exampleUrlScheme.json
which compiles out of the box.

Not sure what I did last time; I notice that there is now an LocationsApi instead of the other API's I had. So I guess I mixed up different generators and/or versions. :( Anyway, this seems to work, and should be backwards compatible so I'll confirm the pull request.

@alamers alamers linked a pull request May 14, 2020 that will close this issue
@alamers
Copy link
Collaborator

alamers commented May 14, 2020

@dickerpulli Can you confirm that it also works for you? Then we can close this ticket :)
Just FYI: the change is in the Develop branch, not (yet) in ADE-1.

@dickerpulli
Copy link
Author

dickerpulli commented May 14, 2020

Hi @alamers I expected the fix to be done on branch ADE-1 so that it is fixed for version 1 also.

... currently it's only fixed on DEVELOP

@dickerpulli
Copy link
Author

Sorry, I missed your hint, that it's only in DEVELOP :-)

I testet the DEVELOP and it works. But only with "spring" as generator language.

It also works with openapi-generator-4.3.1

@alamers
Copy link
Collaborator

alamers commented May 15, 2020

Ok, I just tested with -g java --library resteasy and -g java --library native and those generate fine as well. Closing this ticket.

@alamers alamers closed this as completed May 15, 2020
@dickerpulli
Copy link
Author

@alamers when will it be merged into ADE-1 branch?

@alamers
Copy link
Collaborator

alamers commented May 18, 2020

I just now merged it into ADE-1 and released v1.0.1.

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