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

Revert behaviour to not prepend non-root top-level fields in JSON rendering #653

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2873,15 +2873,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 @@ -3895,7 +3895,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 @@ -4201,7 +4201,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 @@ -4216,22 +4216,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 @@ -4278,22 +4278,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