standard-media-types

Since 0.9.0 · In the rulesets: Recommended at warning, Strict at error, All at error

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. The CloudEvents media types (application/cloudevents+json, application/cloudevents-batch+json and their other formats) are recognized. Note that some media types commonly used with message brokers, for example application/vnd.apache.avro+json or application/x-protobuf, are not currently recognized.

Turn the rule off if your messages use vendor-specific media types, or binary serialization formats that the rule does not recognize.

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

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:
        standard-media-types: off
Was this helpful?