# schema-enum-types

Source: https://apigenie.pl/docs/linter/openapi/rules/schema-enum-types

A rule of the OpenAPI linter, which reads OpenAPI 3.0, 3.1 and 3.2 documents. 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.

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

**Bad**. Numbers in a string schema.

```yaml
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.
