Merge pull request #310 from lukon89/master

Convert int64, uint64 and decimal64 to string in xml to json
This commit is contained in:
Olof Hagsand 2022-02-26 10:13:31 +01:00 committed by GitHub
commit 86ebe9f2fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View file

@ -587,15 +587,25 @@ xml2json_encode_leafs(cxobj *xb,
else else
cprintf(cb, "%s", body); cprintf(cb, "%s", body);
break; break;
case CGV_INT64:
case CGV_UINT64:
case CGV_DEC64:
// [RFC7951] JSON Encoding of YANG Data
// 6.1 Numeric Types - A value of the "int64", "uint64", or "decimal64" type is represented as a JSON string
if (yang_keyword_get(yp) == Y_LEAF_LIST && xml_child_nr_type(xml_parent(xp), CX_ELMNT) == 1) {
cprintf(cb, "[%s]", body);
}
else {
cprintf(cb, "%s", body);
}
quote = 1;
break;
case CGV_INT8: case CGV_INT8:
case CGV_INT16: case CGV_INT16:
case CGV_INT32: case CGV_INT32:
case CGV_INT64:
case CGV_UINT8: case CGV_UINT8:
case CGV_UINT16: case CGV_UINT16:
case CGV_UINT32: case CGV_UINT32:
case CGV_UINT64:
case CGV_DEC64:
case CGV_BOOL: case CGV_BOOL:
cprintf(cb, "%s", body); cprintf(cb, "%s", body);
quote = 0; quote = 0;

View file

@ -210,10 +210,10 @@ expectpart "$(curl $CURLOPTS -H "Accept: application/yang-data+xml" -X GET $RCPR
#--------------- json type tests #--------------- json type tests
new "restconf POST type x3 POST" new "restconf POST type x3 POST"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"example:types":{"tint":42,"tdec64":42.123,"tbool":false,"tstr":"str"}}' $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201" "Location: $RCPROTO://localhost/restconf/data/example:types" expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"example:types":{"tint":42,"tdec64":"42.123","tbool":false,"tstr":"str"}}' $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201" "Location: $RCPROTO://localhost/restconf/data/example:types"
new "restconf POST type x3 GET" new "restconf POST type x3 GET"
expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example:types)" 0 "HTTP/$HVER 200" '{"example:types":{"tint":42,"tdec64":42.123,"tbool":false,"tstr":"str"}}' expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example:types)" 0 "HTTP/$HVER 200" '{"example:types":{"tint":42,"tdec64":"42.123","tbool":false,"tstr":"str"}}'
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
new "Kill restconf daemon" new "Kill restconf daemon"