* [JSON leaf-list output single element leaf-list does not use array](https://github.com/clicon/clixon/issues/289)
This commit is contained in:
parent
339b744835
commit
f4b35cb270
5 changed files with 30 additions and 30 deletions
|
|
@ -231,11 +231,7 @@ array_eval(cxobj *xprev,
|
||||||
else if (eqnext)
|
else if (eqnext)
|
||||||
arraytype = FIRST_ARRAY;
|
arraytype = FIRST_ARRAY;
|
||||||
else if ((ys = xml_spec(x)) != NULL) {
|
else if ((ys = xml_spec(x)) != NULL) {
|
||||||
if (yang_keyword_get(ys) == Y_LIST
|
if (yang_keyword_get(ys) == Y_LIST || yang_keyword_get(ys) == Y_LEAF_LIST)
|
||||||
#if 0 /* XXX instead see special case in xml2json_encode_leafs */
|
|
||||||
|| yang_keyword_get(ys) == Y_LEAF_LIST
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
arraytype = SINGLE_ARRAY;
|
arraytype = SINGLE_ARRAY;
|
||||||
else
|
else
|
||||||
arraytype = NO_ARRAY;
|
arraytype = NO_ARRAY;
|
||||||
|
|
@ -601,12 +597,6 @@ xml2json_encode_leafs(cxobj *xb,
|
||||||
case CGV_UINT64:
|
case CGV_UINT64:
|
||||||
case CGV_DEC64:
|
case CGV_DEC64:
|
||||||
case CGV_BOOL:
|
case CGV_BOOL:
|
||||||
#if 1 /* Special case */
|
|
||||||
if (yang_keyword_get(yp) == Y_LEAF_LIST
|
|
||||||
&& xml_child_nr_type(xml_parent(xp), CX_ELMNT) == 1)
|
|
||||||
cprintf(cb, "[%s]", body);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
cprintf(cb, "%s", body);
|
cprintf(cb, "%s", body);
|
||||||
quote = 0;
|
quote = 0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -614,7 +604,12 @@ xml2json_encode_leafs(cxobj *xb,
|
||||||
/* special case YANG empty type */
|
/* special case YANG empty type */
|
||||||
if (body == NULL && strcmp(restype, "empty")==0){
|
if (body == NULL && strcmp(restype, "empty")==0){
|
||||||
quote = 0;
|
quote = 0;
|
||||||
cprintf(cb, "[null]");
|
if (keyword == Y_LEAF)
|
||||||
|
cprintf(cb, "[null]");
|
||||||
|
else if (keyword == Y_LEAF_LIST && strcmp(restype, "empty") == 0)
|
||||||
|
cprintf(cb, "[null]");
|
||||||
|
else
|
||||||
|
cprintf(cb, "null");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -13,19 +13,21 @@ module json{
|
||||||
prefix ex;
|
prefix ex;
|
||||||
namespace "urn:example:clixon";
|
namespace "urn:example:clixon";
|
||||||
container c{
|
container c{
|
||||||
leaf-list l1{
|
leaf-list l1{
|
||||||
type int32;
|
type int32;
|
||||||
}
|
}
|
||||||
list l2{
|
list l2{
|
||||||
key name;
|
key name;
|
||||||
leaf name{
|
leaf name{
|
||||||
type int32;
|
type int32;
|
||||||
}
|
}
|
||||||
leaf value{
|
leaf value{
|
||||||
type string;
|
type string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
leaf extra{
|
||||||
|
type string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -58,6 +60,9 @@ testrun "two leaf-list" '{"json:c":{"l1":[1,2]}}' '<c xmlns="urn:example:clixon"
|
||||||
|
|
||||||
testrun "three leaf-list" '{"json:c":{"l1":[1,2,3]}}' '<c xmlns="urn:example:clixon"><l1>1</l1><l1>2</l1><l1>3</l1></c>'
|
testrun "three leaf-list" '{"json:c":{"l1":[1,2,3]}}' '<c xmlns="urn:example:clixon"><l1>1</l1><l1>2</l1><l1>3</l1></c>'
|
||||||
|
|
||||||
|
testrun "multiple leaf-list" '{"json:c":{"l1":[1,2],"extra":"abc"}}' '<c xmlns="urn:example:clixon"><l1>1</l1><l1>2</l1><extra>abc</extra></c>'
|
||||||
|
|
||||||
|
|
||||||
testrun "one list" '{"json:c":{"l2":[{"name":1,"value":"x"}]}}' '<c xmlns="urn:example:clixon"><l2><name>1</name><value>x</value></l2></c>'
|
testrun "one list" '{"json:c":{"l2":[{"name":1,"value":"x"}]}}' '<c xmlns="urn:example:clixon"><l2><name>1</name><value>x</value></l2></c>'
|
||||||
|
|
||||||
testrun "two list" '{"json:c":{"l2":[{"name":1,"value":"x"},{"name":2,"value":"y"}]}}' '<c xmlns="urn:example:clixon"><l2><name>1</name><value>x</value></l2><l2><name>2</name><value>y</value></l2></c>'
|
testrun "two list" '{"json:c":{"l2":[{"name":1,"value":"x"},{"name":2,"value":"y"}]}}' '<c xmlns="urn:example:clixon"><l2><name>1</name><value>x</value></l2><l2><name>2</name><value>y</value></l2></c>'
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ expecteofx "$clixon_util_xml -ovJy $fyang" 0 "$JSON" "$XML"
|
||||||
|
|
||||||
# Leaf-lists single
|
# Leaf-lists single
|
||||||
XML='<leaf-lists xmlns="urn:example:clixon"><a></a><b></b></leaf-lists>'
|
XML='<leaf-lists xmlns="urn:example:clixon"><a></a><b></b></leaf-lists>'
|
||||||
JSON='{"json:leaf-lists":{"a":[null],"b":""}}'
|
JSON='{"json:leaf-lists":{"a":[[null]],"b":[""]}}'
|
||||||
|
|
||||||
new "leaf-list single xml to json"
|
new "leaf-list single xml to json"
|
||||||
expecteofx "$clixon_util_xml -ovjy $fyang" 0 "$XML" "$JSON"
|
expecteofx "$clixon_util_xml -ovjy $fyang" 0 "$XML" "$JSON"
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ new "Add NACM read path rule XML"
|
||||||
expectpart "$(curl -u andy:bar $CURLOPTS -X POST $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm -H 'Content-Type: application/yang-data+xml' -d '<rule-list xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"><name>limited-acl</name><group>limited</group><rule><name>table</name><module-name>*</module-name><access-operations>read</access-operations><path xmlns:ex="urn:example:nacm">/ex:table</path><action>permit</action></rule></rule-list>')" 0 "HTTP/$HVER 201"
|
expectpart "$(curl -u andy:bar $CURLOPTS -X POST $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm -H 'Content-Type: application/yang-data+xml' -d '<rule-list xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm"><name>limited-acl</name><group>limited</group><rule><name>table</name><module-name>*</module-name><access-operations>read</access-operations><path xmlns:ex="urn:example:nacm">/ex:table</path><action>permit</action></rule></rule-list>')" 0 "HTTP/$HVER 201"
|
||||||
|
|
||||||
new "Read NACM rule"
|
new "Read NACM rule"
|
||||||
expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl)" 0 "HTTP/$HVER 200" '{"ietf-netconf-acm:rule-list":\[{"name":"limited-acl","group":"limited","rule":\[{"name":"table","module-name":"\*","path":"/ex:table","access-operations":"read","action":"permit"}\]}\]}'
|
expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl)" 0 "HTTP/$HVER 200" '{"ietf-netconf-acm:rule-list":\[{"name":"limited-acl","group":\["limited"\],"rule":\[{"name":"table","module-name":"\*","path":"/ex:table","access-operations":"read","action":"permit"}\]}\]}'
|
||||||
|
|
||||||
new "limit read OK"
|
new "limit read OK"
|
||||||
expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table/parameters/parameter=a)" 0 "HTTP/$HVER 200" '{"nacm-example:parameter":\[{"name":"a","value":"72"}\]}'
|
expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table/parameters/parameter=a)" 0 "HTTP/$HVER 200" '{"nacm-example:parameter":\[{"name":"a","value":"72"}\]}'
|
||||||
|
|
@ -141,7 +141,7 @@ new "Add NACM read path rule JSON"
|
||||||
expectpart "$(curl -u andy:bar $CURLOPTS -X POST $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm -H 'Content-Type: application/yang-data+json' -d '{"ietf-netconf-acm:rule-list":[{"name":"limited-acl","group":"limited","rule":[{"name":"table","module-name":"*","path":"/ex:table","access-operations":"read","action":"permit"}]}]}')" 0 "HTTP/$HVER 201"
|
expectpart "$(curl -u andy:bar $CURLOPTS -X POST $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm -H 'Content-Type: application/yang-data+json' -d '{"ietf-netconf-acm:rule-list":[{"name":"limited-acl","group":"limited","rule":[{"name":"table","module-name":"*","path":"/ex:table","access-operations":"read","action":"permit"}]}]}')" 0 "HTTP/$HVER 201"
|
||||||
|
|
||||||
new "Read NACM rule"
|
new "Read NACM rule"
|
||||||
expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl)" 0 "HTTP/$HVER 200" '{"ietf-netconf-acm:rule-list":\[{"name":"limited-acl","group":"limited","rule":\[{"name":"table","module-name":"\*","path":"/ex:table","access-operations":"read","action":"permit"}\]}\]}'
|
expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl)" 0 "HTTP/$HVER 200" '{"ietf-netconf-acm:rule-list":\[{"name":"limited-acl","group":\["limited"\],"rule":\[{"name":"table","module-name":"\*","path":"/ex:table","access-operations":"read","action":"permit"}\]}\]}'
|
||||||
|
|
||||||
new "limit read OK (Set rul w JSON)"
|
new "limit read OK (Set rul w JSON)"
|
||||||
expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table/parameters/parameter=a)" 0 "HTTP/$HVER 200" '{"nacm-example:parameter":\[{"name":"a","value":"72"}\]}'
|
expectpart "$(curl -u wilma:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:table/parameters/parameter=a)" 0 "HTTP/$HVER 200" '{"nacm-example:parameter":\[{"name":"a","value":"72"}\]}'
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,7 @@ function testrun()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "restconf get data type json"
|
new "restconf get data type json"
|
||||||
expectpart "$(curl $CURLOPTS -X GET $proto://$addr/restconf/data/clixon-example:state/op=42)" 0 '{"clixon-example:op":"42"}'
|
expectpart "$(curl $CURLOPTS -X GET $proto://$addr/restconf/data/clixon-example:state/op=42)" 0 '{"clixon-example:op":\["42"\]}'
|
||||||
|
|
||||||
new "restconf get state operation"
|
new "restconf get state operation"
|
||||||
# Cant get shell macros to work, inline matching from lib.sh
|
# Cant get shell macros to work, inline matching from lib.sh
|
||||||
|
|
@ -398,7 +398,7 @@ function testrun()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "restconf get state operation type json"
|
new "restconf get state operation type json"
|
||||||
expectpart "$(curl $CURLOPTS -X GET $proto://$addr/restconf/data/clixon-example:state/op=42)" 0 '{"clixon-example:op":"42"}'
|
expectpart "$(curl $CURLOPTS -X GET $proto://$addr/restconf/data/clixon-example:state/op=42)" 0 '{"clixon-example:op":\["42"\]}'
|
||||||
|
|
||||||
new "restconf get state operation type xml"
|
new "restconf get state operation type xml"
|
||||||
# Cant get shell macros to work, inline matching from lib.sh
|
# Cant get shell macros to work, inline matching from lib.sh
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue