Linter rulesAsyncAPIparameter-naming
parameter-naming
Since 0.9.0
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
The parameter-naming rule is designed to ensure that the name of each
channel parameter adheres to a specific naming convention. 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- THIS_IS_CONST_CASEcamel- thisIsCamelCase, also with acronyms (userID)camel-strict- thisIsCamelCase, but no two capitals in a row (userId, not userID)kebab- this-is-kebab-casepascal- ThisIsPascalCase, also with acronyms (HTTPServer)pascal-strict- ThisIsPascalCase, but no two capitals in a row (HttpServer, not HTTPServer)header- This-Is-Header-Casesnake- this_is_snake_case
The default convention is snake.
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, camel]
version: "1.0"
commands:
lint:
asyncapi:
rules:
parameter-naming:
- warning
- default: camel
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.
When Not to Use It
We recommend to always enable 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.