Skip to content

Commit d5a8afe

Browse files
authored
Revert behaviour to not prepend non-root top-level fields in JSON rendering. (#653)
This is a partial revert of #638, see discussion in #648.
1 parent 4688fca commit d5a8afe

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

demo/bgp/testdata/bgp-ietf.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"global": {
2+
"openconfig-network-instance:global": {
33
"config": {
44
"as": 15169,
55
"router-id": "192.0.2.42"
66
}
77
},
8-
"neighbors": {
8+
"openconfig-network-instance:neighbors": {
99
"neighbor": [
1010
{
1111
"config": {

ygot/render.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ func (*RFC7951JSONConfig) IsMarshal7951Arg() {}
951951
// to JSON described by RFC7951. The supplied args control options corresponding
952952
// to the method by which JSON is marshalled.
953953
func ConstructIETFJSON(s ValidatedGoStruct, args *RFC7951JSONConfig) (map[string]interface{}, error) {
954-
return structJSON(s, s.ΛBelongingModule(), jsonOutputConfig{
954+
return structJSON(s, "", jsonOutputConfig{
955955
jType: RFC7951,
956956
rfc7951Config: args,
957957
})
@@ -1000,11 +1000,7 @@ func Marshal7951(d interface{}, args ...Marshal7951Arg) ([]byte, error) {
10001000
indent = string(v)
10011001
}
10021002
}
1003-
var parentMod string
1004-
if s, ok := d.(ValidatedGoStruct); ok {
1005-
parentMod = s.ΛBelongingModule()
1006-
}
1007-
j, err := jsonValue(reflect.ValueOf(d), parentMod, jsonOutputConfig{
1003+
j, err := jsonValue(reflect.ValueOf(d), "", jsonOutputConfig{
10081004
jType: RFC7951,
10091005
rfc7951Config: rfcCfg,
10101006
})

ygot/render_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,15 +2873,15 @@ func TestConstructJSON(t *testing.T) {
28732873
},
28742874
inAppendMod: true,
28752875
wantIETF: map[string]interface{}{
2876-
"f1": "foo",
2877-
"config": map[string]interface{}{
2876+
"f1mod:f1": "foo",
2877+
"f1mod:config": map[string]interface{}{
28782878
"f2mod:f6": "mat",
28792879
},
28802880
"f2mod:config": map[string]interface{}{
28812881
"f2": "bar",
28822882
"f3mod:f7": "bat",
28832883
},
2884-
"f3": map[string]interface{}{
2884+
"f1mod:f3": map[string]interface{}{
28852885
"f42mod:config": map[string]interface{}{
28862886
"f4": "baz",
28872887
},
@@ -3895,7 +3895,7 @@ func TestEncodeTypedValue(t *testing.T) {
38953895
},
38963896
inEnc: gnmipb.Encoding_JSON_IETF,
38973897
want: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_JsonIetfVal{[]byte(`{
3898-
"f1": "hello"
3898+
"f1mod:f1": "hello"
38993899
}`)}},
39003900
}, {
39013901
name: "struct val - ietf json different module",
@@ -4201,7 +4201,7 @@ func TestMarshal7951(t *testing.T) {
42014201
inArgs: []Marshal7951Arg{
42024202
&RFC7951JSONConfig{AppendModuleName: true},
42034203
},
4204-
want: `{"f1":"hello"}`,
4204+
want: `{"f1mod:f1":"hello"}`,
42054205
}, {
42064206
desc: "complex children with module name prepend request",
42074207
in: &ietfRenderExample{
@@ -4216,22 +4216,22 @@ func TestMarshal7951(t *testing.T) {
42164216
JSONIndent(" "),
42174217
},
42184218
want: `{
4219-
"enum-list": [
4219+
"f1mod:enum-list": [
42204220
{
42214221
"config": {
42224222
"key": "foo:VAL_ONE"
42234223
},
42244224
"key": "foo:VAL_ONE"
42254225
}
42264226
],
4227-
"f2mod:config": {
4228-
"f2": "bar"
4229-
},
4230-
"mixed-list": [
4227+
"f1mod:mixed-list": [
42314228
"foo:VAL_ONE",
42324229
"test",
42334230
42
4234-
]
4231+
],
4232+
"f2mod:config": {
4233+
"f2": "bar"
4234+
}
42354235
}`,
42364236
}, {
42374237
desc: "complex children with PrependModuleNameIdentityref=true",
@@ -4278,22 +4278,22 @@ func TestMarshal7951(t *testing.T) {
42784278
JSONIndent(" "),
42794279
},
42804280
want: `{
4281-
"enum-list": [
4281+
"f1mod:enum-list": [
42824282
{
42834283
"config": {
42844284
"key": "foo:VAL_ONE"
42854285
},
42864286
"key": "foo:VAL_ONE"
42874287
}
42884288
],
4289-
"f2mod:config": {
4290-
"f2": "bar"
4291-
},
4292-
"mixed-list": [
4289+
"f1mod:mixed-list": [
42934290
"foo:VAL_ONE",
42944291
"test",
42954292
42
4296-
]
4293+
],
4294+
"f2mod:config": {
4295+
"f2": "bar"
4296+
}
42974297
}`,
42984298
}}
42994299

0 commit comments

Comments
 (0)