question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] StackOverflowError in DefaultCodegen.addProperties when a schemas with same name are referenced directly and indirectly

See original GitHub issue

Bug Report Checklist

  • [Y ] Have you provided a full/minimal spec to reproduce the issue?
  • [ Y] Have you validated the input using an OpenAPI validator (example)?
  • What’s the version of OpenAPI Generator used? 4.2.1
  • [Y ] Have you search for related issues/PRs?
  • What’s the actual output vs expected output? java.lang.StackOverflowError, expected Sring generated project
  • [Optional] Bounty to sponsor the fix (example)
Description

When trying to generate spring project from a complex .yaml file setup a java.lang.StackOverflowError is thrown.

The setup is the following:

Base.yaml contains a definition of Test Blue.yaml contains a definition of Test which inherits with Allof from Base.yaml->Test Green.yaml also contains a definition of Test which inherits with Allof from Base.yaml->Test and also it has a reference to Blue.yaml->Test

When generation is started for Green.yaml , DefaultCodegen.addProperties causes stack overflow.

Generator first loads the Base.yaml->Test reference in its cache. The problem happens when the generator starts processing the Blue.yaml->Test reference in Green.yaml. It loads the Blue.yaml->Test but wrongly overrides the Base.yaml->Test in its cache. Blue.yaml->Test is inheriting from Base.yaml->Test but now after the override Blue.yaml->Test inherits from itself and becomes corrupt!!!. After this when DefaultCodegen.addProperties starts its work it goes into endless recursion trying to process the corrupted self referencing Blue.yaml->Test .

See the stack trace below:

[main] INFO o.o.codegen.DefaultGenerator - OpenAPI Generator: spring (server) [main] INFO o.o.codegen.DefaultGenerator - Generator ‘spring’ is considered stable. [main] INFO o.o.codegen.languages.SpringCodegen - ---------------------------------- [main] INFO o.o.c.languages.AbstractJavaCodegen - Environment variable JAVA_POST_PROCESS_FILE not defined so the Java code may not be properly formatted. To define it, try ‘export JAVA_POST_PROCESS_FILE=“/usr/local/bin/clang-format -i”’ (Linux/Mac) [main] INFO o.o.c.languages.AbstractJavaCodegen - NOTE: To enable file post-processing, ‘enablePostProcessFile’ must be set to true (–enable-post-process-file for CLI). [main] INFO o.o.c.languages.AbstractJavaCodegen - Processing operation test [main] INFO o.o.c.languages.AbstractJavaCodegen - Processing operation inbox_storeTaskResponse Exception in thread “main” java.lang.StackOverflowError at org.apache.commons.lang3.StringUtils.isNotBlank(StringUtils.java:327) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2020) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2002) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2022) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2002) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2022) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2002) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2022) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2002) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2022) at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2002)

openapi-generator version

4.2.1

OpenAPI declaration file content or url
Command line used for generation

openapi-generator generate -i task-test.yaml -g spring -o test

Steps to reproduce
Related issues/PRs
Suggest a fix

The problem seem to be that when loading a second ref .yaml file which contains schemas with the same name as a component from the other first ref.yaml file. The second component overrides the first component.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
connorworleycommented, Jun 14, 2020

I am also running into this issue. Any workarounds?

0reactions
kthomscommented, Apr 5, 2022

I have recently build from master and that version fixed my issue at least. Might be that your example uncovers a new situation. I don’t have time to look at it ATM.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger recursive reference (with Intellij Idea plugin)
I have Swagger plugin and Node.yaml json schema, which is referenced in openapi 3.0 spec:
Read more >
java.lang.StackOverflowError – How to solve ... - YouTube
Interested in learning more about java.lang. StackOverflowError ? Then check out our detailed video on how to solve Stack Overflow Error, ...
Read more >
[#XMLBEANS-495] StackOverflowError when parsing a large ...
When XMLBeans validates a very long XML String (4000 or so chars), it generates a StackOverFlowError as shown below. In the schema for...
Read more >
最活跃的中文计算机技术社区 - 码客
[BUG] StackOverflowError in DefaultCodegen.addProperties when a schemas with same name are referenced directly and indirectly.
Read more >
EclipseLink » stackOverFlowError - Eclipse Community Forums
This mapping is not setup correctly - I would hope that hte @JoinTable annotation on the CpTransCoverage cpTerrorismCoverage relationship is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found