@@ -706,6 +706,7 @@ static void
706706yin_print_typedef (struct lyout * out , int level , const struct lys_module * module , const struct lys_tpdf * tpdf )
707707{
708708 yin_print_open (out , level , "typedef" , "name" , tpdf -> name , 0 );
709+ const char * dflt ;
709710
710711 level ++ ;
711712 yin_print_snode_common (out , level , (struct lys_node * )tpdf );
@@ -714,7 +715,15 @@ yin_print_typedef(struct lyout *out, int level, const struct lys_module *module,
714715 yin_print_open (out , level , "units" , "name" , tpdf -> units , 1 );
715716 }
716717 if (tpdf -> dflt ) {
717- yin_print_open (out , level , "default" , "value" , tpdf -> dflt , 1 );
718+ if (tpdf -> flags & LYS_DFLTJSON ) {
719+ dflt = transform_json2schema (module , tpdf -> dflt );
720+ } else {
721+ dflt = tpdf -> dflt ;
722+ }
723+ yin_print_open (out , level , "default" , "value" , dflt , 1 );
724+ if (tpdf -> flags & LYS_DFLTJSON ) {
725+ lydict_remove (module -> ctx , dflt );
726+ }
718727 }
719728 level -- ;
720729
@@ -874,6 +883,7 @@ yin_print_leaf(struct lyout *out, int level, const struct lys_node *node)
874883{
875884 int i ;
876885 struct lys_node_leaf * leaf = (struct lys_node_leaf * )node ;
886+ const char * dflt ;
877887
878888 yin_print_open (out , level , "leaf" , "name" , node -> name , 0 );
879889
@@ -894,7 +904,15 @@ yin_print_leaf(struct lyout *out, int level, const struct lys_node *node)
894904 yin_print_open (out , level , "units" , "name" , leaf -> units , 1 );
895905 }
896906 if (leaf -> dflt ) {
897- yin_print_open (out , level , "default" , "value" , leaf -> dflt , 1 );
907+ if (leaf -> flags & LYS_DFLTJSON ) {
908+ dflt = transform_json2schema (node -> module , leaf -> dflt );
909+ } else {
910+ dflt = leaf -> dflt ;
911+ }
912+ yin_print_open (out , level , "default" , "value" , dflt , 1 );
913+ if (leaf -> flags & LYS_DFLTJSON ) {
914+ lydict_remove (node -> module -> ctx , dflt );
915+ }
898916 }
899917 level -- ;
900918
@@ -937,6 +955,7 @@ yin_print_leaflist(struct lyout *out, int level, const struct lys_node *node)
937955{
938956 int i ;
939957 struct lys_node_leaflist * llist = (struct lys_node_leaflist * )node ;
958+ const char * dflt ;
940959
941960 yin_print_open (out , level , "leaf-list" , "name" , node -> name , 0 );
942961
@@ -957,7 +976,15 @@ yin_print_leaflist(struct lyout *out, int level, const struct lys_node *node)
957976 yin_print_open (out , level , "units" , "name" , llist -> units , 1 );
958977 }
959978 for (i = 0 ; i < llist -> dflt_size ; i ++ ) {
960- yin_print_open (out , level , "default" , "value" , llist -> dflt [i ], 1 );
979+ if (llist -> flags & LYS_DFLTJSON ) {
980+ dflt = transform_json2schema (node -> module , llist -> dflt [i ]);
981+ } else {
982+ dflt = llist -> dflt [i ];
983+ }
984+ yin_print_open (out , level , "default" , "value" , dflt , 1 );
985+ if (llist -> flags & LYS_DFLTJSON ) {
986+ lydict_remove (node -> module -> ctx , dflt );
987+ }
961988 }
962989 if (llist -> min > 0 ) {
963990 yin_print_unsigned (out , level , "min-elements" , "value" , llist -> min );
0 commit comments