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.37k stars 228 forks source link

Path property of error remains empty even if custom function provides some value #2593

Open johannesmarx opened 4 months ago

johannesmarx commented 4 months ago

Describe the bug The path property of the error is not handled correctly when writing custom functions. In case the function also provides some value for the path besides the message, it remains empty after calling new Spectral(resolver).run(openApi).

To Reproduce

  1. Given a custom most simplified function:

    export default (targetValue) => {
    return [
    {
      message: "Some issue with servers",
      path: ['servers'],
    },
    ];
    };
  2. The linting result will be:

    [
    {
    code: 'my-check',
    message: 'Some issue with servers',
    path: [],
    ...
    }
    ]

Expected behavior The expected result would also contain the path provided by the custom function as follows:

[
  {
    code: 'my-check',
    message: 'Some issue with servers',
    path: ['servers'],
    ...
  }

Environment (remove any that are not applicable):