Uploaded image for project: 'mdsal'
  1. mdsal
  2. MDSAL-405

Generated unions fail to enforce patterns

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • 14.0.0
    • 3.0.2
    • Binding codegen

      The following snippet, taken from openconfig-bgp-policy.yang:

        typedef bgp-set-med-type {
          type union {
            type uint32;
            type string {
              pattern "^[+-][0-9]+";
            }
            type enumeration {
              enum IGP {
                description "set the MED value to the IGP cost toward the
                next hop for the route";
              }
            }
          }
          description
            "Type definition for specifying how the BGP MED can
            be set in BGP policy actions. The three choices are to set
            the MED directly, increment/decrement using +/- notation,
            and setting it to the IGP cost (predefined value).";
        }
      
      

      results in the following code:

          public static final List<String> PATTERN_CONSTANTS = ImmutableList.of("^(?:\\^[+-][0-9]+)$");
          private static final Pattern patterns = Pattern.compile(PATTERN_CONSTANTS.get(0));
          private static final String regexes = "^[+-][0-9]+";
          private final Long _uint32;
          private final String _string;
          private final Enumeration _enumeration;
      
      
          private static void checkUint32Range(final long value) {
              if (value >= 0L && value <= 4294967295L) {
                  return;
              }
              CodeHelpers.throwInvalidRange("[[0..4294967295]]", value);
          }
          public BgpSetMedType(Long _uint32) {
              super();
              checkUint32Range(_uint32);
              
              this._uint32 = _uint32;
              this._string = null;
              this._enumeration = null;
          }
          
          private static void check_stringLength(final String value) {
          }
          public BgpSetMedType(String _string) {
              super();
              check_stringLength(_string);
              
              this._string = _string;
              this._uint32 = null;
              this._enumeration = null;
          }
      
      

      Note there is a useless check_stringLength() emitted, which is probably fine. What is not fine is that the String enforcement is completely missing, eventhough we have generated the appropriate regexs constant.

            ivanhrasko Ivan Hrasko
            rovarga Robert Varga
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: