qri-io / jsonschema

golang implementation of https://json-schema.org drafts 7 & 2019-09
MIT License
461 stars 54 forks source link

fix: data type check unsupported Ptr and Interface #112

Closed Cluas closed 2 years ago

Cluas commented 3 years ago

We currently have some scenarios where we construct map[string]interface{} directly and then call jsonschema.Validate , which avoids a json.Marshal operation, but I found that the DataType detection, when encountering a Pointer or Interface of nil, has Here it returns "unknown", when I would expect it to return "null".

Cluas commented 3 years ago

@b5 can you help review the code?

Arqu commented 2 years ago

A pointer is not a structure that should be evaluated or validated against as it's not really representable in JSON (it's either an array or object that needs to be serialized and validated on itself and it's children), and type null/nil is not it's data type here.

Whatever those map[string]interface{} contain should either not be part of the validation process or you should wrap it up in a struct or at least type alias it and implement it as a keyword with it's validation and registration mechanics.