Skip to content

fix: enforce required=true for path parameters per OpenAPI spec#1011

Merged
wolveix merged 2 commits into
danielgtaylor:mainfrom
Yanhu007:fix/path-param-always-required
May 28, 2026
Merged

fix: enforce required=true for path parameters per OpenAPI spec#1011
wolveix merged 2 commits into
danielgtaylor:mainfrom
Yanhu007:fix/path-param-always-required

Conversation

@Yanhu007

Copy link
Copy Markdown
Contributor

Fixes #1009

Problem

Since v2.37.0, path parameters with required:"false" struct tag omit the "required" field from the generated OpenAPI spec. Per the OpenAPI 3.x specification:

If the parameter location is "path", this property is REQUIRED and its value MUST be true.

The initial Required = true set for path params (line 149) was being overridden by the generic required tag processing (lines 245-246).

Fix

Add post-override enforcement that always sets Required = true for path parameters, regardless of the struct tag value. This restores the pre-v2.37.0 behavior where required:"false" on path parameters was silently ignored.

Since v2.37.0, the 'required' struct tag override (line 245-246)
can set Required=false for path parameters, which violates the
OpenAPI 3.x specification:

  'If the parameter location is "path", this property is REQUIRED
   and its value MUST be true.'

The initial Required=true set at line 149 for path params was being
overridden by the generic tag processing. Add a post-override
enforcement that always sets Required=true for path params.

Fixes danielgtaylor#1009
Copilot AI review requested due to automatic review settings April 12, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an OpenAPI spec regression where path parameters tagged required:"false" could omit the required field from generated OpenAPI output, despite the OpenAPI 3.x requirement that all path parameters must be required.

Changes:

  • Enforce Required = true for all path parameters after generic required tag processing.
  • Add inline comments explaining the OpenAPI 3.x requirement and why the override is necessary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread huma.go
Comment thread huma.go Outdated
@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.05%. Comparing base (e2db596) to head (16598e9).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1011      +/-   ##
==========================================
- Coverage   93.07%   93.05%   -0.02%     
==========================================
  Files          23       23              
  Lines        4781     4870      +89     
==========================================
+ Hits         4450     4532      +82     
- Misses        271      274       +3     
- Partials       60       64       +4     

☔ 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.

@wolveix
wolveix merged commit 2899b1b into danielgtaylor:main May 28, 2026
3 of 4 checks passed
@wolveix

wolveix commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Yanhu007!

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.

Path parameters with required:"false" struct tag omit required field from OpenAPI spec (regression since v2.37.0)

3 participants