stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.53k stars 241 forks source link

ReadOnly in synch with required raising an error on POST where it should not #2628

Closed LasneF closed 1 month ago

LasneF commented 5 months ago

Describe the bug

given an attribute set readOnly , and as part of the required list , Spectral raises an error oas3-valid-media-example , property must have required property "XXX"

Looks the context of usage here in a POST is not taken into account

To Reproduce

leveraging the spec below just run spectral lint

it raises 39:13 error oas3-valid-media-example "value" property must have required property "id" components.examples.Medor.value

openapi: 3.1.0

info: 
  title: "sample"
  version: "sample"

paths:
  /dogs:
    post:
      requestBody:
        content:
          application/json:
            schema:
                $ref: '#/components/schemas/Dogs'
            examples:
              Simple:
                $ref: '#/components/examples/Medor' 
      responses:
        '200':
          description: nice Dog

components:
  schemas:
    Dogs:
        type: object
        required: 
          -  id
        properties:
            id: 
              readOnly: true
              type: integer
            name: 
              type: "string"
  examples: 
    Medor: 
      description: |
        A simple pricing request on a single product.
      value:
        name : "Medor le chien"

Expected behavior looking on https://github.com/OAI/learn.openapis.org/issues/101 , and the statement " If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only."

the field should not raise such error

Environment (remove any that are not applicable): Tested leveraging spectral 6.11.1 on windows

Additional context Add any other context about the problem here.

github-actions[bot] commented 5 months ago

This ticket has been labeled jira. A tracking ticket in Stoplight's Jira (STOP-647) has been created.

LasneF commented 1 month ago

cannot reproduce