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

[BUG][JAVA] oneOf/anyOf multiple constructors with same erasure #18548

Closed
5 of 6 tasks
Bethibande opened this issue May 1, 2024 · 1 comment
Closed
5 of 6 tasks

[BUG][JAVA] oneOf/anyOf multiple constructors with same erasure #18548

Bethibande opened this issue May 1, 2024 · 1 comment

Comments

@Bethibande
Copy link
Contributor

Bethibande commented May 1, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using the okhttp-gson library, multiple constructors with the same erasure can be generated.

public ReposCreateDeploymentRequestPayload(List<Integer> o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
}

public ReposCreateDeploymentRequestPayload(List<String> o) {
    super("oneOf", Boolean.FALSE);
    setActualInstance(o);
}

This leads to compiler errors since these constructors are identical.
Gradle logs:
https://gist.github.com/Bethibande/9582795e2e1fd47695019d8f1c685a8b

openapi-generator version

latest/master

Suggest a fix

This is the current constructor generation of the okhttp-gson oneof model template

{{#oneOf}}
public {{classname}}({{{.}}} o) {
    super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
    setActualInstance(o);
}

{{/oneOf}}

Change it to:

public {{classname}}(Object o) {
    super("oneOf", {{#isNullable}}Boolean.TRUE{{/isNullable}}{{^isNullable}}Boolean.FALSE{{/isNullable}});
    setActualInstance(o);
}

The setActualInstance method also always takes Object as a parameter, it also validates the given object, so this should be fine, this also shouldn't break any existing code.
In this case, it might also be a good idea to add some documentation about the types of parameters the constructor actually expects.

Bethibande added a commit to Bethibande/openapi-generator that referenced this issue May 12, 2024
Bethibande added a commit to Bethibande/openapi-generator that referenced this issue May 12, 2024
wing328 pushed a commit that referenced this issue May 13, 2024
#18645)

* [BUG][JAVA] oneOf/anyOf multiple constructors with same erasure
#18548

* [BUG][JAVA] oneOf/anyOf multiple constructors with same erasure
#18548
@Bethibande
Copy link
Contributor Author

Closed since the PR has been merged.

renatomameli pushed a commit to renatomameli/openapi-generator that referenced this issue May 17, 2024
…PITools#18548 (OpenAPITools#18645)

* [BUG][JAVA] oneOf/anyOf multiple constructors with same erasure
OpenAPITools#18548

* [BUG][JAVA] oneOf/anyOf multiple constructors with same erasure
OpenAPITools#18548
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant