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

Support all edge cases with circular references #599

Closed
magicmatatjahu opened this issue Sep 8, 2022 · 2 comments
Closed

Support all edge cases with circular references #599

magicmatatjahu opened this issue Sep 8, 2022 · 2 comments
Labels

Comments

@magicmatatjahu
Copy link
Member

With switching to the Spectral, we found that we do not support all cases with circular references (or, more precisely, one particular case). Spectral has its own ref-resolver that does not resolve circular references like json-schema-ref-parser, but only leaves the $ref field intact at the point when such a reference is encountered. I described that problem in one of issue:

Circular references you can only have with Schema Objects, so '/components/channels/test'.includes('/channels/test') is not a good example.

You can create circular reference only when you point to the schema which is already used in parent path(s), so schema like:

type: object
properties:
  deepProperty:
    type: object
    properties:
      circular:
        $ref: '#/properties/deepProperty'

is circular in properties/deepProperty/properties/circular path. That case is handled by first if in mentioned function

Another case is related to Spectral and how it resolves circular references. We can have two two schemas, main one and external > (from file):

type: object
properties:
  fileProperty:
    $ref: './fromfile.yaml'
    
# fromfile.yaml
type: object
properties:
  deepProperty:
    type: object
    properties:
      circular:
        $ref: '#/properties/deepProperty'

but in this case the circular reference after dereferencing has $ref field still with '#/properties/deepProperty' value, so it means that if we will check path we will have '#/properties/deepProperty' from file pov, not from main file pov, like '#/properties/fileProperty/properties/deepProperty' and due to this fact we need to also check (by second if) the subpath. I hope it's clear now. Above logic is dictated by Spectral "problems".

it's resolved in our parser side, but one case is very hard to resolve like:

type: object
properties:
  fileProperty:
    $ref: './fromfile#/properties/circular1'
        
# fromfile.yaml
type: object
properties:
  circular1:
    type: object
    properties:
      circular:
        $ref: '#/properties/circular2'
  circular2:
    type: object
    properties:
      circular:
        $ref: '#/properties/circular1'

and we don't have any additional data (metadata?) to resolve such a reference. We should switch to the json-schema-ref-resolver in Spectral or fix that problem in Spectral's ref-resolver (but that resolver is deprecated). We can also wait for stoplightio/spectral#1054

@magicmatatjahu
Copy link
Member Author

Resolved by #671

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 2.0.0-next-major.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants