@@ -46,15 +46,18 @@ type RootSchema struct {
4646 // for current and previous published drafts of JSON Schema
4747 // vocabularies as deemed reasonable.
4848 SchemaURI string `json:"$schema"`
49- // Whether the top-level of the schema is an array or not.
50- // Assume it's an object otherwise.
51- TopIsArray bool
5249}
5350
54- func determineTopIsArray (sch * Schema ) bool {
55- validator := sch .Validators ["type" ]
56- typeValidator , ok := validator .(* Type )
57- return ok && typeValidator .FirstValue () == "array"
51+ // TopLevelType returns a string representing the schema's top-level type.
52+ func (rs * RootSchema ) TopLevelType () string {
53+ validator , ok := rs .Schema .Validators ["type" ]
54+ if ok {
55+ typeValidator , ok := validator .(* Type )
56+ if ok {
57+ return typeValidator .String ()
58+ }
59+ }
60+ return "unknown"
5861}
5962
6063// UnmarshalJSON implements the json.Unmarshaler interface for
@@ -64,7 +67,6 @@ func (rs *RootSchema) UnmarshalJSON(data []byte) error {
6467 if err := json .Unmarshal (data , sch ); err != nil {
6568 return err
6669 }
67- topIsArray := determineTopIsArray (sch )
6870
6971 if sch .schemaType == schemaTypeFalse || sch .schemaType == schemaTypeTrue {
7072 * rs = RootSchema {Schema : * sch }
@@ -81,7 +83,6 @@ func (rs *RootSchema) UnmarshalJSON(data []byte) error {
8183 root := & RootSchema {
8284 Schema : * sch ,
8385 SchemaURI : suri .SchemaURI ,
84- TopIsArray : topIsArray ,
8586 }
8687
8788 // collect IDs for internal referencing:
@@ -135,7 +136,6 @@ func (rs *RootSchema) UnmarshalJSON(data []byte) error {
135136 * rs = RootSchema {
136137 Schema : * sch ,
137138 SchemaURI : suri .SchemaURI ,
138- TopIsArray : topIsArray ,
139139 }
140140 return nil
141141}
0 commit comments