Ensures that Example Objects have valid field combinations according to the OpenAPI specification.
| OAS | Compatibility |
|---|---|
| 2.0 | ❌ |
| 3.0 | ✅ |
| 3.1 | ✅ |
| 3.2 | ✅ |
According to the OpenAPI specification, some fields of an Example Object cannot be used together. This rule reports examples that contain any of these pairs:
valueandexternalValue(all OpenAPI 3.x versions)valueanddataValue(OpenAPI 3.2)valueandserializedValue(OpenAPI 3.2)externalValueandserializedValue(OpenAPI 3.2)
This rule replaces the deprecated no-example-value-and-externalValue rule.
| Option | Type | Description |
|---|---|---|
| severity | string | Possible values: off, warn, error. Default error (in recommended configuration). |
An example configuration:
rules:
spec-example-values: error
Given this configuration:
rules:
spec-example-values: error
Example of incorrect example objects:
components:
examples:
InvalidDataValueAndValue:
dataValue:
name: John Doe
value:
name: Jane Doe
InvalidSerializedValueAndValue:
serializedValue: '{"name":"John Doe"}'
value:
name: Jane Doe
InvalidExternalValueAndValue:
externalValue: https://example.com/user-example.json
value:
name: Jane Doe
Example of correct example objects:
components:
examples:
ValidDataValue:
dataValue:
name: John Doe
ValidSerializedValue:
serializedValue: '{"name":"John Doe"}'
ValidExternalValue:
externalValue: https://example.com/user-example.json