Skip to content

Commit

Permalink
fix(RootSchema.Unmarshal): permit opaque properties
Browse files Browse the repository at this point in the history
add a unit test to verify the behavior

fixes qri-io#44
  • Loading branch information
Rob Figueiredo committed Apr 5, 2019
1 parent 8d0aab8 commit 1ff4afd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1ff4afd

Please sign in to comment.