Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

new rule: $ref noticed in invalid places #535

Closed
XVincentX opened this issue Sep 9, 2019 · 7 comments
Closed

new rule: $ref noticed in invalid places #535

XVincentX opened this issue Sep 9, 2019 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed json-refs everything JSON Refs resolving related OpenAPI Issues related to the OpenAPI ruleset p/medium

Comments

@XVincentX
Copy link
Contributor

XVincentX commented Sep 9, 2019

In both OAS2 and OAS3, $ref is only allowed in certain places. Spectral is resolving all references anywhere, instead of following the rules of the specification.

Consider this document:

swagger: "2.0"
host: localhost
info:
  description: bar
  title: "IO APIs, shared specs"
  version: "0.1"
paths: {}
definitions:  # definitions non può contenere $ref
  $ref: file.yml

This is technically invalid OAS2, since refs is not allowed here. Spectral does not give any feedback, just says this is valid.

I understand and support the use case, however it would be great if I could at least see a warning saying "Yo man, I resolved this for you but you should not do this"

@P0lip
Copy link
Contributor

P0lip commented Sep 9, 2019

I'm assuming Spectral is resolving the references for me any way and that's why the validation is passing.

Yeah, that's exactly the cause of the issue. oas2-schema and oas3-schema operate on resolved content, therefore they have no idea about $refs at the time they are executed.

@philsturgeon
Copy link
Contributor

@XVincentX did you actually mean to say "$refs are not allowed in OpenAPI 2 documents" or did you mean to say something else? Because $ref is definitely allowed in OpenAPI v2 documents.

@XVincentX
Copy link
Contributor Author

XVincentX commented Sep 9, 2019

I'm sorry I didn't clarify enough — refs are not supported in the definitions section — it must be just a dictionary of Schema Objects

@XVincentX XVincentX changed the title Throw a warning if Spectral is solving the references for me Throw a warning if Spectral is solving the references for me in inopportune sections Sep 9, 2019
@philsturgeon
Copy link
Contributor

Ah yeah absolutely. That's confused me in the past. Some tools just resolve everything everywhere and some tools only resolve the specific allowed places. If we resolve everything all the time we are going against the spec, furthering confusion, and giving people a false sense of security in their description docs which might not work in other places outside of stoplight.

But if we error we're being to strict, so it sounds like a warning is pretty consistent with how we want to deal with this sort of thing.

@philsturgeon philsturgeon changed the title Throw a warning if Spectral is solving the references for me in inopportune sections Throw a warning if Spectral is resolving $ref in invalid palces Sep 10, 2019
@P0lip P0lip changed the title Throw a warning if Spectral is resolving $ref in invalid palces Throw a warning if Spectral is resolving $ref in invalid places Sep 20, 2019
@P0lip P0lip added enhancement New feature or request t/bug Something isn't working and removed enhancement New feature or request labels Oct 8, 2019
@philsturgeon philsturgeon changed the title Throw a warning if Spectral is resolving $ref in invalid places new rue: $ref noticed in invalid places Oct 24, 2019
@philsturgeon philsturgeon changed the title new rue: $ref noticed in invalid places new ruel: $ref noticed in invalid places Oct 24, 2019
@philsturgeon philsturgeon changed the title new ruel: $ref noticed in invalid places new rule: $ref noticed in invalid places Oct 24, 2019
@philsturgeon philsturgeon added help wanted Extra attention is needed p/high and removed p/medium labels Dec 27, 2019
@philsturgeon philsturgeon removed the help wanted Extra attention is needed label Jan 2, 2020
@philsturgeon philsturgeon added enhancement New feature or request and removed t/bug Something isn't working labels Apr 28, 2020
@hilary
Copy link

hilary commented Dec 15, 2020

Any action on this bug? Btw, I think it has to be marked as a bug, because Spectral advertises itself as an OAS linter with built-in OAS v3 rules. It's reasonable of the reader to believe that OAS v3 validation is part of that linting! By resolving $refs in places where it can't be used, Spectral is validating invalid specs. That's a bug. I came here today explicitly to report this bug...

I have a ticket to add a separate validator to our CI workflow due to this bug. ☹️

@philsturgeon
Copy link
Contributor

philsturgeon commented Dec 15, 2020 via email

@philsturgeon philsturgeon added the help wanted Extra attention is needed label Dec 31, 2020
@P0lip P0lip added the OpenAPI Issues related to the OpenAPI ruleset label May 12, 2021
@P0lip P0lip added the json-refs everything JSON Refs resolving related label Mar 24, 2022
@magicmatatjahu
Copy link
Contributor

magicmatatjahu commented Sep 16, 2022

I created similar rule for AsyncAPI spec based on unresolved (but only main) document #2262 I can extend that rule to be generic to handle also OpenAPI. However I don't know how to "handle" sub documents (referenced) to check if given referenced sections have also valid places where $ref is allowed, e.g.

paths:
  /users:
    $ref: '../resources/users.yaml'

it's valid, but we don't know if ../resources/users.yaml has $refs in proper places. I will check if documentInventory shares some needed data for that.

@stoplightio stoplightio locked and limited conversation to collaborators Mar 23, 2023
@mnaumanali94 mnaumanali94 converted this issue into discussion #2432 Mar 23, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request help wanted Extra attention is needed json-refs everything JSON Refs resolving related OpenAPI Issues related to the OpenAPI ruleset p/medium
Projects
None yet
Development

No branches or pull requests

6 participants