Skip to content

SpecFactory doesn't keep scope state resulting in unresolvable relative references #98

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

Open
ghost opened this issue Sep 10, 2018 · 4 comments
Labels
area/schema Indicates an issue on schema area kind/bug/confirmed

Comments

@ghost
Copy link

ghost commented Sep 10, 2018

I have a set of files that form a spec that fully validates with openapi-spec-validator. It can find all references, but openapi-core cannot and after much debugging I figured out why.
The various generators that are started in the SpecFactory, specifically the PathsGenerator and everything it drives, only keep reference to the top-level spec_url.
When you trace through openapi-spec-validator, you see that with every file change the derefencer.resolver_manager.resolver._scopes_stack increases and the current location is appended to it and used to resolve any references.
But these generators do not do anything with the scope, so cannot resolve the relative path references and the base_uri always remains the same.

@ghost
Copy link
Author

ghost commented Sep 11, 2018

I added test cases that show the problem, but not sure how to proceed from here. Would appreciate any pointers to why this is failing.

@p1c2u p1c2u added kind/bug/confirmed area/schema Indicates an issue on schema area labels Oct 25, 2018
@ghost
Copy link
Author

ghost commented Jan 14, 2019

So in openapi_spec_validator, we have a decorator that wraps the dereferencer and sets ['x-scope'] before diving in further. The generators in openapi_core do not have a similar mechanism and the basic error is here:

  1. OperationsGenerator.generate() dereferences the path.
  2. Before returning, Dereferencer.dereference() from openapi_spec_validator, exits the context and calls finally() which resets the scope.
  3. Now the parameter list needs to be resolved at the yield statement in generate. The parameter list (from debugger) looks like this in my case: <class 'list'>: [{'$ref': '../../common/parameters.yaml#/pagination-page'}, {'$ref': '../../common/parameters.yaml#/pagination-size'}, {'$ref': './parameters.yaml#/ordering'}] and path is <class 'dict'>: {'$ref': './user-panel/orders/get.yaml'}, finally scope_stack = <class 'list'>: ['file:///home/melvyn/hg/polyrepo/button3d/apidocs/openapi/openapi.yaml'].

So at this point the parameter references do not have the correct scope. But if you put the paths into a separate file, then the operations have the problem, so it's a problem for any generator that is instantiated from a file not in the root directory.

We either need a different dereferencer that checks target for things to deref before returning (not possible imo, since you don't know what the refs objects are) or initialize the generators with a dereferencer that has the correct scope.

@p1c2u
Copy link
Collaborator

p1c2u commented Sep 5, 2019

#157 can potentially solve this issue too

@gjcarneiro
Copy link

Noting here that this is still an issue for me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Indicates an issue on schema area kind/bug/confirmed
Projects
None yet
Development

No branches or pull requests

2 participants