Skip to content

Casing error shows incorrect line with nested $ref #2849

@kierank1

Description

@kierank1

Describe the bug
With nested $refs in a schema, it appears that the error response that is given does not always correctly reference the property that is incorrect.

To Reproduce

Here's an example spec file:

openapi: 3.0.2
info:
  title: Example API
  version: 0.20.1
  description: Test API
  contact:
    name: "Testing"
servers:
  - url: https://example.com
tags:
  - name: example-tag
paths:
  /example:
    get:
      operationId: getExample
      description: Get Examples from the API
      tags:
        - example-tag
      responses:
        "200":
          $ref: "#/components/responses/ExampleResponse"

components:
  responses:
    ExampleResponse:
      description: OK
      content:
        application/json:
          schema:
            type: object
            properties:
              meta:
                type: object
                properties:
                  ruleType:
                    type: object
                    properties:
                      goodCasing:
                        $ref: "#/components/schemas/ExampleMeta"
                      BAD-CASING:
                        $ref: "#/components/schemas/ExampleMeta"
  schemas:
    ExampleMeta:
      type: object
      properties:
        goodCasing:
          type: boolean
          default: true
        BAD-CASING-2:
          type: string
          example: In Development

And my implemented rule:

rules:
  camel-case-for-all-field-names:
    description: "All field names must be camel case."
    severity: error
    given: 
      - "$..properties.*~"
    then:
      function: casing
      functionOptions:
        type: camel

This results in the failure:

 44:17  error  camel-case-for-all-field-names  All field names must be camel case.  components.schemas.ExampleMeta
 50:22  error  camel-case-for-all-field-names  All field names must be camel case.  components.schemas.ExampleMeta.properties.BAD-CASING-2

Expected behavior
I would expect that the initial first failure should reference line 41, pointing to BAD-CASING, similarily to BAD-CASING-2.

Environment (remove any that are not applicable):

  • Using docker
  • FROM stoplight/spectral:6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions