schema-enum-types

Since 0.0.1 · fixed by --fix · In the rulesets: Recommended at error, Strict at error, All at error

This rule checks that the values of enum and const have the type the schema declares.

Rule details

A type: string with the values 1 and 2 accepts nothing: a value that is one of the numbers is not a string, and a string is not one of the values. Validators reject every value, and a generated enum type takes the values or the type, not both.

The rule reports Enum value type is not in the schema type on the schema.

Examples

Good. Strings in a string schema.

components:
  schemas:
    UserStatus:
      type: string
      enum:
        - active
        - inactive

Bad. Numbers in a string schema.

components:
  schemas:
    UserStatus:
      type: string
      enum:
        - 1
        - 2

Automatic fixes

--fix sets the type of the schema to the type of the values when all the values have one JSON type and the schema has no format. Enums with values of several types stay for you to resolve.

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

commands:
  lint:
    rules:
      schema-enum-types: off
Was this helpful?