fix: avoid stack overflow errors when using heavily recursive types#1377
Open
yoshikipom wants to merge 10 commits intooapi-codegen:mainfrom
Open
fix: avoid stack overflow errors when using heavily recursive types#1377yoshikipom wants to merge 10 commits intooapi-codegen:mainfrom
yoshikipom wants to merge 10 commits intooapi-codegen:mainfrom
Conversation
added 3 commits
September 20, 2024 12:33
Member
|
Interestingly, this changes behaviour of an existing case: diff --git a/internal/test/all_of/v2/openapi.gen.go b/internal/test/all_of/v2/openapi.gen.go
index ab43034..618cec4 100644
--- a/internal/test/all_of/v2/openapi.gen.go
+++ b/internal/test/all_of/v2/openapi.gen.go
@@ -32,10 +32,10 @@ type PersonProperties struct {
// PersonWithID defines model for PersonWithID.
type PersonWithID struct {
- FirstName string `json:"FirstName"`
- GovernmentIDNumber *int64 `json:"GovernmentIDNumber,omitempty"`
- ID int64 `json:"ID"`
- LastName string `json:"LastName"`
+ FirstName *string `json:"FirstName,omitempty"`
+ GovernmentIDNumber *int64 `json:"GovernmentIDNumber,omitempty"`
+ ID int64 `json:"ID"`
+ LastName *string `json:"LastName,omitempty"`
}I need to confirm if that's expected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
#1373
Stack overflow error happens
merge_schemas.gowhenallOfcontains circular$ref.Cause & How to fix
https://github.com/deepmap/oapi-codegen/blob/1f53862bcc64573d3d0c4c105c71a8143e7b1816/pkg/codegen/merge_schemas.go#L87
mergeOpenapiSchemasis called recursively until all items inallOfare consumed. (allOfof item inallOfare also explored.) If same item is in the path of the exploration, stack overflow can happen.https://github.com/deepmap/oapi-codegen/blob/1f53862bcc64573d3d0c4c105c71a8143e7b1816/pkg/codegen/merge_schemas.go#L85-L86
This code flatten schemas and merge them to handle
allOfinallOf.My approach is just skip to merge same schema because that doesn't affect to the merge result.
https://github.com/deepmap/oapi-codegen/compare/master...yoshikipom:oapi-codegen:fix/recursive-error-allof?expand=1#diff-423bfd1d22f4994f4f0c03f76f15af8371bee0bc5da50efa3ab696e1a60d7d49R41-R43
Commit
Test
Before fix
After fix