Apache Avro · API Governance Rules

Apache Avro API Rules

Spectral linting rules defining API design standards and conventions for Apache Avro.

15 Rules error 9 warn 4 info 2
View Rules File View on GitHub

Rule Categories

avro

Rules

error
avro-schema-type-required
Avro schemas must specify a type.
$
error
avro-record-name-required
Avro record types must have a name.
$..[?(@.type == 'record')]
error
avro-record-fields-required
Avro record types must have a fields array.
$..[?(@.type == 'record')]
error
avro-field-name-required
Each Avro record field must have a name.
$..fields[*]
error
avro-field-type-required
Each Avro record field must have a type.
$..fields[*]
error
avro-enum-name-required
Avro enum types must have a name.
$..[?(@.type == 'enum')]
error
avro-enum-symbols-required
Avro enum types must define symbols.
$..[?(@.type == 'enum')]
error
avro-fixed-name-required
Avro fixed types must have a name.
$..[?(@.type == 'fixed')]
error
avro-fixed-size-required
Avro fixed types must specify a size.
$..[?(@.type == 'fixed')]
warn
avro-namespace-recommended
Avro named types should include a namespace.
$..[?(@.type == 'record' || @.type == 'enum' || @.type == 'fixed')]
warn
avro-doc-recommended
Avro schemas should include documentation.
$
info
avro-field-doc-recommended
Avro record fields should include documentation.
$..fields[*]
warn
avro-field-default-for-nullable
Nullable Avro fields should specify a default value.
$..fields[?(@.type[0] == 'null')]
info
avro-name-camel-case
Avro schema names should use camelCase or PascalCase.
$..name
warn
avro-namespace-dot-separated
Avro namespaces should use dot-separated package notation.
$..namespace

Spectral Ruleset

avro-spectral-rules.yml Raw ↑
rules:
  avro-schema-type-required:
    description: "Avro schemas must specify a type."
    message: "Avro schema must have a type field."
    severity: error
    given: "$"
    then:
      field: type
      function: truthy

  avro-record-name-required:
    description: "Avro record types must have a name."
    message: "Record type must have a name field."
    severity: error
    given: "$..[?(@.type == 'record')]"
    then:
      field: name
      function: truthy

  avro-record-fields-required:
    description: "Avro record types must have a fields array."
    message: "Record type must define fields."
    severity: error
    given: "$..[?(@.type == 'record')]"
    then:
      field: fields
      function: truthy

  avro-field-name-required:
    description: "Each Avro record field must have a name."
    message: "Record field must have a name."
    severity: error
    given: "$..fields[*]"
    then:
      field: name
      function: truthy

  avro-field-type-required:
    description: "Each Avro record field must have a type."
    message: "Record field must have a type."
    severity: error
    given: "$..fields[*]"
    then:
      field: type
      function: truthy

  avro-enum-name-required:
    description: "Avro enum types must have a name."
    message: "Enum type must have a name."
    severity: error
    given: "$..[?(@.type == 'enum')]"
    then:
      field: name
      function: truthy

  avro-enum-symbols-required:
    description: "Avro enum types must define symbols."
    message: "Enum type must have a symbols array."
    severity: error
    given: "$..[?(@.type == 'enum')]"
    then:
      field: symbols
      function: truthy

  avro-fixed-name-required:
    description: "Avro fixed types must have a name."
    message: "Fixed type must have a name."
    severity: error
    given: "$..[?(@.type == 'fixed')]"
    then:
      field: name
      function: truthy

  avro-fixed-size-required:
    description: "Avro fixed types must specify a size."
    message: "Fixed type must have a size in bytes."
    severity: error
    given: "$..[?(@.type == 'fixed')]"
    then:
      field: size
      function: truthy

  avro-namespace-recommended:
    description: "Avro named types should include a namespace."
    message: "Named type should have a namespace for disambiguation."
    severity: warn
    given: "$..[?(@.type == 'record' || @.type == 'enum' || @.type == 'fixed')]"
    then:
      field: namespace
      function: truthy

  avro-doc-recommended:
    description: "Avro schemas should include documentation."
    message: "Schema or named type should have a doc string."
    severity: warn
    given: "$"
    then:
      field: doc
      function: truthy

  avro-field-doc-recommended:
    description: "Avro record fields should include documentation."
    message: "Field should have a doc string describing its purpose."
    severity: info
    given: "$..fields[*]"
    then:
      field: doc
      function: truthy

  avro-field-default-for-nullable:
    description: "Nullable Avro fields should specify a default value."
    message: "Nullable union field should provide a default value."
    severity: warn
    given: "$..fields[?(@.type[0] == 'null')]"
    then:
      field: default
      function: defined

  avro-name-camel-case:
    description: "Avro schema names should use camelCase or PascalCase."
    message: "Schema name should use camelCase or PascalCase convention."
    severity: info
    given: "$..name"
    then:
      function: pattern
      functionOptions:
        match: "^[a-zA-Z][a-zA-Z0-9]*$"

  avro-namespace-dot-separated:
    description: "Avro namespaces should use dot-separated package notation."
    message: "Namespace should use dot-separated notation (e.g., com.example.avro)."
    severity: warn
    given: "$..namespace"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9]*(\\.[a-z][a-z0-9]*)*$"