@@ -27,6 +27,9 @@ type ValidationState struct {
2727 Misc map [string ]interface {}
2828
2929 Errs * []KeyError
30+
31+ // ExtraData is a shared storage between all substates of a ValidationState
32+ ExtraData * map [string ]interface {}
3033}
3134
3235// NewValidationState creates a new ValidationState with the provided location pointers and data instance
@@ -46,6 +49,7 @@ func NewValidationState(s *Schema) *ValidationState {
4649 LocalEvaluatedPropertyNames : & map [string ]bool {},
4750 Misc : map [string ]interface {}{},
4851 Errs : & []KeyError {},
52+ ExtraData : & map [string ]interface {}{},
4953 }
5054}
5155
@@ -66,9 +70,21 @@ func (vs *ValidationState) NewSubState() *ValidationState {
6670 LocalEvaluatedPropertyNames : vs .LocalEvaluatedPropertyNames ,
6771 Misc : map [string ]interface {}{},
6872 Errs : vs .Errs ,
73+ ExtraData : vs .ExtraData ,
6974 }
7075}
7176
77+ // GetExtraData retrieves a key from the shared validation store(ExtraData).
78+ func (vs * ValidationState ) GetExtraData (key string ) (interface {}, bool ) {
79+ data , exists := (* vs .ExtraData )[key ]
80+ return data , exists
81+ }
82+
83+ // SetExtraData stores data into the shared validation store(ExtraData)
84+ func (vs * ValidationState ) SetExtraData (key string , value interface {}) {
85+ (* vs .ExtraData )[key ] = value
86+ }
87+
7288// ClearState resets a schema to it's core elements
7389func (vs * ValidationState ) ClearState () {
7490 vs .EvaluatedPropertyNames = & map [string ]bool {}
0 commit comments