繁体   English   中英

Yang 模式中联合类型的默认字符串值

[英]Default string values for union types in Yang Schema

为什么不能在下面的模式中为叶子wibble分配一个默认值"-" (注释不在模式中,为了清楚起见添加到帖子中)

module type
{
    namespace "example.com";
    prefix "foo";
    
    typedef optional-value {
        type  union {
            type uint8 {
                range "0 .. 99";
            }
            
            type string {
                pattern "^-$";
            }
        }
    }
    
    container bar {
        leaf wibble {
            type optional-value;
            default "-"; ### NOT OKAY
        }
        
        leaf wobble {
            type optional-value;
            default 42;  ### OKAY
        }
    }
}

yanglint(版本 0.16.105)不验证上述架构并返回错误消息:

err : Invalid value "-" in "wibble" element. (/type:wibble)
err : Module "type" parsing failed.

做了一些更多的实验,似乎无法为带有模式的字符串分配默认值

module tmp
{
    namespace "example.com";
    prefix "foo";
    
    container bar {
        leaf wibble {
            type string {
                pattern "^x$";
            }
            default "x";    ### NOT OKAY
        }
        
        leaf wobble {
            type string;
            default "y";    ### OKAY
        }
    }
}

杨林特输出:

err : Value "x" does not satisfy the constraint "^x$" (range, length, or pattern). (/tmp:wibble)
err : Module "tmp" parsing failed.

在 YANG 中,使用XML Schema 中的正则表达式风格,它不需要^$来锚定表达式,以便它们对整个值进行数学运算。 所有 XSD 表达式都是隐式锚定的。 您可以尝试从您的模式中删除这些字符,然后再试一次。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM