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(net/goai): add min, max, length, min-length, max-length and between support for OpenAPIv3 #3914

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ninjashixuan
Copy link

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.

// 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 {
Copy link
Member

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:

_, validationRules, _ := gvalid.ParseTagValue(validationTagValue)

Copy link
Author

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.

}
lstRules := gstr.Split(validationRules, "|")
for _, rule := range lstRules {
if strings.HasPrefix(rule, "max") {
Copy link
Member

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:

validationRuleKeyForRequired = `required`

Copy link
Author

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.

@gqcn
Copy link
Member

gqcn commented Nov 14, 2024

@ninjashixuan This PR is awsome! I'm watching this.

@gqcn gqcn changed the title Feat: Extract validation rules to schema. like min, max, length and s… feat(net/goai): add min, max, length, min-length, max-length and between support for OpenAPIv3 Nov 14, 2024
@gqcn gqcn added the awesome It's awesome! We keep watching. label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awesome It's awesome! We keep watching.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants