How to use the prance.util.resolver.RefResolver function in prance

To help you get started, we’ve selected a few prance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_issue_38_tilde_one():
  specs = get_specs('tests/specs/issue_38_a.yaml')
  res = resolver.RefResolver(specs,
      fs.abspath('tests/specs/issue_38_a.yaml'))
  res.resolve_references()

  path = res.specs['paths']['/api/v2/vms']
  assert 'get' in path
  assert 'operationId' in path['get']
  assert 'description' in path['get']
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_recursion_limit_do_not_recurse_ignore_files(recursion_limit_files_file):
  # If we overload the handler, we should not get an error but should
  # also simply not have the 'next' field - or it should be None
  import os.path
  res = resolver.RefResolver(recursion_limit_files_file,
      fs.abspath('tests/specs/recursion_limit_files.yaml'),
      recursion_limit_handler = recursion_limit_handler_none)
  res.resolve_references()

  from prance.util import formats
  contents = formats.serialize_spec(res.specs, 'foo.yaml')

  # The effect of returning None on recursion limit should be that
  # despite having recursion, the outermost reference to
  # definitions/Pet should get resolved.
  assert 'properties' in res.specs['paths']['/pets']['get']['responses']['200']['schema']

  # However, the 'next' field should not be resolved.
  assert res.specs['paths']['/pets']['get']['responses']['200']['schema']['properties']['next']['schema'] is None
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_resolver_named(mock_get, externals_file):
  mock_get.side_effect = mock_get_petstore

  import os.path
  from prance.util import fs
  res = resolver.RefResolver(externals_file,
      fs.abspath('tests/specs/with_externals.yaml'))
  res.resolve_references()
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_resolver_missing_reference(mock_get, missing_file):
  mock_get.side_effect = mock_get_petstore

  import os.path
  res = resolver.RefResolver(missing_file,
      fs.abspath('tests/specs/missing_reference.yaml'))
  with pytest.raises(ResolutionError) as exc:
    res.resolve_references()

  assert str(exc.value).startswith('Cannot resolve')
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_issue_23_partial_resolution_internal():
  specs = get_specs('tests/specs/with_externals.yaml')
  res = resolver.RefResolver(specs,
      fs.abspath('tests/specs/with_externals.yaml'),
      resolve_types = resolver.RESOLVE_INTERNAL
      )
  res.resolve_references()

  # By default, all externals need to be resolved.
  from prance.util.path import path_get

  val = path_get(res.specs, ('paths', '/pets', 'get', 'responses', '200', 'schema'))
  assert '$ref' in val

  val = path_get(res.specs, ('paths', '/pets', 'get', 'responses', 'default', 'schema'))
  assert '$ref' in val

  val = path_get(res.specs, ('paths', '/pets', 'post', 'responses', 'default', 'schema'))
  assert '$ref' in val
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_recursion_limit_set_limit_ignore(recursion_limit_file):
  # If we overload the handler, and set the recursion limit higher,
  # we should get nested Pet objects a few levels deep.

  import os.path
  res = resolver.RefResolver(recursion_limit_file,
      fs.abspath('tests/specs/recursion_limit.yaml'),
      recursion_limit = 2,
      recursion_limit_handler = recursion_limit_handler_none)
  res.resolve_references()

  from prance.util import formats
  contents = formats.serialize_spec(res.specs, 'foo.yaml')

  # The effect of returning None on recursion limit should be that
  # despite having recursion, the outermost reference to
  # definitions/Pet should get resolved.
  assert 'properties' in res.specs['paths']['/pets']['get']['responses']['200']['schema']

  # However, the 'next' field should be resolved due to the higher recursion limit
  next_field = res.specs['paths']['/pets']['get']['responses']['200']['schema']['properties']['next']['schema']
  assert next_field is not None
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_recursion_limit_do_not_recurse_ignore(recursion_limit_file):
  # If we overload the handler, we should not get an error but should
  # also simply not have the 'next' field - or it should be None
  import os.path
  res = resolver.RefResolver(recursion_limit_file,
      fs.abspath('tests/specs/recursion_limit.yaml'),
      recursion_limit_handler = recursion_limit_handler_none)
  res.resolve_references()

  from prance.util import formats
  contents = formats.serialize_spec(res.specs, 'foo.yaml')

  # The effect of returning None on recursion limit should be that
  # despite having recursion, the outermost reference to
  # definitions/Pet should get resolved.
  assert 'properties' in res.specs['paths']['/pets']['get']['responses']['200']['schema']

  # However, the 'next' field should not be resolved.
  assert res.specs['paths']['/pets']['get']['responses']['200']['schema']['properties']['next']['schema'] is None
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_resolver_recursive_objects(mock_get, recursive_objs_file):
  mock_get.side_effect = mock_get_petstore

  # Recursive references to objects are a problem
  import os.path
  res = resolver.RefResolver(recursive_objs_file,
      fs.abspath('tests/specs/recursive_objs.yaml'))
  with pytest.raises(ResolutionError) as exc:
    res.resolve_references()

  assert str(exc.value).startswith('Recursion reached limit')
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def test_issue_23_partial_resolution_invalid_scheme():
  specs = {'$ref': 'foo://cannot-do-anything'}
  res = resolver.RefResolver(specs,
      fs.abspath('tests/specs/with_externals.yaml'))

  with pytest.raises(ValueError):
    res.resolve_references()