Skip to content

Commit

Permalink
code cleanup linkedin#146
Browse files Browse the repository at this point in the history
  • Loading branch information
Karrick S. McDermott committed Jul 12, 2019
1 parent bf42428 commit ac00340
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
15 changes: 3 additions & 12 deletions canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ func pcfNumber(val float64) (string, error) {
func pcfString(val string, typeLookup map[string]string) (string, error) {
if canonicalName, ok := typeLookup[val]; ok {
return `"` + canonicalName + `"`, nil
} else {
return `"` + val + `"`, nil
}
return `"` + val + `"`, nil
}

// pcfArray returns the parsing canonical form for a JSON array.
Expand Down Expand Up @@ -81,20 +80,12 @@ func pcfObject(jsonMap map[string]interface{}, parentNamespace string, typeLooku
if parentNamespace == "" {
namespace = namespaceStr
} else {

namespace = parentNamespace + "." + namespaceStr
}
parentNamespace = namespace
}
} else {
if objectType, ok := jsonMap["type"]; ok {
//if typeStr, ok := objectType.(string); ok && typeStr == "record" {
// namespace = parentNamespace
//}
if objectType == "record" {
namespace = parentNamespace
}
}
} else if objectType, ok := jsonMap["type"]; ok && objectType == "record" {
namespace = parentNamespace
}

for k, v := range jsonMap {
Expand Down
10 changes: 6 additions & 4 deletions canonical_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,14 @@ func TestCanonicalSchema(t *testing.T) {
Schema: `["\u006e\u0075\u006c\u006c","\u0069\u006e\u0074"]`,
Canonical: `["null","int"]`,
},
{ // propagate namespace "bar" to subtype "baz", i.e., "bar.baz"
Schema: `{"type":"record","name":"foo","namespace":"bar","fields":[{"type":"record","name":"baz","fields":[{"name":"hi","type":"int"}]}]}`,
{
// propagate namespace "bar" to subtype "baz", i.e., "bar.baz"
Schema: `{"type":"record","name":"foo","namespace":"bar","fields":[{"type":"record","name":"baz","fields":[{"name":"hi","type":"int"}]}]}`,
Canonical: `{"name":"bar.foo","type":"record","fields":[{"name":"bar.baz","type":"record","fields":[{"name":"hi","type":"int"}]}]}`,
},
{ // replace the second reference to type "baz" in bye to "bar.baz
Schema: `{"type":"record","name":"foo","namespace":"bar","fields":[{"type":"record","name":"baz","fields":[{"name":"hi","type":"int"}]},{"name":"bye", "type":["null","baz"]}]}`,
{
// replace the second reference to type "baz" in bye to "bar.baz"
Schema: `{"type":"record","name":"foo","namespace":"bar","fields":[{"type":"record","name":"baz","fields":[{"name":"hi","type":"int"}]},{"name":"bye", "type":["null","baz"]}]}`,
Canonical: `{"name":"bar.foo","type":"record","fields":[{"name":"bar.baz","type":"record","fields":[{"name":"hi","type":"int"}]},{"name":"bye","type":["null","bar.baz"]}]}`,
},
}
Expand Down
2 changes: 1 addition & 1 deletion codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,4 @@ type ErrNotSingleObjectEncoded string

func (e ErrNotSingleObjectEncoded) Error() string {
return "cannot decode buffer as single-object encoding: " + string(e)
}
}

0 comments on commit ac00340

Please sign in to comment.