jsonpointer icon indicating copy to clipboard operation
jsonpointer copied to clipboard

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

Open dan-j opened this issue 4 years ago • 1 comments

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 avatar Aug 04 '21 12:08 dan-j

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{}

dan-j avatar Aug 04 '21 15:08 dan-j