forked from forgejo/forgejo
[Vendor] update go-swagger v0.21.0 -> v0.25.0 (#12670)
* Update go-swagger * vendor
This commit is contained in:
parent
66843f2237
commit
3270e7a443
350 changed files with 26353 additions and 5552 deletions
123
vendor/github.com/go-openapi/validate/default_validator.go
generated
vendored
123
vendor/github.com/go-openapi/validate/default_validator.go
generated
vendored
|
@ -33,14 +33,8 @@ func (d *defaultValidator) resetVisited() {
|
|||
d.visitedSchemas = map[string]bool{}
|
||||
}
|
||||
|
||||
// beingVisited asserts a schema is being visited
|
||||
func (d *defaultValidator) beingVisited(path string) {
|
||||
d.visitedSchemas[path] = true
|
||||
}
|
||||
|
||||
// isVisited tells if a path has already been visited
|
||||
func (d *defaultValidator) isVisited(path string) bool {
|
||||
found := d.visitedSchemas[path]
|
||||
func isVisited(path string, visitedSchemas map[string]bool) bool {
|
||||
found := visitedSchemas[path]
|
||||
if !found {
|
||||
// search for overlapping paths
|
||||
frags := strings.Split(path, ".")
|
||||
|
@ -70,6 +64,16 @@ func (d *defaultValidator) isVisited(path string) bool {
|
|||
return found
|
||||
}
|
||||
|
||||
// beingVisited asserts a schema is being visited
|
||||
func (d *defaultValidator) beingVisited(path string) {
|
||||
d.visitedSchemas[path] = true
|
||||
}
|
||||
|
||||
// isVisited tells if a path has already been visited
|
||||
func (d *defaultValidator) isVisited(path string) bool {
|
||||
return isVisited(path, d.visitedSchemas)
|
||||
}
|
||||
|
||||
// Validate validates the default values declared in the swagger spec
|
||||
func (d *defaultValidator) Validate() (errs *Result) {
|
||||
errs = new(Result)
|
||||
|
@ -89,64 +93,60 @@ func (d *defaultValidator) validateDefaultValueValidAgainstSchema() *Result {
|
|||
s := d.SpecValidator
|
||||
|
||||
for method, pathItem := range s.analyzer.Operations() {
|
||||
if pathItem != nil { // Safeguard
|
||||
for path, op := range pathItem {
|
||||
// parameters
|
||||
for _, param := range paramHelp.safeExpandedParamsFor(path, method, op.ID, res, s) {
|
||||
if param.Default != nil && param.Required {
|
||||
res.AddWarnings(requiredHasDefaultMsg(param.Name, param.In))
|
||||
}
|
||||
for path, op := range pathItem {
|
||||
// parameters
|
||||
for _, param := range paramHelp.safeExpandedParamsFor(path, method, op.ID, res, s) {
|
||||
if param.Default != nil && param.Required {
|
||||
res.AddWarnings(requiredHasDefaultMsg(param.Name, param.In))
|
||||
}
|
||||
|
||||
// reset explored schemas to get depth-first recursive-proof exploration
|
||||
d.resetVisited()
|
||||
// reset explored schemas to get depth-first recursive-proof exploration
|
||||
d.resetVisited()
|
||||
|
||||
// Check simple parameters first
|
||||
// default values provided must validate against their inline definition (no explicit schema)
|
||||
if param.Default != nil && param.Schema == nil {
|
||||
// check param default value is valid
|
||||
red := NewParamValidator(¶m, s.KnownFormats).Validate(param.Default)
|
||||
if red.HasErrorsOrWarnings() {
|
||||
res.AddErrors(defaultValueDoesNotValidateMsg(param.Name, param.In))
|
||||
res.Merge(red)
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively follows Items and Schemas
|
||||
if param.Items != nil {
|
||||
red := d.validateDefaultValueItemsAgainstSchema(param.Name, param.In, ¶m, param.Items)
|
||||
if red.HasErrorsOrWarnings() {
|
||||
res.AddErrors(defaultValueItemsDoesNotValidateMsg(param.Name, param.In))
|
||||
res.Merge(red)
|
||||
}
|
||||
}
|
||||
|
||||
if param.Schema != nil {
|
||||
// Validate default value against schema
|
||||
red := d.validateDefaultValueSchemaAgainstSchema(param.Name, param.In, param.Schema)
|
||||
if red.HasErrorsOrWarnings() {
|
||||
res.AddErrors(defaultValueDoesNotValidateMsg(param.Name, param.In))
|
||||
res.Merge(red)
|
||||
}
|
||||
// Check simple parameters first
|
||||
// default values provided must validate against their inline definition (no explicit schema)
|
||||
if param.Default != nil && param.Schema == nil {
|
||||
// check param default value is valid
|
||||
red := NewParamValidator(¶m, s.KnownFormats).Validate(param.Default)
|
||||
if red.HasErrorsOrWarnings() {
|
||||
res.AddErrors(defaultValueDoesNotValidateMsg(param.Name, param.In))
|
||||
res.Merge(red)
|
||||
}
|
||||
}
|
||||
|
||||
if op.Responses != nil {
|
||||
if op.Responses.Default != nil {
|
||||
// Same constraint on default Response
|
||||
res.Merge(d.validateDefaultInResponse(op.Responses.Default, "default", path, 0, op.ID))
|
||||
}
|
||||
// Same constraint on regular Responses
|
||||
if op.Responses.StatusCodeResponses != nil { // Safeguard
|
||||
for code, r := range op.Responses.StatusCodeResponses {
|
||||
res.Merge(d.validateDefaultInResponse(&r, "response", path, code, op.ID))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Empty op.ID means there is no meaningful operation: no need to report a specific message
|
||||
if op.ID != "" {
|
||||
res.AddErrors(noValidResponseMsg(op.ID))
|
||||
// Recursively follows Items and Schemas
|
||||
if param.Items != nil {
|
||||
red := d.validateDefaultValueItemsAgainstSchema(param.Name, param.In, ¶m, param.Items)
|
||||
if red.HasErrorsOrWarnings() {
|
||||
res.AddErrors(defaultValueItemsDoesNotValidateMsg(param.Name, param.In))
|
||||
res.Merge(red)
|
||||
}
|
||||
}
|
||||
|
||||
if param.Schema != nil {
|
||||
// Validate default value against schema
|
||||
red := d.validateDefaultValueSchemaAgainstSchema(param.Name, param.In, param.Schema)
|
||||
if red.HasErrorsOrWarnings() {
|
||||
res.AddErrors(defaultValueDoesNotValidateMsg(param.Name, param.In))
|
||||
res.Merge(red)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if op.Responses != nil {
|
||||
if op.Responses.Default != nil {
|
||||
// Same constraint on default Response
|
||||
res.Merge(d.validateDefaultInResponse(op.Responses.Default, jsonDefault, path, 0, op.ID))
|
||||
}
|
||||
// Same constraint on regular Responses
|
||||
if op.Responses.StatusCodeResponses != nil { // Safeguard
|
||||
for code, r := range op.Responses.StatusCodeResponses {
|
||||
res.Merge(d.validateDefaultInResponse(&r, "response", path, code, op.ID))
|
||||
}
|
||||
}
|
||||
} else if op.ID != "" {
|
||||
// Empty op.ID means there is no meaningful operation: no need to report a specific message
|
||||
res.AddErrors(noValidResponseMsg(op.ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,7 @@ func (d *defaultValidator) validateDefaultInResponse(resp *spec.Response, respon
|
|||
|
||||
responseName, responseCodeAsStr := responseHelp.responseMsgVariants(responseType, responseCode)
|
||||
|
||||
// nolint: dupl
|
||||
if response.Headers != nil { // Safeguard
|
||||
for nm, h := range response.Headers {
|
||||
// reset explored schemas to get depth-first recursive-proof exploration
|
||||
|
@ -223,7 +224,7 @@ func (d *defaultValidator) validateDefaultValueSchemaAgainstSchema(path, in stri
|
|||
s := d.SpecValidator
|
||||
|
||||
if schema.Default != nil {
|
||||
res.Merge(NewSchemaValidator(schema, s.spec.Spec(), path+".default", s.KnownFormats).Validate(schema.Default))
|
||||
res.Merge(NewSchemaValidator(schema, s.spec.Spec(), path+".default", s.KnownFormats, SwaggerSchema(true)).Validate(schema.Default))
|
||||
}
|
||||
if schema.Items != nil {
|
||||
if schema.Items.Schema != nil {
|
||||
|
@ -260,6 +261,8 @@ func (d *defaultValidator) validateDefaultValueSchemaAgainstSchema(path, in stri
|
|||
return res
|
||||
}
|
||||
|
||||
// TODO: Temporary duplicated code. Need to refactor with examples
|
||||
// nolint: dupl
|
||||
func (d *defaultValidator) validateDefaultValueItemsAgainstSchema(path, in string, root interface{}, items *spec.Items) *Result {
|
||||
res := new(Result)
|
||||
s := d.SpecValidator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue