Swagger Resolution Errors
Goldziher opened this issue · 3 comments
Expected Behaviour
Minimal Example Spec
Actual Behaviour
Steps to Reproduce
Environment
- OS: maxOf
- Python version: 3.9
- Swagger/OpenAPI version used: swagger 2.0
- Backend: (flex, swagger-spec-validator or openapi-spec-validator) using the resolver directly
Hi there, and first off thanks for this resolver!
I'm maintaining another library that relies on Prance as a derferencer. It works well in most cases, but I think I encountered a bug. I'm testing our library (https://github.com/snok/drf-openapi-tester) against various specs, and now I'm trying to test it against the kubernetes swgger 2.0 docs:, which can be found here: https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json
It seems that this spec cannot be resolved at present because instead of a url what is passed to the following function is a dictionary {type: string}
:
def absurl(url, relative_to = None):
....
# prance.util.url lines 49-59
parsed = url
if not isinstance(parsed, tuple):
from .fs import is_pathname_valid
if is_pathname_valid(url):
from . import fs
url = fs.to_posix(url)
try:
parsed = parse.urlparse(url)
except Exception as ex:
from .exceptions import raise_from
raise_from(ResolutionError, ex, 'Unable to parse url: %s' % (url,))
I got to this point in debugging it.
According to the intellij debugger absurl
was called with two parameters:
url={'type': 'string'},
relative_to=ParseResult(scheme='file', netloc='', path='/', params='', query='', fragment='/definitions/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps')
If you want I can add a json copy of the kubernetes spec to the repo and have it fail in a test if that would help :).
Thank you for this!
It is true that validation and dereferencing do not have to happen at the same time. In fact, this is also how it's implemented - the validation function is just called internally.
I think that makes for a very easy change.
As to the bug: the spec could help, yes! Also, if/when I have time, #81 would help with locating the error. In the past, people passed malformed specs to get this kind of problem, but that doesn't mean it has to be the case here!
great, i will create the test branch and maybe add a PR if I figure it out 😉
@jfinkhaeuser, i added a PR with the Kubernetes swagger specs and a failing test.