Forum Discussion

Stoplight's avatar
Stoplight
Community Manager
3 months ago
Solved

spectrals javascript api always returns an empty array

Originally posted by user tobiasneubert to the Stoplight Community on 05/26/2023 at 10:37 ET.

Hi everyone, I hope I am at the right place here. If not, my apologies.

I try to use spectrals javascript api to unit test my rules. But whatever I try, spectral.run() always returns with an empty array, even if I broke my rules. I posted a question on stackoverflow: https://stackoverflow.com/questions/76341713/use-spectral-via-javascript-api-returns-empty-result

I don't know how to add code blocks here and I think there is no need in duplicating the question 🙂 It would be great if someone could help.

  • Jakub_R (Staff) [05/30/2023 - 12:30 ET]

    Hey! Try using the following ruleset

    rules:
      resource-names-plural:
        severity: warn
        message: "Resource names should generally be plural"
        given: "$.paths"
        then:
          field: "@key"
          function: pattern
          functionOptions:
            match: "^hello$"

2 Replies