protovalidate/violation

Violations: the rules a message broke, as buf.validate.Violation describes them. The types match TrevRPC’s trevrpc/violations, so a violation here is one there too.

Unset fields are their zero values: an empty string or list, False, 0 or None.

Types

One step of a field path: a field, with the index or key of a repeated or map field’s item.

pub type FieldPathElement {
  FieldPathElement(
    field_number: Int,
    field_name: String,
    field_type: option.Option(FieldType),
    key_type: option.Option(FieldType),
    value_type: option.Option(FieldType),
    subscript: option.Option(Subscript),
  )
}

Constructors

A google.protobuf.FieldDescriptorProto.Type.

pub type FieldType {
  TypeDouble
  TypeFloat
  TypeInt64
  TypeUint64
  TypeInt32
  TypeFixed64
  TypeFixed32
  TypeBool
  TypeString
  TypeGroup
  TypeMessage
  TypeBytes
  TypeUint32
  TypeEnum
  TypeSfixed32
  TypeSfixed64
  TypeSint32
  TypeSint64
  UnknownType(Int)
}

Constructors

  • TypeDouble
  • TypeFloat
  • TypeInt64
  • TypeUint64
  • TypeInt32
  • TypeFixed64
  • TypeFixed32
  • TypeBool
  • TypeString
  • TypeGroup
  • TypeMessage
  • TypeBytes
  • TypeUint32
  • TypeEnum
  • TypeSfixed32
  • TypeSfixed64
  • TypeSint32
  • TypeSint64
  • UnknownType(Int)

    A value the type does not define.

The item of a repeated or map field a path element names.

pub type Subscript {
  Index(Int)
  BoolKey(Bool)
  IntKey(Int)
  UintKey(Int)
  StringKey(String)
}

Constructors

  • Index(Int)
  • BoolKey(Bool)
  • IntKey(Int)
  • UintKey(Int)
  • StringKey(String)

A broken rule: the path of the field it applies to (empty for a rule on the message itself), the path of the rule within buf.validate’s rules, its ID, a message saying what broke it, and, for a rule on a map field, whether it applies to the key rather than the value.

pub type Violation {
  Violation(
    field: List(FieldPathElement),
    rule: List(FieldPathElement),
    rule_id: String,
    message: String,
    for_key: Bool,
  )
}

Constructors

Values

pub fn field_path(elements: List(FieldPathElement)) -> String

A field path as protovalidate prints it, such as items[0].name.

pub fn to_string(violation: Violation) -> String

A violation as protovalidate prints it: its field path, then its message, or its rule ID in brackets when it has no message, such as tags[1]: must be at most 3 characters.

✨ Search Document