`oas3-valid-oas-content-example` rule needs to obey readOnly/writeOnly property
See original GitHub issueDescribe the bug
According to https://swagger.io/docs/specification/data-models/data-types/ :
If a readOnly or writeOnly property is included in the required list, required affects just the relevant scope – responses only or requests only. That is, read-only required properties apply to responses only, and write-only required properties – to requests only.
The rule oas3-valid-oas-content-example
should not raise error when a readOnly
and required
property is missing in request example. And also writeOnly
property isn’t required in response example.
The rule oas3-valid-media-example
has the same bug as well.
To Reproduce
- Given this OpenAPI/AsyncAPI document index.yaml
- Run this CLI command
spectral lint index.yaml
- See error
16:21 error oas3-valid-oas-content-example Object should have required property
self
Expected behavior This error report is not expected.
The self
property is readOnly, it isn’t required in request.
Environment (remove any that are not applicable):
- Library version: 5.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:10 (1 by maintainers)
We also encountered this bug today. AFAIK
readOnly
andwriteOnly
are not removed from OpenAPI v3.1.0, it was only adjusted to be compliant with JSON schema which means that it can only be set on properties, not anymore on models. But the bug is also still present for (at least)readOnly
+required
on properties in request bodies.(However in our case it was the
oas3-valid-media-example
rule that complained about examples on requests that were missing a required property even though it was read-only.)I can confirm that the issue is still there, it would be nice to fix this as it’s creating problems with some of our OAS files.