-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(swagger): Fix logic error in POST JSON parameter validation. #4970
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,23 +62,23 @@ func rangeValueFromOptions(options []string) (minimum *float64, maximum *float64 | |
| } | ||
|
|
||
| func enumsValueFromOptions(options []string) []any { | ||
| if len(options) == 0 { | ||
| return []any{} | ||
| } | ||
| var enums []any | ||
| for _, option := range options { | ||
| if strings.HasPrefix(option, enumFlag) { | ||
| var resp = make([]any, 0) | ||
| val := option[8:] | ||
| fields := util.FieldsAndTrimSpace(val, func(r rune) bool { | ||
| return r == '|' | ||
| }) | ||
| for _, field := range fields { | ||
| resp = append(resp, field) | ||
| if strings.HasPrefix(option, "options=") { | ||
| optionValue := strings.TrimPrefix(option, "options=") | ||
| for _, enum := range strings.Split(optionValue, "|") { | ||
| if enum == "true" { | ||
| enums = append(enums, true) | ||
| } else if enum == "false" { | ||
| enums = append(enums, false) | ||
| } else { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| enums = append(enums, enum) | ||
| } | ||
| } | ||
| return resp | ||
| break | ||
| } | ||
| } | ||
| return []any{} | ||
| return enums | ||
| } | ||
|
|
||
| func defValueFromOptions(ctx Context, options []string, apiType spec.Type) any { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import ( | |
| ) | ||
|
|
||
| func isPostJson(ctx Context, method string, tp apiSpec.Type) (string, bool) { | ||
| if strings.EqualFold(method, http.MethodPost) { | ||
| if !strings.EqualFold(method, http.MethodPost) { | ||
|
||
| return "", false | ||
| } | ||
| structType, ok := tp.(apiSpec.DefineStruct) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,33 @@ func itemsFromGoType(ctx Context, tp apiSpec.Type) *spec.SchemaOrArray { | |
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| if ctx.UseDefinitions { | ||
|
||
| structName, containsStruct := containsStruct(array.Value) | ||
| if containsStruct { | ||
| if _, ok := array.Value.(apiSpec.DefineStruct); ok { | ||
| return &spec.SchemaOrArray{ | ||
| Schema: &spec.Schema{ | ||
| SchemaProps: spec.SchemaProps{ | ||
| Ref: spec.MustCreateRef(getRefName(structName)), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| if ptr, ok := array.Value.(apiSpec.PointerType); ok { | ||
| if _, ok := ptr.Type.(apiSpec.DefineStruct); ok { | ||
| return &spec.SchemaOrArray{ | ||
| Schema: &spec.Schema{ | ||
| SchemaProps: spec.SchemaProps{ | ||
| Ref: spec.MustCreateRef(getRefName(structName)), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return itemFromGoType(ctx, array.Value) | ||
| } | ||
|
|
||
|
|
||
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.
[nitpick] Hardcoding the prefix
"options="instead of using the existingenumFlagconstant may cause inconsistency. Consider usingenumFlagfor matching the enum option.