schema-datetime-suffix

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

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.

Turn the rule off if your API follows a different convention for naming temporal properties.

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

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:
        schema-datetime-suffix: off

Related rules

Last updated on View as Markdown
Was this helpful?