@@ -17,17 +17,12 @@ var DefaultSchemaCache = &SchemaCache{}
1717
1818// Parse parses a schema string.
1919func Parse (schema string ) (Schema , error ) {
20- return ParseWithCache ( schema , "" , DefaultSchemaCache )
20+ return ParseBytes ([] byte ( schema ) )
2121}
2222
23- // ParseWithCache parses a schema string using the given namespace and schema cache.
23+ // ParseWithCache parses a schema string using the given namespace and schema cache.
2424func ParseWithCache (schema , namespace string , cache * SchemaCache ) (Schema , error ) {
25- var json any
26- if err := jsoniter .Unmarshal ([]byte (schema ), & json ); err != nil {
27- json = schema
28- }
29-
30- return parseType (namespace , json , cache )
25+ return ParseBytesWithCache ([]byte (schema ), namespace , cache )
3126}
3227
3328// MustParse parses a schema string, panicing if there is an error.
@@ -60,6 +55,21 @@ func ParseFiles(paths ...string) (Schema, error) {
6055 return schema , nil
6156}
6257
58+ // ParseBytes parses a schema byte slice.
59+ func ParseBytes (schema []byte ) (Schema , error ) {
60+ return ParseBytesWithCache (schema , "" , DefaultSchemaCache )
61+ }
62+
63+ // ParseBytesWithCache parses a schema byte slice using the given namespace and schema cache.
64+ func ParseBytesWithCache (schema []byte , namespace string , cache * SchemaCache ) (Schema , error ) {
65+ var json any
66+ if err := jsoniter .Unmarshal (schema , & json ); err != nil {
67+ json = string (schema )
68+ }
69+
70+ return parseType (namespace , json , cache )
71+ }
72+
6373func parseType (namespace string , v any , cache * SchemaCache ) (Schema , error ) {
6474 switch val := v .(type ) {
6575 case nil :
0 commit comments