Skip to content

Commit

Permalink
feat(validation): Add a shared storage between all substates of a Val…
Browse files Browse the repository at this point in the history
…idation State
  • Loading branch information
bmfs committed Jul 9, 2021
1 parent 36b0071 commit 68b05a9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions validation_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type ValidationState struct {
Misc map[string]interface{}

Errs *[]KeyError

// ExtraData is a shared storage between all substates of a ValidationState
ExtraData *map[string]interface{}
}

// NewValidationState creates a new ValidationState with the provided location pointers and data instance
Expand All @@ -45,6 +48,7 @@ func NewValidationState(s *Schema) *ValidationState {
LocalEvaluatedPropertyNames: &map[string]bool{},
Misc: map[string]interface{}{},
Errs: &[]KeyError{},
ExtraData: &map[string]interface{}{},
}
}

Expand All @@ -65,9 +69,21 @@ func (vs *ValidationState) NewSubState() *ValidationState {
LocalEvaluatedPropertyNames: vs.LocalEvaluatedPropertyNames,
Misc: map[string]interface{}{},
Errs: vs.Errs,
ExtraData: vs.ExtraData,
}
}

// GetExtraData retrieves a key from the shared validation store(ExtraData).
func (vs *ValidationState) GetExtraData(key string) (interface{}, bool) {
data, exists := (*vs.ExtraData)[key]
return data, exists
}

// SetExtraData stores data into the shared validation store(ExtraData)
func (vs *ValidationState) SetExtraData(key string, value interface{}) {
(*vs.ExtraData)[key] = value
}

// ClearState resets a schema to it's core elements
func (vs *ValidationState) ClearState() {
vs.EvaluatedPropertyNames = &map[string]bool{}
Expand Down

0 comments on commit 68b05a9

Please sign in to comment.