Files
redocly-cli/docs/rules/no-enum-type-mismatch.md
Adam Altman fcdd782d18 refactor: rename four types (#906)
Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
2022-10-10 15:36:35 -05:00

2.0 KiB

no-enum-type-mismatch

Requires that the contents of every enum value in your API definition conform to the corresponding schema's specified type.

OAS Compatibility
2.0
3.0
3.1
flowchart TD

Root ==> Paths --> PathItem --> Operation --> Parameter --> Schema
PathItem --> Parameter
NamedParameter --> Parameter
Operation --> RequestBody --> MediaType --> Schema
Operation --> Responses --> MediaType
NamedSchema --> Schema
Root ==> components

subgraph components
NamedParameter
NamedSchema
end

style Schema fill:#codaf9,stroke:#0044d4,stroke-width:5px

API design principles

If a property is defined for a certain type, then its corresponding enum values should comply with that type. Lack of compliance is most likely the result of a typo.

Configuration

Option Type Description
severity string Possible values: off, warn, error. Default error (in recommended configuration).

An example configuration:

rules:
  no-enum-type-mismatch: error

Examples

Given this configuration:

rules:
  no-enum-type-mismatch: error

Example of incorrect enum values given the enum type:

properties:
  huntingSkill:
    type: string
    description: The measured skill for hunting
    enum:
      - adventurous
      - 12
      - 3.14

Example of correct enum values given the enum type:

properties:
  huntingSkill:
    type: string
    description: The measured skill for hunting
    enum:
      - adventurous
      - aggressive
      - passive

Resources