Skip to content

Support empty string as default value in the struct field #2053

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

Conversation

milanvthakor
Copy link
Contributor

Describe the PR
This PR handles the issue with the default tag in the struct field. The tool ignores the empty string value for the default tag while generating the swagger specification.

The reason behind it is how the value for the default tag is being read. The code was using the tag.Get() method. This method could return an empty string in two cases: the value itself is an empty string, or the tag doesn't exist at all. And the condition below doesn't handle the first case correctly.

I have changed it to use the tag.Lookup() method to distinguish between the two cases and changed the condition accordingly.

Relation issue
#2052

@sdghchj sdghchj merged commit 77771f0 into swaggo:master Aug 4, 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