spectral icon indicating copy to clipboard operation
spectral copied to clipboard

oas3-valid-media-example is reported for primitives if type is object

Open gssbzn opened this issue 11 months ago • 0 comments

Describe the bug According to https://spec.openapis.org/oas/v3.0.3#schema-object object can also be primitive values but spectral seems to flag examples using primitives as invalid

To Reproduce

  1. Given this this schema
schema:
    ApiError:
      type: object
      properties:
        detail:
          type: string
        error:
          type: integer
          format: int32
        parameters:
          type: array
          description: Parameter used to give more information about the error.
          items:
            type: object            

an example like

          example:
            error: 400
            detail: "Example"
            parameters:
            - "0"
  1. Run this CLI command spectral lint with the default extends: [spectral:oas] rule sets
  2. See error
error  oas3-valid-media-example  "0" property type must be object  components.responses.badRequest.content.application/json.example.parameters[0]

Expected behavior Object examples should accept primitives according to the spec

Environment (remove any that are not applicable):

  • CLI version 6.11.0

gssbzn avatar Feb 28 '24 13:02 gssbzn