Forum Discussion

Stoplight's avatar
Stoplight
Community Manager
11 months ago

"nullable" cannot be used without "type"

Originally posted by user Ashutosh to the Stoplight Community on 12/27/2023 at 00:24 ET.

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.

  • Stoplight's avatar
    Stoplight
    Community Manager

    a_welch (Staff) [12/28/2023 - 13:24 ET]

    Hello Ashutosh, can you clarify if you are seeing this issue in Stoplight Studio or are you seeing this in Spectral? If you are seeing this in Spectral can you please add this questions to the Git discussion so that team can review it. Here is a link: https://github.com/stoplightio/spectral/discussions.

    If you are seeing this issue in Stoplight Studio, I would recommend that you open a Support Case so that the team can review it and if it is determined to be a bug, get it submitted to Engineering.

    • Stoplight's avatar
      Stoplight
      Community Manager

      Ashutosh (OP) [01/03/2024 - 05:34 ET]

      I am seeing this in spectral. I will add to the github discussion