Linter rulesAsyncAPIschema-property-naming

schema-property-naming

Since 0.9.0

This rule ensures that the names of schema properties adhere to a predefined naming convention.

Rule Details

Adhering to a consistent naming convention enhances the readability and maintainability of the API’s structure, and makes messages easier to map to native data structures.

The schema-property-naming rule checks the keys of the properties map of every schema of an AsyncAPI document. For every property whose name is not in the expected convention, it reports Schema property '<name>' is not in the '<convention>' convention.

The recognised naming conventions are:

  • const - THIS_IS_CONST_CASE
  • camel - thisIsCamelCase, also with acronyms (userID)
  • camel-strict - thisIsCamelCase, but no two capitals in a row (userId, not userID)
  • kebab - this-is-kebab-case
  • pascal - ThisIsPascalCase, also with acronyms (HTTPServer)
  • pascal-strict - ThisIsPascalCase, but no two capitals in a row (HttpServer, not HTTPServer)
  • header - This-Is-Header-Case
  • snake - this_is_snake_case

The default convention is snake.

Configuration

The configuration block is a naming convention name (see the “Rule Details” section for a list of recognized names).

version: "1.0"
commands:
  lint:
    asyncapi:
      rules:
        schema-property-naming: [error, camel]

Examples

Good. With the default configuration.

asyncapi: 3.0.0
info:
  title: User Events
  version: 1.0.0
components:
  schemas:
    UserSignedUp:
      type: object
      properties:
        user_id:
          type: string
        display_name:
          type: string

Bad. With the default configuration.

asyncapi: 3.0.0
info:
  title: User Events
  version: 1.0.0
components:
  schemas:
    UserSignedUp:
      type: object
      properties:
        userId:
          type: string
        DisplayName:
          type: string

When Not to Use It

If your API does not follow a specific naming convention for schema properties, you may not need to use this rule.

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