11package jtdinfer
22
3+ // Wildcard represents the character that matches any value for hints.
34const Wildcard = "-"
45
6+ // Hints contains the default number type to use and all the hints for enums,
7+ // values and discriminators.
58type Hints struct {
69 DefaultNumType NumType
710 Enums HintSet
811 Values HintSet
912 Discriminator HintSet
1013}
1114
15+ func WithoutHints () Hints {
16+ return Hints {}
17+ }
18+
19+ // SubHint will return the sub hints for all hint sets for the passed key.
1220func (h Hints ) SubHints (key string ) Hints {
1321 return Hints {
1422 DefaultNumType : h .DefaultNumType ,
@@ -18,33 +26,42 @@ func (h Hints) SubHints(key string) Hints {
1826 }
1927}
2028
29+ // IsEnumActive checks if the enum hint set is active.
2130func (h Hints ) IsEnumActive () bool {
2231 return h .Enums .IsActive ()
2332}
2433
34+ // IsValuesActive checks if the values hint set is active.
2535func (h Hints ) IsValuesActive () bool {
2636 return h .Values .IsActive ()
2737}
2838
39+ // PeekActiveDiscriminator will peek the currently active discriminator, if any.
40+ // The returned boolean tells if there is an active discriminator.
2941func (h Hints ) PeekActiveDiscriminator () (string , bool ) {
3042 return h .Discriminator .PeekActive ()
3143}
3244
45+ // HintSet represents a list of paths (lists) to match for hints.
3346type HintSet struct {
3447 Values [][]string
3548}
3649
50+ // NewHintSet creates a new empty `HintSet`.
3751func NewHintSet () HintSet {
3852 return HintSet {
3953 Values : [][]string {},
4054 }
4155}
4256
57+ // Add will add a path (slice) to the `HintSet`.
4358func (h HintSet ) Add (v []string ) HintSet {
4459 h .Values = append (h .Values , v )
4560 return h
4661}
4762
63+ // SubHint will filter all the current sets and keep those who's first element
64+ // matches the passed key or wildcard.
4865func (h HintSet ) SubHints (key string ) HintSet {
4966 filteredValues := [][]string {}
5067
@@ -64,6 +81,7 @@ func (h HintSet) SubHints(key string) HintSet {
6481 }
6582}
6683
84+ // IsActive returns true if any set in the hint set his active.
6785func (h HintSet ) IsActive () bool {
6886 for _ , valueList := range h .Values {
6987 if len (valueList ) == 0 {
@@ -74,6 +92,8 @@ func (h HintSet) IsActive() bool {
7492 return false
7593}
7694
95+ // PeekActive returns the currently active value if any. The returned boolean
96+ // tells if a value was found.
7797func (h HintSet ) PeekActive () (string , bool ) {
7898 for _ , values := range h .Values {
7999 if len (values ) != 1 {
0 commit comments