# cloudevents/binding-headers

Source: https://api-genie.dev/docs/linter/asyncapi/rules/cloudevents-binding-headers

A rule of the AsyncAPI linter, which reads AsyncAPI 3 documents; the reader rejects AsyncAPI 2 documents. 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**.

```yaml
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`.

```yaml
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
```
