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
25
vendor/github.com/go-openapi/validate/schema.go
generated
vendored
25
vendor/github.com/go-openapi/validate/schema.go
generated
vendored
|
@ -27,8 +27,8 @@ import (
|
|||
var (
|
||||
specSchemaType = reflect.TypeOf(&spec.Schema{})
|
||||
specParameterType = reflect.TypeOf(&spec.Parameter{})
|
||||
specItemsType = reflect.TypeOf(&spec.Items{})
|
||||
specHeaderType = reflect.TypeOf(&spec.Header{})
|
||||
//specItemsType = reflect.TypeOf(&spec.Items{})
|
||||
)
|
||||
|
||||
// SchemaValidator validates data against a JSON schema
|
||||
|
@ -39,14 +39,14 @@ type SchemaValidator struct {
|
|||
validators []valueValidator
|
||||
Root interface{}
|
||||
KnownFormats strfmt.Registry
|
||||
Options *SchemaValidatorOptions
|
||||
Options SchemaValidatorOptions
|
||||
}
|
||||
|
||||
// AgainstSchema validates the specified data against the provided schema, using a registry of supported formats.
|
||||
//
|
||||
// When no pre-parsed *spec.Schema structure is provided, it uses a JSON schema as default. See example.
|
||||
func AgainstSchema(schema *spec.Schema, data interface{}, formats strfmt.Registry) error {
|
||||
res := NewSchemaValidator(schema, nil, "", formats).Validate(data)
|
||||
func AgainstSchema(schema *spec.Schema, data interface{}, formats strfmt.Registry, options ...Option) error {
|
||||
res := NewSchemaValidator(schema, nil, "", formats, options...).Validate(data)
|
||||
if res.HasErrors() {
|
||||
return errors.CompositeValidationError(res.Errors...)
|
||||
}
|
||||
|
@ -72,9 +72,15 @@ func NewSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string
|
|||
panic(msg)
|
||||
}
|
||||
}
|
||||
s := SchemaValidator{Path: root, in: "body", Schema: schema, Root: rootSchema, KnownFormats: formats, Options: &SchemaValidatorOptions{}}
|
||||
s := SchemaValidator{
|
||||
Path: root,
|
||||
in: "body",
|
||||
Schema: schema,
|
||||
Root: rootSchema,
|
||||
KnownFormats: formats,
|
||||
Options: SchemaValidatorOptions{}}
|
||||
for _, o := range options {
|
||||
o(s.Options)
|
||||
o(&s.Options)
|
||||
}
|
||||
s.validators = []valueValidator{
|
||||
s.typeValidator(),
|
||||
|
@ -134,9 +140,9 @@ func (s *SchemaValidator) Validate(data interface{}) *Result {
|
|||
|
||||
// TODO: this part should be handed over to type validator
|
||||
// Handle special case of json.Number data (number marshalled as string)
|
||||
isnumber := s.Schema.Type.Contains("number") || s.Schema.Type.Contains("integer")
|
||||
isnumber := s.Schema.Type.Contains(numberType) || s.Schema.Type.Contains(integerType)
|
||||
if num, ok := data.(json.Number); ok && isnumber {
|
||||
if s.Schema.Type.Contains("integer") { // avoid lossy conversion
|
||||
if s.Schema.Type.Contains(integerType) { // avoid lossy conversion
|
||||
in, erri := num.Int64()
|
||||
if erri != nil {
|
||||
result.AddErrors(invalidTypeConversionMsg(s.Path, erri))
|
||||
|
@ -196,6 +202,7 @@ func (s *SchemaValidator) sliceValidator() valueValidator {
|
|||
Items: s.Schema.Items,
|
||||
Root: s.Root,
|
||||
KnownFormats: s.KnownFormats,
|
||||
Options: s.Options,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,6 +255,6 @@ func (s *SchemaValidator) objectValidator() valueValidator {
|
|||
PatternProperties: s.Schema.PatternProperties,
|
||||
Root: s.Root,
|
||||
KnownFormats: s.KnownFormats,
|
||||
Options: *s.Options,
|
||||
Options: s.Options,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue