* Fixed: [restconf GET json response does not encode top level node with namespace as per rfc #303](https://github.com/clicon/clixon/issues/303)

This commit is contained in:
Olof hagsand 2022-02-17 18:42:37 +01:00
parent 4631b02e00
commit bf00fdf2c1
12 changed files with 57 additions and 11 deletions

View file

@ -784,6 +784,11 @@ xml2json1_cbuf(cbuf *cb,
if (ys_real_module(ys, &ymod) < 0)
goto done;
modname = yang_argument_get(ymod);
/* Special case for ietf-netconf -> ietf-restconf translation
* A special case is for return data on the form {"data":...}
*/
if (strcmp(modname, "ietf-netconf")==0)
modname = "ietf-restconf";
if (modname0 && strcmp(modname, modname0) == 0)
modname=NULL;
else
@ -1065,7 +1070,6 @@ xml2json_cbuf(cbuf *cb,
pretty?"\n":"",
pretty?level*JSON_INDENT:0,"",
pretty?"\n":"");
retval = 0;
done:
return retval;

View file

@ -466,15 +466,19 @@ clicon_rpc_get_config(clicon_handle h,
goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
goto done;
yspec = clicon_dbspec_yang(h);
/* Send xml error back: first check error, then ok */
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
goto done;
if (xml_bind_special(xd, yspec, "/nc:get-config/output/data") < 0)
goto done;
}
else{
yspec = clicon_dbspec_yang(h);
if (xml_bind_special(xd, yspec, "/nc:get-config/output/data") < 0)
goto done;
if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
@ -838,15 +842,19 @@ clicon_rpc_get(clicon_handle h,
goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
goto done;
yspec = clicon_dbspec_yang(h);
/* Send xml error back: first check error, then ok */
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
goto done;
if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
goto done;
}
else{
yspec = clicon_dbspec_yang(h);
if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
goto done;
if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
@ -974,15 +982,19 @@ clicon_rpc_get_pageable_list(clicon_handle h,
goto done;
if (clicon_rpc_msg(h, msg, &xret) < 0)
goto done;
yspec = clicon_dbspec_yang(h);
/* Send xml error back: first check error, then ok */
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
if ((xd = xml_new(NETCONF_OUTPUT_DATA, NULL, CX_ELMNT)) == NULL)
goto done;
if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
goto done;
}
else{
yspec = clicon_dbspec_yang(h);
if (xml_bind_special(xd, yspec, "/nc:get/output/data") < 0)
goto done;
if ((ret = xml_bind_yang(xd, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){

View file

@ -752,3 +752,22 @@ xml_bind_yang_rpc_reply(cxobj *xrpc,
retval = 0;
goto done;
}
/*! Special case explicit binding
*/
int
xml_bind_special(cxobj *xd,
yang_stmt *yspec,
char *schema_nodeid)
{
int retval = -1;
yang_stmt *yd;
if (yang_abs_schema_nodeid(yspec, schema_nodeid, &yd) < 0)
goto done;
if (yd)
xml_spec_set(xd, yd);
retval = 0;
done:
return retval;
}

View file

@ -1170,7 +1170,9 @@ yang_find_schemanode(yang_stmt *yn,
} /* Y_CHOICE */
else
if (yang_schemanode(ys)){
if (yang_keyword_get(ys) == Y_INPUT || yang_keyword_get(ys) == Y_OUTPUT)
if (strcmp(argument, "input") == 0 && yang_keyword_get(ys) == Y_INPUT)
ysmatch = ys;
else if (strcmp(argument, "output") == 0 && yang_keyword_get(ys) == Y_OUTPUT)
ysmatch = ys;
else if (argument == NULL)
ysmatch = ys;
@ -3122,7 +3124,7 @@ schema_nodeid_iterate(yang_stmt *yn,
goto ok;
}
yp = ys; /* ys is matched */
ys = NULL;
} /* while cv */
assert(yp && yang_schemanode((yang_stmt*)yp));
*yres = (yang_stmt*)yp;