Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make json.Marshal normalize refs #74

Open
amansx opened this issue Jul 4, 2020 · 2 comments
Open

Make json.Marshal normalize refs #74

amansx opened this issue Jul 4, 2020 · 2 comments
Assignees

Comments

@amansx
Copy link

amansx commented Jul 4, 2020

How can I make the "remote" refs here, be normalized as one consolidated schema?

        var schemaData = []byte(`{
		"$id": "schema://a",
		"type": "object",
		"properties": {
			"a": {"type": "integer"},
		    "friend": {
		    	"name" : {"type": "bool"}
		    }
		},
		"required": ["a"]		
	}`)

	var schemaData2 = []byte(`{
		"$id": "schema://b",
		"type": "object",
		"properties": {
		    "allfriends": {
		    	"type" : "array",
		    	"items" : { "$ref" : "schema://a" }
		    }
		}
	}`)


	r := jsonschema.GetSchemaRegistry()

	g1 := &jsonschema.Schema{}
	g2 := &jsonschema.Schema{}

	if err := json.Unmarshal(schemaData, &g1); err != nil {
		panic("unmarshal schema: " + err.Error())
	}
	g1.Register("schema", r)

	if err := json.Unmarshal(schemaData2, &g2); err != nil {
		panic("unmarshal schema: " + err.Error())
	}
	g2.Register("", r)
@Kemosabert
Copy link

Hey @amansx, I was looking for the same thing and managed to resolve it by first reading all the schemas in the global registry and then performing the validations.

@Arqu Arqu self-assigned this Sep 7, 2020
@Arqu
Copy link
Contributor

Arqu commented Sep 7, 2020

I don't think this is supported right now as during the Marshal process we only serialize the reference hence it doesn't print out the resolved schema if you try to print it out. For that to happen we would need to extend the marshalling to serialize the r.resolved schema instead of it's reference. If we do add this, I'd like to have this under a flag or env var of some sort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants