From 1ff4afd9697d1fcd8683cd19d191418e87ea75a3 Mon Sep 17 00:00:00 2001 From: Rob Figueiredo Date: Fri, 5 Apr 2019 10:28:38 -0400 Subject: [PATCH] fix(RootSchema.Unmarshal): permit opaque properties add a unit test to verify the behavior fixes #44 --- schema.go | 4 ++-- schema_test.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/schema.go b/schema.go index ee1f939..e3b19a7 100644 --- a/schema.go +++ b/schema.go @@ -523,8 +523,8 @@ func (s *Schema) UnmarshalJSON(data []byte) error { sch.extraDefinitions = Definitions{} } s := new(Schema) - if err := json.Unmarshal(rawmsg, s); err != nil { - return fmt.Errorf("error unmarshaling %s from json: %s", prop, err.Error()) + if err := json.Unmarshal(rawmsg, s); err == nil { + sch.extraDefinitions[prop] = s } sch.extraDefinitions[prop] = s continue diff --git a/schema_test.go b/schema_test.go index cecad8d..b78283b 100644 --- a/schema_test.go +++ b/schema_test.go @@ -562,6 +562,23 @@ func TestValidateBytes(t *testing.T) { } } +func TestOpaqueProperties(t *testing.T) { + const input = ` +{ + "$id": "https://www.github.com/schemas/robfig", + "properties": { + "name": { + "type": "string", + "opaque": "something" + } + } +}` + var rs RootSchema + if err := rs.UnmarshalJSON([]byte(input)); err != nil { + t.Error(err) + } +} + // TODO - finish remoteRef.json tests by setting up a httptest server on localhost:1234 // that uses an http.Dir to serve up testdata/remotes directory // func testServer() {