Linter rulesOpenAPIparameter-naming

parameter-naming

Since 0.0.1

This rule checks all parameters in an OpenAPI schema and warns if they do not adhere to the specified naming convention.

Rule Details

The parameter-naming rule is designed to ensure that each parameter in an OpenAPI schema adheres to a specific naming 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

It is possible to configure the naming convention separately for each parameter location. The default values are:

  • query parameters - kebab
  • header parameter - header
  • other parameters - snake

Configuration

The configuration block can be a string or an object.

If it is a string, its value is intepreted as the default naming convention, and is used for all parameter types.

If it is an object, it must contain the default property, and may contain any of the path, query, header and cookie properties. Value of each property is the naming convention name (see the “Rule Details” section for a list of recognized names). Value of the default property is used as a default naming convention, and values from other properties override naming convention for specific parameter types.

Configuration Example 1. The following two examples are equivalent. They specify that the expected naming convention for all parameters is PascalCase.

lint:
  rules:
    parameter-naming:
      - warning
      - pascal
lint:
  rules:
    parameter-naming:
      - warning
      - default: pascal

Configuration Example 2. This configuration specifies sets the default naming convention to be snake, and overrides it for query parameters with kebab, as well as for header parameters with header.

lint:
  rules:
    parameter-naming:
      - warning
      - default: snake
        query: kebab
        header: header

Examples

None.

When Not to Use It

We recommend to always enable this rule.

Compatibility

This rule is compatible with all OpenAPI 3.x versions.