fix: enforce required=true for path parameters per OpenAPI spec#1011
Merged
wolveix merged 2 commits intoMay 28, 2026
Conversation
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
Contributor
There was a problem hiding this comment.
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 = truefor allpathparameters after genericrequiredtag 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Collaborator
|
Thanks @Yanhu007! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:The initial
Required = trueset for path params (line 149) was being overridden by the genericrequiredtag processing (lines 245-246).Fix
Add post-override enforcement that always sets
Required = truefor path parameters, regardless of the struct tag value. This restores the pre-v2.37.0 behavior whererequired:"false"on path parameters was silently ignored.