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

Example value as null fails #2649

Open benjamin-mogensen opened 4 days ago

benjamin-mogensen commented 4 days ago

Describe the bug When OpenAPI specification contains null as an example value the Spectral engine reports Cannot read properties of null (reading 'type')

To Reproduce

  1. Run Spectral validation on the following OAS:
openapi: 3.0.0
info:
  version: 1.0.0
  title: Cat
  description: Cat API
  contact:
    name: Cat owner
    email: cats@cat.com
    url: https://developer.cats.com/contact-us
  license:
    url: https://www.cats.com/api-license-terms
    name: Cats 1.0
servers:
  - url: https://api.maersk.com/products
    description: Production Environment
paths:
  /cats:
    get:
      operationId: get-cats
      description: Cats
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: string
                nullable: true
                example: null

Expected behavior It is expected that null is an allowed example value for nullable properties.

CLI Environment:

CLI Environment Output

(node:46129) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Error running Spectral!
Use --verbose flag to print the error stack.
Error #1: Cannot read properties of null (reading 'type')

Node.js Environment

Node.js Environment Output image