Using swagger-codegen to create API from swagger.json

Hi - has anyone been able to generate the TC API using swagger-codegen from your server's swagger definition (https://<server_url>/app/rest/swagger.json)? I'm getting Exception in thread "main" java.lang.OutOfMemoryError: Java heap space regardless of the client language:

> wget http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.1/swagger-codegen-cli-2.3.1.jar -O swagger-codegen-cli.jar

> wget https://<server_url>/app/rest/swagger.json -O swagger.json

> mkdir tc_api

> java -jar swagger-codegen-cli.jar generate -i swagger.json -l csharp -o tc_api

 

If you're like me you'll get to about the same spot:

 

[main] INFO io.swagger.codegen.AbstractGenerator - writing file /tc_api/swagger-codegen/docs/VcsStatus.md
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `SetBuildQueuePosition_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `CancelBuild_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `SetParameter_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `GetParameters_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `SetParameters_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `SetParameter_1`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `DeleteAllParameters_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `GetParameter_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `SetParameter_2`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `DeleteParameter_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `GetParameterValueLong_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `SetParameterValueLong_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `SetParameter_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `CancelBuild_0`
[main] WARN io.swagger.codegen.DefaultCodegen - generated unique operationId `GetParameter_0`
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.HashMap$EntrySet.iterator(HashMap.java:1014)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:600)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:536)

 

I've tried this on a few different PCs and various -Xmx options but same results, if you do get it to work can you share your steps?

 

 

1 comment

Success! used -Xmx12288 (12G) and it's generated. The spec is so large it appears to stream the spec in to memory and build up an in memory view of the classes then writes them out to file, and this causes the OOM. 

0

Please sign in to leave a comment.