Skip to content

Commit

Permalink
add a few doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
casualjim committed Apr 20, 2015
1 parent d3cc868 commit 762a526
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
24 changes: 15 additions & 9 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/validate/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SchemaValidator struct {
KnownFormats strfmt.Registry
}

// NewSchemaValidator creates a new schema validator
func NewSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string, formats strfmt.Registry) *SchemaValidator {
if schema == nil {
return nil
Expand Down Expand Up @@ -50,15 +51,18 @@ func NewSchemaValidator(schema *spec.Schema, rootSchema interface{}, root string
return &s
}

// SetPath sets the path for this schema valdiator
func (s *SchemaValidator) SetPath(path string) {
s.Path = path
}

// Applies returns true when this schema validator applies
func (s *SchemaValidator) Applies(source interface{}, kind reflect.Kind) bool {
_, ok := source.(*spec.Schema)
return ok
}

// Validate validates the data against the schema
func (s *SchemaValidator) Validate(data interface{}) *Result {
if data == nil {
v := s.validators[0].Validate(data)
Expand Down
22 changes: 16 additions & 6 deletions internal/validate/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,23 @@ func (s *SpecValidator) Validate(data interface{}) (errs *Result, warnings *Resu
warnings = new(Result)

schv := NewSchemaValidator(s.schema, nil, "", s.KnownFormats)
errs.Merge(schv.Validate(sd.Spec())) // error -
errs.Merge(s.validateItems()) // error -
errs.Merge(schv.Validate(sd.Spec())) // error -
if errs.HasErrors() {
return // no point in continuing
}
errs.Merge(s.validateReferencesValid()) // error
if errs.HasErrors() {
return // no point in continuing
}

errs.Merge(s.validateParameters()) // error -
errs.Merge(s.validateItems()) // error -
errs.Merge(s.validateRequiredDefinitions()) // error -
errs.Merge(s.validateDefaultValueValidAgainstSchema()) // error

warnings.Merge(s.validateUniqueSecurityScopes()) // warning
warnings.Merge(s.validateUniqueScopesSecurityDefinitions()) // warning
warnings.Merge(s.validateReferenced()) // warning
errs.Merge(s.validateRequiredDefinitions()) // error
errs.Merge(s.validateParameters()) // error -
errs.Merge(s.validateReferencesValid()) // error
errs.Merge(s.validateDefaultValueValidAgainstSchema()) // error

return
}
Expand Down Expand Up @@ -293,5 +301,7 @@ func (s *SpecValidator) validateReferencesValid() *Result {

func (s *SpecValidator) validateDefaultValueValidAgainstSchema() *Result {
// every default value that is specified must validate against the schema for that property
// headers, items, parameters, schema

return nil
}

0 comments on commit 762a526

Please sign in to comment.