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

feat: breaks infinite cycle when looking for fields in recursive structures. #306

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

yuridevx
Copy link

My machine has crashed when I've tried to use Huma for the new micro-service that I'm developing.

// Node is a custom type for testing recursive definition for huma.Register
type Node struct {
	Name  string          `json:"name"`
	Nodes []Node          `json:"nodes,omitempty"`
	Left  *Node           `json:"left,omitempty"`
	Named map[string]Node `json:"named,omitempty"`
}

This pr breaks the cycle in findInType by adding visited map[reflect.Type]bool as a parameter.
I haven't spent much time figuring out semantics and usage of findInType, so it might be a wrong solution. However I would like to hear your thoughts on the issue.

@yuridevx yuridevx changed the title Breaks infinite cycle when looking for fields in recursive structures. feat: breaks infinite cycle when looking for fields in recursive structures. Mar 13, 2024
huma.go Outdated Show resolved Hide resolved
huma_test.go Show resolved Hide resolved
@victoraugustolls
Copy link
Sponsor Contributor

@danielgtaylor, sorry if I'm barging myself in here! I just guessed that reviewing this PR would be a nice opportunity to learn more about the code.

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.22%. Comparing base (c312351) to head (b32a525).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #306      +/-   ##
==========================================
+ Coverage   95.14%   95.22%   +0.08%     
==========================================
  Files          19       19              
  Lines        2782     2788       +6     
==========================================
+ Hits         2647     2655       +8     
+ Misses         98       97       -1     
+ Partials       37       36       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yuridevx
Copy link
Author

@danielgtaylor @victoraugustolls I've adjusted visited to struct{} to match the rest of project usage, also I've added break to getFields

Copy link
Owner

@danielgtaylor danielgtaylor left a comment

Choose a reason for hiding this comment

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

@yuridevx thank you! 👍

@danielgtaylor danielgtaylor merged commit 347d6d0 into danielgtaylor:main Mar 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants