Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4650] Fix StackOverflowError for recursive composite schemas #11620

Merged

Conversation

kthoms
Copy link
Contributor

@kthoms kthoms commented Feb 16, 2022

The generator ran into a loop when a composite schema recursively added itself. This change provides a reproducing example and fixes the issue by extending DefaultCodegen#addProperties() by an additional circuit breaker parameter.

When additionalProperties() is called with a schema instance for which the properties have already been added, the method directly returns and does not run into the loop.

To fix #4650

@@ -3264,13 +3264,16 @@ protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Sc
* @param required required property only
* @param schema schema in which the properties will be added to the lists
*/
protected void addProperties(Map<String, Schema> properties, List<String> required, Schema schema) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kthoms thanks for the PR. Please update the docstring of the method as well since it's causing issues to the build: https://github.com/OpenAPITools/openapi-generator/runs/5213864795?check_suite_focus=true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code and rebased it. The build fails in the samples. I don't think that it is related, WDYT?

@wing328
Copy link
Member

wing328 commented Feb 17, 2022

cc @OpenAPITools/generator-core-team

@kthoms kthoms force-pushed the issues/4650-recursive-composite-schemas branch 2 times, most recently from afa57c9 to 1c9977b Compare February 18, 2022 09:19
@wing328
Copy link
Member

wing328 commented Feb 18, 2022

Samples not up-to-date: https://github.com/OpenAPITools/openapi-generator/runs/5245407913?check_suite_focus=true

Can you please follow step 3 in the PR checklist to update the samples so that the CI can verify the result?

@kthoms
Copy link
Contributor Author

kthoms commented Feb 18, 2022

Thanks for the pointer. Will do.

**color** | **str** | | [optional]
**origin** | **str** | | [optional]
**cultivar** | **str** | | [optional]
**length_cm** | **float** | | [optional]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kthoms looks like this fix converts properties from required to optional. Is that the intended behaviour?

cc @spacether

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this looks like an unwanted side effect. Thanks for pointing this out!
When I see this correctly the originating spec is
modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
There these both properties are declared as required.
I need to have a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code. Now the samples are untouched.

@kthoms kthoms force-pushed the issues/4650-recursive-composite-schemas branch from 229f15d to 6c6396c Compare February 19, 2022 08:25
@kthoms
Copy link
Contributor Author

kthoms commented Feb 19, 2022

Build fails here:

ok  	github.com/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/go	28.525s
go: downloading github.com/gorilla/mux v1.7.3
?   	github.com/GIT_USER_ID/GIT_REPO_ID	[no test files]
# golang.org/x/net/http2
/home/circleci/.go_workspace/src/golang.org/x/net/http2/transport.go:417:45: undefined: os.ErrDeadlineExceeded
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (go-get) on project GoGinServer: Command execution failed. Process exited with an error: 2 (Exit value: 2) -> [Help 1]

This is also reported here: odeke-em/drive#1128
So I assume the build failure is unrelated to the change.

@kthoms
Copy link
Contributor Author

kthoms commented Feb 19, 2022

The Go upgrade resolved the previous issue, but now it fails with

store_api_test.go:31: Error while placing order: parsing time "\"2022-02-19T09:11:15.907+0000\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse "+0000\"" as "Z07:00"

This issue I have found here:
#1292

@wing328
Copy link
Member

wing328 commented Feb 20, 2022

Please revert e881b193682a71243297d35e295d0e7db81fd19e and I'll fix it in the master.

@kthoms kthoms force-pushed the issues/4650-recursive-composite-schemas branch from e881b19 to 6c6396c Compare February 20, 2022 15:31
@kthoms
Copy link
Contributor Author

kthoms commented Feb 20, 2022

@wing328 Thanks for your patience. I've reverted the last commit.

…hemas

The generator ran into a loop when a composite schema recursively added itself. This change provides a reproducing example and fixes the issue by extending DefaultCodegen#addProperties() by an additional circuit breaker parameter.

When additionalProperties() is called with a schema instance for which the properties have already been added, the method directly returns and does not run into the loop.
@kthoms kthoms force-pushed the issues/4650-recursive-composite-schemas branch from 6c6396c to 46c489a Compare February 23, 2022 22:33
@wing328
Copy link
Member

wing328 commented Mar 1, 2022

Tested locally to confirm the fix

@wing328 wing328 merged commit 6a7fc38 into OpenAPITools:master Mar 1, 2022
@wing328 wing328 added this to the 6.0.0 milestone Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants