parameter-naming

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

This rule checks all channel parameters in an AsyncAPI document and warns if their names do not adhere to the specified naming convention.

Rule details

A consumer who has seen one parameter should be able to spell the next. In AsyncAPI 3.x, the name of a parameter is its key in the parameters map, which is the same name that appears between braces in the channel address.

The rule checks the parameters of every channel (in the root channels map and in components/channels), as well as the entries of components/parameters. For every parameter whose name is not in the expected convention, it reports Parameter should be named <name>, where <name> is the parameter name converted to that convention.

The recognised naming conventions are:

  • CONST_CASE (also UPPER_CASE and SCREAMING_SNAKE_CASE) - THIS_IS_CONST_CASE
  • camelCase - thisIsCamelCase, also with acronyms (userID)
  • camelCaseStrict - thisIsCamelCase, but no two capitals in a row (userId, not userID)
  • kebab-case - this-is-kebab-case
  • PascalCase - ThisIsPascalCase, also with acronyms (HTTPServer)
  • PascalCaseStrict - ThisIsPascalCase, but no two capitals in a row (HttpServer, not HTTPServer)
  • Header-Case - This-Is-Header-Case
  • snake_case - this_is_snake_case

The default convention is snake_case.

Unlike OpenAPI, AsyncAPI parameters have no location (path, query, header or cookie), so a single convention applies to all of them.

Configuration

The configuration block can be a string or an object.

If it is a string, its value is the name of the naming convention (see the “Rule details” section for a list of recognized names).

If it is an object, it must contain the default property, whose value is the name of the naming convention. Other properties are ignored.

Configuration example. The following two examples are equivalent. They specify that the expected naming convention for all parameters is camelCase.

version: "1.0"
commands:
  lint:
    asyncapi:
      rules:
        parameter-naming: [warning, camelCase]
version: "1.0"
commands:
  lint:
    asyncapi:
      rules:
        parameter-naming:
          - warning
          - default: camelCase

Examples

Good. With the default configuration.

asyncapi: 3.0.0
info:
  title: User Events
  version: 1.0.0
channels:
  userSignedUp:
    address: users.{user_id}.signedUp
    parameters:
      user_id:
        description: Identifier of the user.

Bad. With the default configuration, the linter reports Parameter should be named user_id.

asyncapi: 3.0.0
info:
  title: User Events
  version: 1.0.0
channels:
  userSignedUp:
    address: users.{userId}.signedUp
    parameters:
      userId:
        description: Identifier of the user.

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:
        parameter-naming: off

Related rules

Was this helpful?