question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`oas3-valid-oas-content-example` rule needs to obey readOnly/writeOnly property

See original GitHub issue

Describe 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

  1. Given this OpenAPI/AsyncAPI document index.yaml
  2. Run this CLI command spectral lint index.yaml
  3. 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:open
  • Created 3 years ago
  • Reactions:12
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bertramakerscommented, Aug 19, 2021

We also encountered this bug today. AFAIK readOnly and writeOnly 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.

/home/runner/work/stoplight-docs-uitpas/stoplight-docs-uitpas/reference/UiTPAS.v2.json
 376:21  error  oas3-valid-media-example  `0` property must have required property `id`  paths./ticket-sales.post.requestBody.content.application/json.examples['Example for one ticket sale'].value[0]
 389:21  error  oas3-valid-media-example  `0` property must have required property `id`  paths./ticket-sales.post.requestBody.content.application/json.examples['Example for multiple ticket sales'].value[0]
 411:21  error  oas3-valid-media-example  `0` property must have required property `id`  paths./ticket-sales.post.requestBody.content.application/json.examples['Example for multiple ticket sales at the same tariff'].value[0]

(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.)

0reactions
petkostascommented, Sep 16, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CA1044: Properties should not be write only (code analysis)
Although it is acceptable and often necessary to have a read-only property, the design guidelines prohibit the use of write-only properties.
Read more >
c# - Write-Only properties, what's the point? - Stack Overflow
I have never come across a valid use-case for a write-only property. Honestly, if there is a valid use-case for a write-only property...
Read more >
A brand new website interface for an even better experience!
oas3-valid-oas-content-example ` rule needs to obey readOnly/writeOnly property.
Read more >
Atlas - Standard Controls without parameters - Pega
Presents a value always in read-only mode. Appropriate for properties computed through Declare Expression rules of type Text , Integer , or Identifier...
Read more >
Rule 71.1. Condemning Real or Personal Property
These rules govern proceedings to condemn real and personal property by eminent ... When the action commences, the plaintiff need join as defendants...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found