schema-property-naming

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

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

Rule details

Property names are typed by every client, and one convention lets a client author who has seen one name spell the next; it also maps payloads to the data structures of one language without renaming.

The schema-property-naming rule checks the keys of the properties map of every schema of a Swagger 2.0 document (schemas with a $ref are checked where they are defined). For every property whose name is not in the expected convention, it reports Schema property '<name>' is not in the '<convention>' convention, where <convention> is the display name of the convention (e.g. snake_case). The issue is reported at the schema that declares the property.

The recognized 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.

The OpenAPI linter has a rule of the same name, schema-property-naming, for OpenAPI 3.x documents.

Turn the rule off when the API follows no naming convention for property names.

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:
    swagger:
      rules:
        schema-property-naming: [error, camelCase]

Examples

Good. With the default configuration.

swagger: '2.0'
info:
  title: Users
  version: 1.0.0
paths: {}
definitions:
  User:
    type: object
    properties:
      first_name:
        type: string
      last_name:
        type: string

Bad. With the default configuration.

swagger: '2.0'
info:
  title: Users
  version: 1.0.0
paths: {}
definitions:
  User:
    type: object
    properties:
      firstName:
        type: string
      LastName:
        type: string

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.swagger has the details.

commands:
  lint:
    swagger:
      rules:
        schema-property-naming: off

Related rules

Further reading

Last updated on View as Markdown
Was this helpful?