Visitar URL original
Support setting fields as optional by default by robtme · Pull Request #947 · danielgtaylor/huma · GitHub
Skip to content

Support setting fields as optional by default - #947

Merged
robtme merged 1 commit into
mainfrom
optional-fields-by-default
Jan 23, 2026
Merged

robtme merged 1 commit into
mainfrom
optional-fields-by-default

Conversation

@robtme

@robtme robtme commented Jan 23, 2026 •

Copy link
Copy Markdown
Collaborator

This adds a configurable option to mark struct fields as optional by default.

router := chi.NewMux()
cfg := huma.DefaultConfig("My API", "1.0.0")
cfg.FieldsOptionalByDefault = true
api := humachi.New(router, cfg)

This would close #901.

@codecov

codecov Bot commented Jan 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.67%. Comparing base (a3c8b56) to head (7586d96).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #947   +/-   ##
=======================================
  Coverage   92.67%   92.67%           
=======================================
  Files          23       23           
  Lines        4557     4562    +5     
=======================================
+ Hits         4223     4228    +5     
  Misses        275      275           
  Partials       59       59           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@robtme
robtme merged commit 3a43be6 into main Jan 23, 2026
7 checks passed
@robtme
robtme deleted the optional-fields-by-default branch January 23, 2026 16:20
robtme added a commit that referenced this pull request Feb 17, 2026
@robtme robtme mentioned this pull request Feb 17, 2026
robtme added a commit that referenced this pull request Feb 17, 2026
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.

Make “Required by Default” Struct Field Behavior Configurable

1 participant