Linter rulesAsyncAPIschema-datetime-suffix

schema-datetime-suffix

Since 0.9.0

This rule ensures that the names of date and time properties end with a common suffix.

Rule Details

A consistent suffix makes temporal properties easy to recognize, and distinguishes them from other properties describing the same concept (e.g. created_at versus created_by).

The schema-datetime-suffix rule checks the properties of every object schema of an AsyncAPI document. For every property whose schema has the date, date-time or time format and whose name does not end with the configured suffix, it reports Property name <name> should end with <suffix>. The issue is reported at the property itself, not at a (possibly shared) referenced schema.

The default suffix is _at.

Configuration

The configuration block is a non-empty string: the required suffix.

Configuration Example. The following configuration requires temporal properties to end with At, which fits camelCase property names.

version: "1.0"
commands:
  lint:
    asyncapi:
      rules:
        schema-datetime-suffix: [warning, At]

Examples

Good. With the default configuration.

asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
components:
  schemas:
    PetAdopted:
      type: object
      properties:
        adopted_at:
          type: string
          format: date-time

Bad. With the default configuration.

asyncapi: 3.0.0
info:
  title: Pet Events
  version: 1.0.0
components:
  schemas:
    PetAdopted:
      type: object
      properties:
        adoption_date:
          type: string
          format: date-time

When Not to Use It

You may disable this rule if your API follows a different convention for naming temporal properties.

Compatibility

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

Related rules