spectral:oas warn on by default

typed-enum

Enum values must respect the specified type.

Applies to
enum
Selects
$..[?(@ && @.enum && @.type)]
Function
typedEnum
Specs
OpenAPI 2.0OpenAPI 3.0OpenAPI 3.1OpenAPI 3.2
Message
{{error}}

Use it

This rule ships with OpenLint in spectral:oas. Extending the ruleset turns it on:

extends: spectral:oas
rules:
  typed-enum: warn   # or off, or another severity

Definition

As defined in @openlint/openlint-rulesets. Functions show by name.

typed-enum:
  description: Enum values must respect the specified type.
  message: '{{error}}'
  recommended: true
  given: '$..[?(@ && @.enum && @.type)]'
  then:
    function: typedEnum

About this rule

Enum values should respect the type specifier.

Good Example

TheGoodModel:
  type: object
  properties:
    number_of_connectors:
      type: integer
      description: The number of extension points.
      enum:
        - 1
        - 2
        - 4
        - 8

Bad Example

TheBadModel:
  type: object
  properties:
    number_of_connectors:
      type: integer
      description: The number of extension points.
      enum:
        - 1
        - 2
        - "a string!"
        - 8

Sources