qri-io / jsonpointer

golang implementation of IETF RFC6901: https://tools.ietf.org/html/rfc6901
MIT License
16 stars 3 forks source link

JSONParent interface doesn't match it's documentation, nor is useful with jsonschema.Schema #10

Open dan-j opened 3 years ago

dan-j commented 3 years ago

Issue

I'm trying to traverse a *jsonschema.Schema using this library and notice that this library declares the following interface:

// JSONParent is an interface that enables tree traversal by listing
// all immediate children of an object
type JSONParent interface {
    // JSONChildren should return all immidiate children of this element
    // with json property names as keys, go types as values
    // Note that implementations on slice-types are expected to convert
    // integers to string keys
    JSONProps() map[string]interface{}
}

Note that the JSONProps() function is actually documented as JSONChildren.

Also, https://github.com/qri-io/jsonschema exposes the JSONChildren() function and not JSONProps().

Do you have a suggested fix?

Two options:

  1. Don't introduce breaking changes and update the documentation here. Then update the jsonschema package to implement both JSONProps() and JSONChildren() (which implements the same behaviour)
  2. Make a breaking change to this repo and change the signature to match the documentation. The only change to jsonschema would be to update go.mod with the latest version.
dan-j commented 3 years ago

Looking more into this, I notice that jsonschema actually implements JSONChildren() map[string]JSONPather. Notice the value-type of the map is JSONPather and not interface{}.

I think this should be closed and add a new method to the relevant keywords within jsonschema for JSONProps() map[string]interface{}