danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.87k stars 138 forks source link

Allow providing name hints using tags for anonymous body structs #416

Closed lsdch closed 4 months ago

lsdch commented 4 months ago

Small change introducing the possibility to provide name hints for request/response body through struct tags. Previously discussed in #322

Example:

type EndpointInput struct {
  Body struct {
    SomeData string `json:"some_data"`
  } `name-hint:"SomeName"`
}

Because it defines a name hint, it only applies to anonymous types. We could go further and allow overriding the name altogether but that would involve changing the schema namer interface (func (t reflect.Type, hint string) string) to include one more parameter, which might break backward compatibility.

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 92.73%. Comparing base (ed2c3cd) to head (f2d014e). Report is 9 commits behind head on main.

:exclamation: Current head f2d014e differs from pull request most recent head 831b1db. Consider uploading reports for the commit 831b1db to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #416 +/- ## ========================================== + Coverage 92.65% 92.73% +0.08% ========================================== Files 21 21 Lines 3539 3552 +13 ========================================== + Hits 3279 3294 +15 + Misses 221 220 -1 + Partials 39 38 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.