-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(net/goai): add min, max, length, min-length, max-length and between support for OpenAPIv3 #3914
base: master
Are you sure you want to change the base?
Conversation
net/goai/goai_shema.go
Outdated
// Extract validation rules to schema. like min, max, length | ||
validationRules := ref.Value.ValidationRules | ||
// remove custom error message | ||
if idx := strings.Index(ref.Value.ValidationRules, "#"); idx != -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can refer current parsing logic in package goai
, which uses gvalid.ParseTagValue
to parse the validation pattern:
Line 230 in e8a2629
_, validationRules, _ := gvalid.ParseTagValue(validationTagValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up to this point, gvalid.ParseTagValue(validationTagValue) has already been processed. The rules have already removed the custom error messages, and strings.index is no longer needed.
net/goai/goai_shema.go
Outdated
} | ||
lstRules := gstr.Split(validationRules, "|") | ||
for _, rule := range lstRules { | ||
if strings.HasPrefix(rule, "max") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use hard-coded string, use constant instead. Please refer current usage example:
Line 66 in 7d4c59a
validationRuleKeyForRequired = `required` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, hard-coded is not good practice.
@ninjashixuan This PR is awsome! I'm watching this. |
…o openapi-doc-validate
Improve OpenAPI Documentation Generation
This update primarily enhances the OpenAPI documentation generation by setting the min, max, and max-length constraints for the schema based on request validation.