Fixed: [Returning a string while Querying leaf-list for single entry](https://github.com/clicon/clixon/issues/326)
This commit is contained in:
parent
7065d6f760
commit
0c81b66ef3
6 changed files with 66 additions and 8 deletions
|
|
@ -123,6 +123,7 @@ Users may have to change how they access the system
|
|||
|
||||
### Corrected Bugs
|
||||
|
||||
* Fixed: [Returning a string while Querying leaf-list for single entry](https://github.com/clicon/clixon/issues/326)
|
||||
* Fixed: A long TLS+HTTP/2 request such as by a browser causing block of other requests.
|
||||
* Fixed: [Error message seen twice in some cases](https://github.com/clicon/clixon/issues/325)
|
||||
* Fixed: [if choice is declared with multiple elements or leaf-list with in a case scope , addition or updation is not happening as expected](https://github.com/clicon/clixon/issues/327)
|
||||
|
|
|
|||
|
|
@ -1062,15 +1062,29 @@ xml2json_cbuf(cbuf *cb,
|
|||
cxobj *x,
|
||||
int pretty)
|
||||
{
|
||||
int retval = 1;
|
||||
int level = 0;
|
||||
|
||||
int retval = 1;
|
||||
int level = 0;
|
||||
yang_stmt *y;
|
||||
enum array_element_type arraytype = NO_ARRAY;
|
||||
|
||||
cprintf(cb, "%*s{%s",
|
||||
pretty?level*JSON_INDENT:0,"",
|
||||
pretty?"\n":"");
|
||||
|
||||
if ((y = xml_spec(x)) != NULL){
|
||||
switch (yang_keyword_get(y)){
|
||||
case Y_LEAF_LIST:
|
||||
case Y_LIST:
|
||||
arraytype = SINGLE_ARRAY;
|
||||
break;
|
||||
default:
|
||||
arraytype = NO_ARRAY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (xml2json1_cbuf(cb,
|
||||
x,
|
||||
NO_ARRAY,
|
||||
arraytype,
|
||||
level+1,
|
||||
pretty,
|
||||
0,
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ edit table
|
|||
show config json
|
||||
EOF
|
||||
new "show config json"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '{"clixon-example:parameter":{"name":"a","value":"42"}}'
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '{"clixon-example:parameter":\[{"name":"a","value":"42"}\]}'
|
||||
|
||||
cat <<EOF > $fin
|
||||
edit table
|
||||
|
|
|
|||
|
|
@ -29,6 +29,20 @@ module json{
|
|||
type string;
|
||||
}
|
||||
}
|
||||
leaf-list l1{
|
||||
description "top-level";
|
||||
type int32;
|
||||
}
|
||||
list l2{
|
||||
description "top-level";
|
||||
key name;
|
||||
leaf name{
|
||||
type int32;
|
||||
}
|
||||
leaf value{
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
|
|
@ -54,6 +68,14 @@ function testrun()
|
|||
|
||||
new "test params: -y $fyang"
|
||||
|
||||
testrun "top one leaf-list" '{"json:l1":[1]}' '<l1 xmlns="urn:example:clixon">1</l1>'
|
||||
|
||||
# XXX There is a problem with how clixon shows json and xml on top-level
|
||||
# Typically, there is a loop over xml children to cope with the case if there is more
|
||||
# than one top-level which is invalid in XML.
|
||||
# See for example clixon_util_xml.c, clixon_util_json.c, cli_auto_show, cli_show_config
|
||||
#testrun "top two leaf-list" '{"json:l1":[1,2]}' '<l1 xmlns="urn:example:clixon">1</l1><l1 xmlns="urn:example:clixon">2</l1>'
|
||||
|
||||
testrun "one leaf-list" '{"json:c":{"l1":[1]}}' '<c xmlns="urn:example:clixon"><l1>1</l1></c>'
|
||||
|
||||
testrun "two leaf-list" '{"json:c":{"l1":[1,2]}}' '<c xmlns="urn:example:clixon"><l1>1</l1><l1>2</l1></c>'
|
||||
|
|
@ -62,6 +84,10 @@ testrun "three leaf-list" '{"json:c":{"l1":[1,2,3]}}' '<c xmlns="urn:example:cli
|
|||
|
||||
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 "top one list" '{"json:l2":[{"name":1,"value":"x"}]}' '<l2 xmlns="urn:example:clixon"><name>1</name><value>x</value></l2>'
|
||||
|
||||
# XXX
|
||||
#testrun "top two list" '{"json:l2":[{"name":1,"value":"x"},{"name":2,"value":"x"}]}' '<l2 xmlns="urn:example:clixon"><name>1</name><value>x</value></l2><l2 xmlns="urn:example:clixon"><name>2</name><value>x</value></l2>'
|
||||
|
||||
testrun "one list" '{"json:c":{"l2":[{"name":1,"value":"x"}]}}' '<c xmlns="urn:example:clixon"><l2><name>1</name><value>x</value></l2></c>'
|
||||
|
||||
|
|
|
|||
|
|
@ -145,12 +145,20 @@ main(int argc,
|
|||
xml_print(stderr, xerr);
|
||||
goto done;
|
||||
}
|
||||
#if 0
|
||||
if (json)
|
||||
xml2json_cbuf(cb, xt, pretty); /* print json */
|
||||
else
|
||||
clicon_xml2cbuf(cb, xt, 0, pretty, -1); /* print xml */
|
||||
#else
|
||||
xc = NULL;
|
||||
/* XXX This is troublesome for JSON top-level lists */
|
||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
||||
if (json)
|
||||
xml2json_cbuf(cb, xc, pretty); /* print xml */
|
||||
xml2json_cbuf(cb, xc, pretty); /* print json */
|
||||
else
|
||||
clicon_xml2cbuf(cb, xc, 0, pretty, -1); /* print xml */
|
||||
#endif
|
||||
fprintf(stdout, "%s", cbuf_get(cb));
|
||||
fflush(stdout);
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -337,12 +337,21 @@ main(int argc,
|
|||
}
|
||||
/* 4. Output data (xml/json) */
|
||||
if (output){
|
||||
#if 0
|
||||
if (jsonout)
|
||||
xml2json_cbuf(cb, xt, pretty); /* print json */
|
||||
else
|
||||
clicon_xml2cbuf(cb, xt, 0, pretty, -1); /* print xml */
|
||||
#else
|
||||
xc = NULL;
|
||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
||||
/* XXX This is troublesome for JSON top-level lists */
|
||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL){
|
||||
if (jsonout)
|
||||
xml2json_cbuf(cb, xc, pretty); /* print xml */
|
||||
xml2json_cbuf(cb, xc, pretty); /* print json */
|
||||
else
|
||||
clicon_xml2cbuf(cb, xc, 0, pretty, -1); /* print xml */
|
||||
}
|
||||
#endif
|
||||
fprintf(stdout, "%s", cbuf_get(cb));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue