Repository navigation
feat: json:omitempty marks field as optional - #2041
Merged
Merged
Conversation
Enhance field parser to recognize 'omitempty' in JSON tags, updating IsRequired logic and adding corresponding test cases. Update README to document the new behavior. Signed-off-by: Andy Stoneberg <astonebe@redhat.com>
sdghchj
approved these changes
Jul 16, 2025
|
@sdghchj could this also be merged to the v2 branch? Thanks |
pborgen
pushed a commit
to pborgen/swag
that referenced
this pull request
Jan 8, 2026
Enhance field parser to recognize 'omitempty' in JSON tags, updating IsRequired logic and adding corresponding test cases. Update README to document the new behavior. Signed-off-by: Andy Stoneberg <astonebe@redhat.com>
|
Any chance this can get prioritized somehow? I can propose the same PR against the v2 branch? Thanks! |
Member
|
@ant1g PR is welcome. |
Hoffs
pushed a commit
to Hoffs/swag
that referenced
this pull request
Mar 25, 2026
Enhance field parser to recognize 'omitempty' in JSON tags, updating IsRequired logic and adding corresponding test cases. Update README to document the new behavior. Signed-off-by: Andy Stoneberg <astonebe@redhat.com>
racciari
added a commit
to racciari/swag
that referenced
this pull request
Oct 6, 2026
) With --requiredByDefault, v1 treats a field whose json tag carries omitempty as optional. The v2 branch forked before swaggo#2041, so both tagBaseFieldParser.IsRequired and tagBaseFieldParserV3.IsRequired still return RequiredByDefault for such fields. An explicit binding/validate required or optional still takes precedence.
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.
Describe the PR
json:tag asrequired: false, updating IsRequired logic (following existing pattern present in parsing logic) and adding corresponding test case.json:omitemptyRelation issue
Related: #2040
Additional context
While I believe this behavior makes the most sense to use in conjunction with the
--requiredByDefaultflag - there is no hard requirement or dependency to force both these options to co-exist. Implementation gives preference to existing supportedtagvalues (binding+validate) so anything presently relying on them forrequiredcalculation is unaffected by this change.