no-invalid-schema-examples

Disallow invalid schema examples.

OAS Compatibility
2.0
3.0
3.1
components
compares schema
to example
NamedSchema
Root
PathMap
PathItem
Operation
Parameter
Example
Schema
MediaType

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.
disallowAdditionalProperties boolean Determines if additional properties are allowed in examples. Default true.

An example configuration:

Copy
Copied
styleguide:
  rules:
    no-invalid-schema-examples:
      severity: error
      disallowAdditionalProperties: true

Examples

Given the following configuration:

Copy
Copied
styleguide:
  rules:
    no-invalid-schema-examples:
      severity: error
      disallowAdditionalProperties: true

Example of incorrect schema example:

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

Example of correct parameter example:

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

Related rules

Resources