Skip to content

feat: json:omitempty marks field as optional #2041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025

Conversation

andyatmiami
Copy link
Contributor

@andyatmiami andyatmiami commented Jul 15, 2025

Describe the PR

  • Enhances field parser to recognize 'omitempty' in json: tag as required: false, updating IsRequired logic (following existing pattern present in parsing logic) and adding corresponding test case.
  • Update README to document the new behavior w.r.t json:omitempty

Relation issue
Related: #2040

Additional context
While I believe this behavior makes the most sense to use in conjunction with the --requiredByDefault flag - there is no hard requirement or dependency to force both these options to co-exist. Implementation gives preference to existing supported tag values ( binding + validate) so anything presently relying on them for required calculation is unaffected by this change.

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 <[email protected]>
@sdghchj sdghchj merged commit 15a183b into swaggo:master Jul 16, 2025
10 checks passed
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