# schema-enum-no-duplicates

Source: https://api-genie.dev/docs/linter/swagger/rules/schema-enum-no-duplicates

A rule of the Swagger 2.0 linter, which reads Swagger 2.0 documents; OpenAPI 3 documents go to the OpenAPI linter. Since 0.9.0. Fixed by `--fix`. In the rulesets: Recommended at error, Strict at error, All at error.

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.

The OpenAPI linter has a rule of the same name,
[schema-enum-no-duplicates](/docs/linter/openapi/rules/schema-enum-no-duplicates), for OpenAPI 3.x
documents.

## 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

`--fix` removes every duplicate value, keeping
the first occurrence of each value.
