spectral icon indicating copy to clipboard operation
spectral copied to clipboard

Improve error locations when using $rel objects

Open nmoreaud opened this issue 2 years ago • 1 comments

Hello,

I use zalando spectral ruleset, and I wish to have better error locations in case of $rel objects. Do you think it can be improved?

For example:

openapi: 3.0.0

paths:
  '/test':
    get:
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Test'

components:
  schemas:
    Test:
      type: object
      properties:
        BAD1:    <-- real error (bad case)
          $ref: '#/components/schemas/Value'
        test2:
          $ref: '#/components/schemas/Value'

    Value:     <-- detected error
      type: object
      properties:
        val:
          type: string
npx @stoplight/spectral-cli lint v1.yaml

v1.yaml
  1:1   error  oas3-schema                             Object must have required property "info".
 24:11  error  must-use-snake-case-for-property-names  Property name has to be ASCII snake_case    components.schemas.Value

Rule definition from https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/main/zalando.yml

  must-use-snake-case-for-property-names:
    message: Property name has to be ASCII snake_case
    description: MUST property names must be ASCII snake_case [118]
    documentationUrl: https://opensource.zalando.com/restful-api-guidelines/#118
    severity: error
    given: $.paths.*.*[responses,requestBody]..content..schema..properties.*~
    then:
      function: pattern
      functionOptions:
        match: ^[a-z_][a-z_0-9]*$

In my project, there was an error in a "link" to resource (HATEOAS). There are so many "links" that it is hard to identify where the error comes from.

Original issue: https://github.com/baloise-incubator/spectral-ruleset/issues/37

nmoreaud avatar Mar 17 '23 09:03 nmoreaud

Hey! The issue here is caused by the fact each error is linked to the value of a property, while what raises the linting issue here is the key of it. Unfortunately, there's no way for Spectral to report an issue with a key as things stand.

This would be an enhancement.

P0lip avatar Mar 23 '23 15:03 P0lip

Any progress on this? Would be really nice to be able to tie errors to the key as it is really time consuming to try and locate where the errors originate from. Our use case is basically the same as @nmoreaud, validating property names.

Revyy avatar May 22 '24 06:05 Revyy