OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.02k stars 6.61k forks source link

[BUG][typescript-node] Large spec client results in java.lang.OutOfMemoryError #5201

Open GMZwinge opened 4 years ago

GMZwinge commented 4 years ago
Description

When trying to generate a typescript-node client from a large size v2 spec (10,000 lines of JSON), the generator crashes with java.lang.OutOfMemoryError and this output and stack trace:

[main] WARN  o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: typescript-node (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'typescript-node' is considered stable.
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Hint: Environment variable 'TS_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Note: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/identity]
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/identity]
[main] INFO  o.o.codegen.DefaultGenerator - Model LayoutReference not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model literal not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model Evaluator not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model CriteriaOperator not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model Sort not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model LinkParams not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model Clause not generated since it's a free-form object
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3181)
    at java.util.ArrayList.grow(ArrayList.java:265)
    at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239)
    at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231)
    at java.util.ArrayList.add(ArrayList.java:462)
    at org.openapitools.codegen.DefaultCodegen.updateAllModels(DefaultCodegen.java:305)
    at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:477)
    at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:923)
    at org.openapitools.codegen.cmd.Generate.run(Generate.java:416)
    at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)

Similar error with swagger-codegen.

openapi-generator version

Standalone: 4.2.2

OpenAPI declaration file content or url

https://vdc-download.vmware.com/vmwb-repository/dcr-public/4e9128db-55e6-443b-acd8-38a1e6de78c2/3820b3fb-9c77-463b-8aa5-e8f2471924e0/api-vra-identity.json from vRealize Automation Identity Service API 7.5 tab Documentation.

Command line used for generation

java -jar openapi-generator-cli-4.2.2.jar generate --input-spec api-vra-identity.json --generator-name typescript-node

Steps to reproduce

Just run above command.

Related issues/PRs

The error is identical to #4398, but the stack trace is not.

auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

davija commented 3 years ago

Any updates? Almost a year and no movement on this... Still exists in the latest 4.3.1 and 5.0.0-beta3.

This is a show-stopper for anyone using this library with a halfway decent sized API....

i3rinkmann commented 3 years ago

Bump

i have a similar issue but with the python client generation and my spec file is around 75000 lines long albeit its a json file (so every bracket creates 2 extra lines) tried on cli version v5.1.0

Xerocry commented 1 year ago

Bump, same error, but using Java. Same stacktrace. Will there be any fix after a couple years?

java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf (Arrays.java:3689)
    at java.util.ArrayList.grow (ArrayList.java:238)
    at java.util.ArrayList.grow (ArrayList.java:243)
    at java.util.ArrayList.add (ArrayList.java:486)
    at java.util.ArrayList.add (ArrayList.java:499)
    at org.openapitools.codegen.DefaultCodegen.updateAllModels (DefaultCodegen.java:633)
    at org.openapitools.codegen.DefaultGenerator.generateModels (DefaultGenerator.java:529)
    at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:918)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:837)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
i3rinkmann commented 1 year ago

Greetings, after Xerocry reportet the issue with Java, i tried it with the openapi-generator-cli via docker (i used the latest version 4 days ago which should be version 6.5?) There it worked without any issue, but i did not try again wwith the standalone java application so there it maybe still is a problem.

coderaven commented 1 year ago

Same issue with ours, there seems to be a memory handling issue. We tried to feed our spec to Swagger-codegen and it works. But when we use open-api-tools it just goes out of memory error.