# cloudevents/attribute-schemas

Source: https://api-genie.dev/docs/linter/asyncapi/rules/cloudevents-attribute-schemas

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 warning.

This rule checks that the schemas of CloudEvents attributes say what the specification says of
them.

## Rule details

The schemas of the attributes are what validators, mocks and generated code know of them. The rule
checks the attribute headers of binary-mode messages and the payload properties of structured-mode
ones (other than `data` and `data_base64`):

- `specversion` is pinned to `'1.0'`, with `const` or an `enum` of that one value;
- the context attributes (`id`, `source`, `specversion`, `type`, `datacontenttype`, `dataschema`,
  `subject`, `time`) are strings when the schema gives a `type`;
- `time` has `format: date-time`, `source` has `format: uri-reference` (or `uri`), `dataschema`
  has `format: uri`;
- the names of extension attributes have lower-case letters and digits only, and at most 20 of
  them. MQTT 5 user properties carry attributes without a prefix, so their other names are not
  checked.

## 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_source:
              type: string
              format: uri-reference
            ce_time:
              type: string
              format: date-time
            ce_partitionkey:
              type: string
```

**Bad**. `specversion` takes any string, `time` has no format, and `partitionKey` has an upper-case
letter.

```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:
              type: string
            ce_time:
              type: string
            ce_partitionKey:
              type: string
```
