baloise-incubator / spectral-ruleset

Custom Spectral API Linter ruleset for Zalando RESTful API Guidelines.
Apache License 2.0
27 stars 13 forks source link

Zalando rule 169 introduces an issue for null properties #59

Open johannesmarx opened 3 months ago

johannesmarx commented 3 months ago

Somehow it seems that the newly introduced Zalando rule 169 causes an issue in cases with null properties.

I stumbled over the issue in a case where a response example references an Example that contains a null property.

To better illustrate the issue, I created a draft PR that showcases it: https://github.com/baloise-incubator/spectral-ruleset/pull/60

       resonses:
       ...
           application/json:
              schema:
                $ref: '#/components/schemas/Example'
              examples:
                default:
                  $ref: '#/components/examples/ExampleResponse'

...

components:
 ...
  examples:
    ExampleResponse:
      summary: example response summary
      value:
        name: null # this null value causes the exception

This is the resulting stack trace:

TypeError: Cannot read properties of null (reading 'type')

      at Object.$.paths..[?(@.type === 'string' && (@.format === 'date-time' || @.format === 'date' || @.format === 'time' || @.format === 'duration' || @.format === 'period'))] (eval at query (node_modules/nimma/dist/legacy/cjs/core/index.js:66:71), <anonymous>:117:31)
      at eval (eval at query (node_modules/nimma/dist/legacy/cjs/core/index.js:66:71), <anonymous>:201:176)
      at _traverseBody (node_modules/nimma/dist/legacy/cjs/runtime/traverse.js:13:5)
      at _traverse (node_modules/nimma/dist/legacy/cjs/runtime/traverse.js:41:7)
      at _traverseBody (node_modules/nimma/dist/legacy/cjs/runtime/traverse.js:17:5)

Side note: I'm not sure if the operator === is "standard" for JSONPath filters but it seems not to cause the issue. Never the less == seem to be more common.

johannesmarx commented 3 months ago

@dweber019 did you had a chance to look into the issue?