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

OAS Core Rule: $ref can have description and summary siblings #2480

Closed
CanVuralStudocu opened this issue May 25, 2023 · 3 comments
Closed

OAS Core Rule: $ref can have description and summary siblings #2480

CanVuralStudocu opened this issue May 25, 2023 · 3 comments

Comments

@CanVuralStudocu
Copy link

Describe the bug
I think according to the OpenAPI spec (https://swagger.io/specification/#reference-object) reference objects can have $ref, summary and description fields. But the Spectral rule no-$ref-siblings marks the description sibling of $ref as error.

To Reproduce

  1. Given this OpenAPI/AsyncAPI document
    {
    	"$ref": "#/components/schemas/Pet",
        "description": "This is a sibling description that should be allowed."
    }
  1. Run this CLI command spectral lint
  2. See error no-$ref-siblings $ref must not be placed next to any other properties

Expected behavior
description and summary should be allowed as a sibling to $ref

@davidkeaveny
Copy link

https://swagger.io/docs/specification/using-ref/#sibling suggests otherwise:

Any sibling elements of a $ref are ignored. This is because $ref works by replacing itself and everything on its level with the definition it is pointing at.

Instead, you have to use allOf:

{
  "allOf": [
    { "$ref": "#/components/schemas/Pet" }
  ],
  "description": "This is a sibling description that should be allowed."
}

@CanVuralStudocu
Copy link
Author

I found this issue that confirms $ref can have siblings: OAI/OpenAPI-Specification#2744

@mnaumanali94
Copy link
Contributor

@CanVuralStudocu That's an addition to the OAS3.1 spec. This rule as configured doesn't apply to OAS3.1 and is only enabled for OAS3 and 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants