cloudevents/attribute-schemas

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.

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.

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

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/attribute-schemas: off

Related rules

Further reading

Last updated on View as Markdown
Was this helpful?