Skip to content

Commit 774960a

Browse files
committed
Revert behaviour to not prepend non-root top-level fields in JSON rendering.
This is a partial revert of #638, see discussion in #648.
1 parent c15884d commit 774960a

3 files changed

Lines changed: 21 additions & 25 deletions

File tree

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
@@ -2769,15 +2769,15 @@ func TestConstructJSON(t *testing.T) {
27692769
},
27702770
inAppendMod: true,
27712771
wantIETF: map[string]interface{}{
2772-
"f1": "foo",
2773-
"config": map[string]interface{}{
2772+
"f1mod:f1": "foo",
2773+
"f1mod:config": map[string]interface{}{
27742774
"f2mod:f6": "mat",
27752775
},
27762776
"f2mod:config": map[string]interface{}{
27772777
"f2": "bar",
27782778
"f3mod:f7": "bat",
27792779
},
2780-
"f3": map[string]interface{}{
2780+
"f1mod:f3": map[string]interface{}{
27812781
"f42mod:config": map[string]interface{}{
27822782
"f4": "baz",
27832783
},
@@ -3552,7 +3552,7 @@ func TestEncodeTypedValue(t *testing.T) {
35523552
},
35533553
inEnc: gnmipb.Encoding_JSON_IETF,
35543554
want: &gnmipb.TypedValue{Value: &gnmipb.TypedValue_JsonIetfVal{[]byte(`{
3555-
"f1": "hello"
3555+
"f1mod:f1": "hello"
35563556
}`)}},
35573557
}, {
35583558
name: "struct val - ietf json different module",
@@ -3858,7 +3858,7 @@ func TestMarshal7951(t *testing.T) {
38583858
inArgs: []Marshal7951Arg{
38593859
&RFC7951JSONConfig{AppendModuleName: true},
38603860
},
3861-
want: `{"f1":"hello"}`,
3861+
want: `{"f1mod:f1":"hello"}`,
38623862
}, {
38633863
desc: "complex children with module name prepend request",
38643864
in: &ietfRenderExample{
@@ -3873,22 +3873,22 @@ func TestMarshal7951(t *testing.T) {
38733873
JSONIndent(" "),
38743874
},
38753875
want: `{
3876-
"enum-list": [
3876+
"f1mod:enum-list": [
38773877
{
38783878
"config": {
38793879
"key": "foo:VAL_ONE"
38803880
},
38813881
"key": "foo:VAL_ONE"
38823882
}
38833883
],
3884-
"f2mod:config": {
3885-
"f2": "bar"
3886-
},
3887-
"mixed-list": [
3884+
"f1mod:mixed-list": [
38883885
"foo:VAL_ONE",
38893886
"test",
38903887
42
3891-
]
3888+
],
3889+
"f2mod:config": {
3890+
"f2": "bar"
3891+
}
38923892
}`,
38933893
}, {
38943894
desc: "complex children with PrependModuleNameIdentityref=true",
@@ -3935,22 +3935,22 @@ func TestMarshal7951(t *testing.T) {
39353935
JSONIndent(" "),
39363936
},
39373937
want: `{
3938-
"enum-list": [
3938+
"f1mod:enum-list": [
39393939
{
39403940
"config": {
39413941
"key": "foo:VAL_ONE"
39423942
},
39433943
"key": "foo:VAL_ONE"
39443944
}
39453945
],
3946-
"f2mod:config": {
3947-
"f2": "bar"
3948-
},
3949-
"mixed-list": [
3946+
"f1mod:mixed-list": [
39503947
"foo:VAL_ONE",
39513948
"test",
39523949
42
3953-
]
3950+
],
3951+
"f2mod:config": {
3952+
"f2": "bar"
3953+
}
39543954
}`,
39553955
}}
39563956

0 commit comments

Comments
 (0)