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

Swagger Resolution Errors #87

Open
Goldziher opened this issue Jan 24, 2021 · 3 comments
Open

Swagger Resolution Errors #87

Goldziher opened this issue Jan 24, 2021 · 3 comments

Comments

@Goldziher
Copy link
Contributor

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 :).

@jfinkhaeuser

@jfinkhaeuser
Copy link
Collaborator

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!

@Goldziher
Copy link
Contributor Author

great, i will create the test branch and maybe add a PR if I figure it out 😉

@Goldziher Goldziher changed the title Request - split up resolution from validation Swagger Resolution Errors Feb 13, 2021
@Goldziher
Copy link
Contributor Author

@jfinkhaeuser, i added a PR with the Kubernetes swagger specs and a failing test.

RonnyPfannschmidt added a commit that referenced this issue Apr 9, 2021
Added failing test for issue #87
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

2 participants