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] error: too many parameters #20019

Open
blaghed opened this issue Nov 4, 2024 · 4 comments
Open

[BUG] [JAVA] error: too many parameters #20019

blaghed opened this issue Nov 4, 2024 · 4 comments

Comments

@blaghed
Copy link

blaghed commented Nov 4, 2024

Description

After upgrading from 7.3.0, we started getting error: too many parameters on a generated POJO Model of an object that has 255 fields.
Tracked it down to Java/pojo.mustache)

We've tried manually setting x-java-all-args-constructor: false and x-has-readonly-properties: false, but these result in the same error.
As far as I can tell, x-java-all-args-constructor is respected, but x-has-readonly-properties is superseded by the property being read only itself -- which makes sense (see AbstractJavaCodegen.java).

As such, we're unable to instruct the generator to not add these constructors at all.
I understand this was done to fix an issue with Jackson (see #18870 ), but sadly it brings this issue on the other side.

openapi-generator version

7.9.0

Suggest a fix

Issue: Java/pojo.mustache)
Commit: #18870

@jpfinne
Copy link
Contributor

jpfinne commented Nov 6, 2024

@blaghed

This can be fixed by a small change in AbstractJavaCodeGen.java

protected int constructorWithAllArgsMaxArguments=254;

protected boolean isConstructorWithAllArgsAllowed(CodegenModel codegenModel) {
    return (this.generateConstructorWithAllArgs &&
            (!codegenModel.vars.isEmpty() || codegenModel.parentVars.isEmpty()) &&
            cm.vars.size() + cm.parentVars.size() <= constructorWithAllArgsMaxArguments;
}

can you create a PR with that change?

@blaghed
Copy link
Author

blaghed commented Nov 6, 2024

The error happens on the read-only constructor, though. The "all args" one can be disabled correctly.
At the moment I am working around this by adding a vendor extension on the pojo.mustache to allow disabling.

@jpfinne
Copy link
Contributor

jpfinne commented Nov 6, 2024

Maybe this:

if (property.isReadOnly && property.readOnlyVars.size() <= 255) {
    model.getVendorExtensions().put("x-has-readonly-properties", true);
}

@blaghed
Copy link
Author

blaghed commented Nov 6, 2024

That's reasonable. This won't bring back whatever issue with Jackson was fixed? I assume it needs some way to write these properties, and no setters are present since they are read-only.

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

2 participants