openapi-generator "java.lang.OutOfMemoryError: Java heap space" in CI
OpenAPI Generator runs on the JVM. A very large or deeply nested spec can exhaust the default heap, so generation dies with "java.lang.OutOfMemoryError: Java heap space" partway through. Giving the JVM more heap usually resolves it.
What this error means
openapi-generator-cli aborts with "java.lang.OutOfMemoryError: Java heap space" mid-generation, often on a constrained runner with a big OpenAPI document.
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.openapitools.codegen.DefaultGenerator.processPaths(...)Common causes
Default JVM heap is too small for the spec
A large spec with many paths and schemas needs more heap than the JVM default, so generation runs out of memory.
A constrained runner with little memory
A small runner caps available RAM, leaving the JVM with too little to grow the heap.
How to fix it
Raise the JVM heap with JAVA_OPTS
- Set
JAVA_OPTS(the CLI passes it to the JVM) to a larger maximum heap. - Re-run generation with the increased limit.
- If it still fails, move to a larger runner.
JAVA_OPTS="-Xmx4g" openapi-generator-cli generate \
-i openapi.yaml -g typescript-axios -o ./clientGenerate only what you need
Restrict generation to the relevant tags or models so the generator holds less in memory.
openapi-generator-cli generate -i openapi.yaml -g go -o ./client \
--global-property models,apis,supportingFilesHow to prevent it
- Set an explicit
-Xmxfor large specs in CI. - Use a runner with enough memory for the JVM heap.
- Split very large specs or limit generation scope.