Repository navigation
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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?
Description
A Java okhttp-gson client with a large oneOf can compile successfully but fail when the generated Gson adapter is loaded. The anonymous adapter captures each variant adapter as a separate constructor argument, exceeding the JVM method parameter limit.
Actual: java.lang.ClassFormatError: Too many arguments in method signature when loading the generated adapter.
Expected: the generated adapter loads and serializes/deserializes the variants.
openapi-generator version
Reproduced on master d80e6fc9d26b1205c84a0a822684f0ef7f3f6ef2 with the focused runtime regression test. The standalone generated-client reproduction was also verified on b54d497d44058592b22b96c9159e0e0a9d23927e.
OpenAPI declaration file content or url
Generate a self-contained specification with 260 variants:
python3 - <<'PY'
with open('/tmp/large-oneof.yaml', 'w') as f:
f.write("openapi: 3.0.3\ninfo: {title: Large oneOf, version: '1'}\npaths: {}\ncomponents:\n schemas:\n Union:\n oneOf:\n")
for i in range(260):
f.write(f" - $ref: '#/components/schemas/Variant{i}'\n")
for i in range(260):
f.write(f" Variant{i}:\n type: object\n required: [kind]\n properties:\n kind: {{type: string, enum: [v{i}]}}\n")
PYGeneration Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-g java --library okhttp-gson -i /tmp/large-oneof.yaml -o /tmp/large-oneof-client \
--global-property=apis,models,supportingFiles,apiTests=false,modelTests=false
mvn -f /tmp/large-oneof-client/pom.xml -DskipTests compile dependency:build-classpath \
-Dmdep.outputFile=/tmp/large-oneof-classpath
cat > /tmp/LoadUnionAdapter.java <<'JAVA'
public class LoadUnionAdapter {
public static void main(String[] args) throws Exception {
Class.forName("org.openapitools.client.model.Union$CustomTypeAdapterFactory$1");
}
}
JAVA
javac -d /tmp /tmp/LoadUnionAdapter.java
java -cp "/tmp:/tmp/large-oneof-client/target/classes:$(cat /tmp/large-oneof-classpath)" LoadUnionAdapterSteps to reproduce
Build the generator, create the specification, and run the commands above. Compilation succeeds, but loading the anonymous adapter fails on Java 11, 21, and 27.
Related issues/PRs
Related to, but independent of, #25532 / #25533, which address the size of the model registration initializer in JSON.java.
Suggest a fix
For large oneOf schemas, store variant adapters as fields of the generated anonymous adapter rather than capturing them as constructor arguments.
Activity