Skip to content
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

feat: support go-playground/validator tags. #1045

Merged
merged 8 commits into from
Nov 10, 2021
Merged

feat: support go-playground/validator tags. #1045

merged 8 commits into from
Nov 10, 2021

Conversation

HYY-yu
Copy link
Contributor

@HYY-yu HYY-yu commented Nov 8, 2021

Describe the PR
Support go-playground/validator.
Support for parsing more tags of validator, such as max\min\oneof.

example:

type JsonResponse struct {
	Errno  int         `json:"errno" validate:"required,max=1000,min=10"`
	ErrMsg string      `json:"errmsg" validate:"required,max=1000,min=10,oneof=success fail"`
	Data   interface{} `json:"data"`
}

after:

{
    "response.JsonResponse": {
            "type": "object",
            "required": [
                "errmsg",
                "errno"
            ],
            "properties": {
                "data": {},
                "errmsg": {
                    "type": "string",
                    "maxLength": 1000,
                    "minLength": 10,
                    "enum": [
                        "success",
                        "fail"
                    ] 
                },
                "errno": {
                    "type": "integer",
                    "maximum": 1000,
                    "minimum": 10
                }
            }
        }
}

Relation issue
#995

@ubogdan
Copy link
Contributor

ubogdan commented Nov 8, 2021

@HYY-yu Some conflicts need to be fixed before we can go forward.

parser_test.go Outdated
}, field)

})
t.Run("Required with oneof tag", func(t *testing.T) {
Copy link
Contributor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please review again.

@forsaken628
Copy link
Contributor

@HYY-yu
Copy link
Contributor Author

HYY-yu commented Nov 9, 2021

@forsaken628 No, should I fix it on this PR ?

@forsaken628
Copy link
Contributor

of course,this is a bug!

@HYY-yu
Copy link
Contributor Author

HYY-yu commented Nov 9, 2021

@forsaken628 Ok, fixed by
6920dee

@codecov
Copy link

codecov bot commented Nov 10, 2021

Codecov Report

Merging #1045 (b51e2fa) into master (eff27cc) will increase coverage by 0.28%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1045      +/-   ##
==========================================
+ Coverage   93.05%   93.34%   +0.28%     
==========================================
  Files           8        8              
  Lines        2046     2134      +88     
==========================================
+ Hits         1904     1992      +88     
  Misses         79       79              
  Partials       63       63              
Impacted Files Coverage Δ
field_parser.go 99.32% <100.00%> (+0.28%) ⬆️
parser.go 92.27% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eff27cc...b51e2fa. Read the comment docs.

Copy link
Contributor

@ubogdan ubogdan left a comment

Choose a reason for hiding this comment

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

LGTM

@ubogdan ubogdan merged commit 5237c6d into swaggo:master Nov 10, 2021
@ubogdan
Copy link
Contributor

ubogdan commented Nov 10, 2021

@HYY-yu Thanks for your contribution.

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.

3 participants