Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when running spectral 6.4.0 or later with specific custom rule using js function: endsWith is not a function #2560

Open
phoenixy1 opened this issue Dec 11, 2023 · 0 comments
Labels
p/medium t/bug Something isn't working triaged

Comments

@phoenixy1
Copy link

phoenixy1 commented Dec 11, 2023

Describe the bug
A custom rule that worked in spectral 6.3.0 and earlier is causing spectral to throw an exception in 6.4.0 and later
To Reproduce

  1. Given this OpenAPI/AsyncAPI document: https://github.com/plaid/plaid-openapi/blob/master/2020-09-14.yml
  2. With the following custom rule in the spectral ruleset:
  response-object-additional-properties:
    description: Every model of type object used in a response has additionalProperties=true
    message: '{{path}} {{error}}'
    severity: error
    given: '$.components.schemas.[?(@.type == ''object'')]'
    resolved: false
    then:
      function: response-object-additional-properties

and the following response-object-additional-properties.js function defined:

module.exports = (input, options, context) => {
    if (context.path == null) {
        return;
    }

    const parentPropertyName = context.path[context.path.length - 1]
    if (parentPropertyName.endsWith('Response')) {
        if (!input.additionalProperties) {
            return [{
                message: 'No additional properties field',
            }]
        }
    }
}
  1. Run this CLI command: spectral lint 2020-09-14.yml
  2. Error received:
Error #1: Function "responseObjectAdditionalProperties" threw an exception: parentPropertyName.endsWith is not a function
Error #2: Function "responseObjectAdditionalProperties" threw an exception: parentPropertyName.endsWith is not a function
Error #3: Function "responseObjectAdditionalProperties" threw an exception: parentPropertyName.endsWith is not a function

Expected behavior
I expected spectral to run without an error.

Additional context
This error appears in Spectral 6.4.0 and later. Spectral 6.3.0 does not exhibit this issue.

@phoenixy1 phoenixy1 changed the title Exception when running spectral 6.4.0 with specific custom rule using js function: endsWith is not a function Exception when running spectral 6.4.0 or later with specific custom rule using js function: endsWith is not a function Dec 11, 2023
@mnaumanali94 mnaumanali94 added t/bug Something isn't working p/medium triaged labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/medium t/bug Something isn't working triaged
Projects
None yet
Development

No branches or pull requests

2 participants