Skip to content

[BUG][Java][okhttp-gson] JSON.java fails to compile with many model adapters #25532

Open

Description

@AndreyVMarkelov

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

Java okhttp-gson clients generated from a specification with many object models can fail compilation. The generated JSON.java registers every model adapter in one static initializer, exceeding the JVM's per-method bytecode limit.

Actual: generation succeeds, but compilation reports JSON.java: code too large.

Expected: generated Java sources compile, with all model adapters registered in their original order.

openapi-generator version

Current master 0810b02db908ccb48c0d1ee480123fade431f21c (7.28.0-SNAPSHOT): reproduced using a public API specification with 5822 registered model adapters.

OpenAPI declaration file content or url

Create a standalone reproduction with 6000 simple object schemas:

python3 - <<'PY'
with open('/tmp/many-models.yaml', 'w') as f:
    f.write("openapi: 3.0.3\ninfo: {title: Many models, version: '1'}\npaths: {}\ncomponents:\n  schemas:\n")
    for i in range(6000):
        f.write(f"    Model{i}:\n      type: object\n      properties:\n        value: {{type: string}}\n")
PY
Generation Details
java -Xmx6g -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
  -g java --library okhttp-gson -i /tmp/many-models.yaml -o /tmp/many-models-client \
  --global-property=apis,models,supportingFiles,apiTests=false,modelTests=false
mvn -f /tmp/many-models-client/pom.xml -DskipTests compile
Steps to reproduce

Build the generator from master, create the synthetic specification above, then run the generation and compilation commands. The synthetic reproduction was verified with generator commit b54d497d44058592b22b96c9159e0e0a9d23927e; the relevant Java generator and template files are unchanged at the tested master commit above.

Related issues/PRs

No matching issue found for JSON.java and code too large.

Suggest a fix

Split model adapter registration into bounded helper methods while preserving registration order. Keep output for small specifications unchanged.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions