简体   繁体   English

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

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

Why can't the leaf wibble be assigned a default value "-" in the following schema (comments not in schema, added to post for clarity)为什么不能在下面的模式中为叶子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 (version 0.16.105) does not validate the above schema and returns the error message: yanglint(版本 0.16.105)不验证上述架构并返回错误消息:

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

Done some more experimenting and it appears that strings with patterns cannot be assigned default values做了一些更多的实验,似乎无法为带有模式的字符串分配默认值

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
        }
    }
}

yanglint output:杨林特输出:

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

In YANG one uses the regex flavor from XML Schema which doesn't require ^$ to anchor expressions so that they math the entire value.在 YANG 中,使用XML Schema 中的正则表达式风格,它不需要^$来锚定表达式,以便它们对整个值进行数学运算。 All XSD expressions are implicitly anchored.所有 XSD 表达式都是隐式锚定的。 You could try to remove these characters from your patterns and give it another try.您可以尝试从您的模式中删除这些字符,然后再试一次。

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

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