Linter rulesAsyncAPIstandard-media-types

standard-media-types

Since 0.9.0

This rule checks whether messages use only standard media types.

Rule Details

Using non-standard media types can lead to interoperability issues: consumers and tools may not know how to decode the messages.

The standard-media-types rule checks the following fields of an AsyncAPI document:

  • the root defaultContentType,
  • the contentType of every message,
  • the contentType of every message trait.

For every value that is not a recognized media type, the rule reports Non-standard media type is used (<value>). Media type parameters (such as ; charset=utf-8) are allowed and ignored.

A media type is recognized when it has the type/subtype form and its subtype is one of the well-known subtypes, such as json, xml, plain, octet-stream, problem+json, vnd.api+json or x-www-form-urlencoded. Note that some media types commonly used with message brokers, for example application/vnd.apache.avro+json, application/x-protobuf or application/cloudevents+json, are not currently recognized.

Configuration

None.

Examples

Good.

asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
defaultContentType: application/json
channels:
  petAdopted:
    address: pets.adopted
    messages:
      petAdopted:
        contentType: application/json; charset=utf-8
        payload:
          type: object

Bad. json is not a media type, and application/pet uses a subtype that is not registered.

asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
defaultContentType: json
channels:
  petAdopted:
    address: pets.adopted
    messages:
      petAdopted:
        contentType: application/pet
        payload:
          type: object

When Not to Use It

You may disable this rule if your messages use vendor-specific media types, or binary serialization formats that the rule does not recognize.

Compatibility

This rule is compatible with AsyncAPI 3.x documents. AsyncAPI 2.x documents are rejected by the reader and are not linted.