Files
redocly-cli/docs/rules/no-invalid-schema-examples.md
2023-11-17 09:45:03 +00:00

2.4 KiB

slug
slug
/docs/cli/rules/no-invalid-schema-examples

no-invalid-schema-examples

Disallow invalid schema examples.

OAS Compatibility
2.0
3.0
3.1
flowchart TD

Root ==> Paths --> PathItem --> Operation --> Parameter --> Example
PathItem --> Parameter
Parameter --> Schema
Operation --> MediaType --> Schema
Root ==> components

NamedSchema --> Parameter

Schema -.compares schema\nto example.- Example

subgraph components
NamedSchema
end


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

API design principles

If your schema and example conflict, there is a problem in the definition of the schema or the example. Solve it before you ship it.

Configuration

Option Type Description
severity string Possible values: off, warn, error. Default warn.
allowAdditionalProperties boolean Determines if additional properties are allowed in examples. Default false.

An example configuration:

rules:
  no-invalid-schema-examples:
    severity: error
    allowAdditionalProperties: false

Examples

Given the following configuration:

rules:
  no-invalid-schema-examples:
    severity: error
    allowAdditionalProperties: false

Example of incorrect schema example:

components:
  schemas:
    Car:
      type: object
      properties:
        color:
          type: string
          example: 3.14

Example of correct parameter example:

components:
  schemas:
    Car:
      type: object
      properties:
        color:
          type: string
          example: red

Resources