spectral:oas warn on by default

duplicated-entry-in-enum

Enum values must not have duplicate entry.

Applies to
enum
Selects
$..[?(@property !== 'properties' && @ != null && @.enum && @.enum.constructor.name === 'Array')]
Function
oasSchema
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:
  duplicated-entry-in-enum: warn   # or off, or another severity

Definition

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

duplicated-entry-in-enum:
  description: Enum values must not have duplicate entry.
  message: '{{error}}'
  severity: warn
  recommended: true
  given:
    - >-
      $..[?(@property !== 'properties' && @ != null && @.enum &&
      @.enum.constructor.name === 'Array')]
  then:
    field: enum
    function: oasSchema
    functionOptions:
      schema:
        type: array
        uniqueItems: true

About this rule

Each value of an enum must be different from one another.

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
        - 3
        - 2

Sources