Skip to content

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

Merged
danielgtaylor merged 2 commits into
danielgtaylor:mainfrom
lsdch:body-name-hints
Apr 28, 2024
Merged

Allow providing name hints using tags for anonymous body structs#416
danielgtaylor merged 2 commits into
danielgtaylor:mainfrom
lsdch:body-name-hints

Conversation

@lsdch

@lsdch lsdch commented Apr 26, 2024

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Apr 26, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

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

❗ 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
@@            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     

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

@lsdch
lsdch force-pushed the body-name-hints branch from 45cf03b to 7ab1280 Compare April 26, 2024 18:42

@danielgtaylor danielgtaylor left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is awesome, thank you!

Comment thread huma.go Outdated
@lsdch
lsdch force-pushed the body-name-hints branch from 7ab1280 to f2d014e Compare April 28, 2024 12:22
@danielgtaylor
danielgtaylor merged commit 68006f5 into danielgtaylor:main Apr 28, 2024
wolveix added a commit that referenced this pull request Feb 15, 2026
Add docs for `nameHint` tag (#416)
@wolveix wolveix mentioned this pull request Feb 15, 2026
wolveix added a commit that referenced this pull request Feb 16, 2026
* Stop reusing schema objects in $schema field
Support multiple docs renderers
Add RegistryConfig

* Stop setting example in schema and param (fix #946)

* Support DocsRendererSwaggerUI
Add docs for `nameHint` tag (#416)

* Bump dependencies
Removed outdated example humachi.NewV4 call

* Run `go fix`

* Add tests for docs renderers

* Update Go version in secondary READMEs
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.

2 participants