Skip to content

Commit

Permalink
Revert behaviour to not prepend non-root top-level fields in JSON ren…
Browse files Browse the repository at this point in the history
…dering.

This is a partial revert of #638, see discussion in #648.
  • Loading branch information
wenovus committed Apr 22, 2022
1 parent c15884d commit 774960a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
4 changes: 2 additions & 2 deletions demo/bgp/testdata/bgp-ietf.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"global": {
"openconfig-network-instance:global": {
"config": {
"as": 15169,
"router-id": "192.0.2.42"
}
},
"neighbors": {
"openconfig-network-instance:neighbors": {
"neighbor": [
{
"config": {
Expand Down
8 changes: 2 additions & 6 deletions ygot/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ func (*RFC7951JSONConfig) IsMarshal7951Arg() {}
// to JSON described by RFC7951. The supplied args control options corresponding
// to the method by which JSON is marshalled.
func ConstructIETFJSON(s ValidatedGoStruct, args *RFC7951JSONConfig) (map[string]interface{}, error) {
return structJSON(s, s.ΛBelongingModule(), jsonOutputConfig{
return structJSON(s, "", jsonOutputConfig{
jType: RFC7951,
rfc7951Config: args,
})
Expand Down Expand Up @@ -1000,11 +1000,7 @@ func Marshal7951(d interface{}, args ...Marshal7951Arg) ([]byte, error) {
indent = string(v)
}
}
var parentMod string
if s, ok := d.(ValidatedGoStruct); ok {
parentMod = s.ΛBelongingModule()
}
j, err := jsonValue(reflect.ValueOf(d), parentMod, jsonOutputConfig{
j, err := jsonValue(reflect.ValueOf(d), "", jsonOutputConfig{
jType: RFC7951,
rfc7951Config: rfcCfg,
})
Expand Down
34 changes: 17 additions & 17 deletions ygot/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2769,15 +2769,15 @@ func TestConstructJSON(t *testing.T) {
},
inAppendMod: true,
wantIETF: map[string]interface{}{
"f1": "foo",
"config": map[string]interface{}{
"f1mod:f1": "foo",
"f1mod:config": map[string]interface{}{
"f2mod:f6": "mat",
},
"f2mod:config": map[string]interface{}{
"f2": "bar",
"f3mod:f7": "bat",
},
"f3": map[string]interface{}{
"f1mod:f3": map[string]interface{}{
"f42mod:config": map[string]interface{}{
"f4": "baz",
},
Expand Down Expand Up @@ -3552,7 +3552,7 @@ func TestEncodeTypedValue(t *testing.T) {
},
inEnc: gnmipb.Encoding_JSON_IETF,
want: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_JsonIetfVal{[]byte(`{
"f1": "hello"
"f1mod:f1": "hello"
}`)}},
}, {
name: "struct val - ietf json different module",
Expand Down Expand Up @@ -3858,7 +3858,7 @@ func TestMarshal7951(t *testing.T) {
inArgs: []Marshal7951Arg{
&RFC7951JSONConfig{AppendModuleName: true},
},
want: `{"f1":"hello"}`,
want: `{"f1mod:f1":"hello"}`,
}, {
desc: "complex children with module name prepend request",
in: &ietfRenderExample{
Expand All @@ -3873,22 +3873,22 @@ func TestMarshal7951(t *testing.T) {
JSONIndent(" "),
},
want: `{
"enum-list": [
"f1mod:enum-list": [
{
"config": {
"key": "foo:VAL_ONE"
},
"key": "foo:VAL_ONE"
}
],
"f2mod:config": {
"f2": "bar"
},
"mixed-list": [
"f1mod:mixed-list": [
"foo:VAL_ONE",
"test",
42
]
],
"f2mod:config": {
"f2": "bar"
}
}`,
}, {
desc: "complex children with PrependModuleNameIdentityref=true",
Expand Down Expand Up @@ -3935,22 +3935,22 @@ func TestMarshal7951(t *testing.T) {
JSONIndent(" "),
},
want: `{
"enum-list": [
"f1mod:enum-list": [
{
"config": {
"key": "foo:VAL_ONE"
},
"key": "foo:VAL_ONE"
}
],
"f2mod:config": {
"f2": "bar"
},
"mixed-list": [
"f1mod:mixed-list": [
"foo:VAL_ONE",
"test",
42
]
],
"f2mod:config": {
"f2": "bar"
}
}`,
}}

Expand Down

0 comments on commit 774960a

Please sign in to comment.