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

fix: allow response types to contain unexported fields #278

Conversation

FlorianLoch
Copy link
Contributor

@FlorianLoch FlorianLoch commented Mar 4, 2024

So far using a type as Body on a response type containing unexported fields results in a panic:

panic: reflect.StructOf: field "config" is anonymous but has PkgPath set

goroutine 1 [running]:
reflect.runtimeStructField({{0x105753038, 0x6}, {0x105778f34, 0x27}, {0x1059311a8, 0x1058b15e0}, {0x10575303f, 0x8}, 0x0, {0x14000352668, ...}, ...})
        /opt/homebrew/Cellar/go/1.22.0/libexec/src/reflect/type.go:2538 +0x1c8
reflect.StructOf({0x14000270008, 0x10, 0x14000548508?})
        /opt/homebrew/Cellar/go/1.22.0/libexec/src/reflect/type.go:2189 +0x274
github.com/danielgtaylor/huma/v2.(*SchemaLinkTransformer).OnAddOperation(0x140005a2150, 0x140005aa0b0, 0x14000548601?)
       .../huma/transforms.go:110 +0x2d0

As I am using ent (entgo.io) that is subpar, because the structs generated by ent contain unexported fields (in this case config, which triggered the panic above).
Creating proxy types would really break the experience, so it's not really an option.
And anyway I don't see why huma would not want to support such structs as it seems to me there is no drawback in this simple fix suggested - but as I am new to huma and its codebase I might just not see it 😉.

Feedback would be appreciated.

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.70%. Comparing base (30fe05a) to head (34360bb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #278   +/-   ##
=======================================
  Coverage   94.70%   94.70%           
=======================================
  Files          18       18           
  Lines        2700     2700           
=======================================
  Hits         2557     2557           
  Misses        105      105           
  Partials       38       38           

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

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.

This looks great, thanks! 👍

@danielgtaylor danielgtaylor merged commit 895f500 into danielgtaylor:main Mar 4, 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

2 participants