cloudevents/binding-headers

Since 0.12.0 · In the rulesets: CloudEvents at error

This rule checks that the attribute headers of binary-mode CloudEvents use the prefix of the protocol their channel is served over.

Rule details

Each protocol binding of CloudEvents names the headers of attributes its own way: ce- over HTTP, ce_ over Kafka, cloudEvents: (or cloudEvents_) over AMQP, and no prefix for MQTT 5 user properties. SDKs and brokers look only for their binding’s prefix, so a header named for another binding, such as ce-id on a Kafka topic, is not an attribute to them: the event arrives without it.

The rule reports a header whose prefix is another binding’s than those of the channel’s servers (all servers when the channel lists none), and says what to name it. Headers with a prefix but no valid attribute name after it (ce-not-an-attribute) are not reported.

Examples

Good.

asyncapi: 3.0.0
info:
  title: Shipments
  version: 1.0.0
servers:
  kafka:
    host: kafka.example.com:9092
    protocol: kafka
channels:
  shipments:
    address: shipments
    messages:
      created:
        headers:
          type: object
          properties:
            ce_specversion:
              const: '1.0'
            ce_id:
              type: string

Bad. ce-id is the HTTP name of the attribute; over Kafka it is ce_id.

asyncapi: 3.0.0
info:
  title: Shipments
  version: 1.0.0
servers:
  kafka:
    host: kafka.example.com:9092
    protocol: kafka
channels:
  shipments:
    address: shipments
    messages:
      created:
        headers:
          type: object
          properties:
            ce_specversion:
              const: '1.0'
            ce-id:
              type: string

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.asyncapi has the details.

commands:
  lint:
    asyncapi:
      rules:
        cloudevents/binding-headers: off

Related rules

Further reading

Was this helpful?