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 as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.35k stars 226 forks source link

The oas3-valid-media-example linter complains about using nullable type when using allOf. I am using the below example schema: #2620

Open menaheme opened 2 months ago

menaheme commented 2 months ago

The oas3-valid-media-example linter complains about using nullable type when using allOf. I am using the below example schema:

openapi: 3.0.1
info:
  title: User API
  description: The User API allows managing users.
  version: 0.1.0
paths:
  /api/v1/user:
    patch:
      summary: Patch User
      operationId: patchUser
      requestBody:
        description: Patch user body
        required: true
        content:
          application/json:
            example:
              Name: test
            schema:
              $ref: "#/components/schemas/PatchRequest"
      responses:
        "200":
          description: The patched user.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Name"

components:
  schemas:
    Name:
      type: string
      description: Name of the user.
      maxLength: 255
      minLength: 1

    ID:
      type: string
      description: ID of the user.
      maxLength: 255
      minLength: 1

    PatchRequest:
      description: Patch user
      allOf:
        - $ref: "#/components/schemas/Name"
        - $ref: "#/components/schemas/ID"
      minProperties: 1
      nullable: true

Why does the linter complain while using nullable:true ? Also, when i remove the example from the spec, the error goes away. I am using this code generator https://github.com/deepmap/oapi-codegen and it generates the code as expected and works fine.

Originally posted by @sonasingh46 in https://github.com/stoplightio/spectral/discussions/2568

menaheme commented 2 months ago

found in discussions, happens to me too