# schema-enum-no-duplicates

Source: https://apigenie.pl/docs/linter/swagger/rules/schema-enum-no-duplicates

This rule ensures that `enum` lists do not contain duplicate values.

## Rule Details

A duplicate enum value is redundant and usually a copy-paste mistake. It may
also break code generators, which turn enum values into constants that must
be unique.

The `schema-enum-no-duplicates` rule checks the `enum` list of every typed
object of a Swagger 2.0 document: schemas, non-body parameters, response
headers and `items` objects (objects with a `$ref` are checked where they are
defined). It reports `Duplicate enum value` once for every value that is
equal to a value listed before it.

Values are compared structurally: arrays are equal when their elements are
equal in order, and objects are equal when they have the same keys with equal
values, regardless of the order of the keys.

## Configuration

None.

## Examples

**Good**.

```yaml
swagger: '2.0'
info:
  title: Users
  version: 1.0.0
paths: {}
definitions:
  UserStatus:
    type: string
    enum: [ACTIVE, INACTIVE]
```

**Bad**. `ACTIVE` is listed twice, and the two points differ only in the
order of their keys.

```yaml
swagger: '2.0'
info:
  title: Users
  version: 1.0.0
paths: {}
definitions:
  UserStatus:
    type: string
    enum: [ACTIVE, INACTIVE, ACTIVE]
  Corner:
    type: object
    enum:
      - { x: 1, y: 2 }
      - { y: 2, x: 1 }
```

## Automatic fixes

When invoked with `--fix`, this rule removes every duplicate value, keeping
the first occurrence of each value.

## When Not to Use It

There is no good reason to keep duplicate enum values, so this rule should
always be enabled.

## Compatibility

This rule is compatible with Swagger 2.0 documents. OpenAPI 3.x documents are
linted by the OpenAPI linter, which has a rule of the same name.
