How to use the prance.ResolvingParser 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_resolving_parser.py View on Github external
def petstore_parser_from_string():
  yaml = None
  with open('tests/specs/petstore.yaml', 'rb') as f:
    x = f.read()
    yaml = x.decode('utf8')
  return ResolvingParser(spec_string = yaml)
github jfinkhaeuser / prance / tests / test_resolving_parser.py View on Github external
title: ''
  version: '1.0.0'
paths: {}
components:
    schemas:
        SampleArray:
            type: array
            items:
              $ref: '#/components/schemas/ItemType'

        ItemType:
          type: integer
'''

  from prance.util import resolver
  parser = ResolvingParser(
    spec_string = specs,
    resolve_types = resolver.RESOLVE_FILES
  )

  from prance.util.path import path_get
  val = path_get(parser.specification, ('components', 'schemas', 'SampleArray', 'items'))
  assert '$ref' in val
github jfinkhaeuser / prance / tests / test_resolving_parser.py View on Github external
def test_issue_39_sequence_indices():
  # Must not fail to parse
  parser = ResolvingParser('tests/specs/issue_39.yaml', backend = 'openapi-spec-validator')

  # The /useCase path should have two values in its response example.
  example = parser.specification['paths']['/useCase']['get']['responses']['200']['content']['application/json']['examples']['response']
  assert 'value' in example
  assert len(example['value']) == 2

  # However, the /test path should have only one of the strings.
  example = parser.specification['paths']['/test']['get']['responses']['200']['content']['application/json']['example']
  assert example == 'some really long or specific string'
github jfinkhaeuser / prance / tests / test_convert.py View on Github external
def test_convert_parser_lazy_swagger_backend():
  from prance import BaseParser, ResolvingParser, ValidationError
  parser = BaseParser('tests/specs/petstore.yaml')

  # Conversion should fail with the default backend.
  with pytest.raises(ValidationError):
    converted = convert.convert_spec(parser)

  # However, with the lazy flag it should work.
  converted = convert.convert_spec(parser, lazy = True)
  assert isinstance(converted, BaseParser)

  # Passing a ResolvingParser class should also work.
  converted = convert.convert_spec(parser, ResolvingParser, lazy = True)
  assert isinstance(converted, ResolvingParser)
github jmvrbanac / falcon-lambda / falcon_lambda / validators / swagger.py View on Github external
def load(path):
    spec = prance.ResolvingParser(path).specification
    return apply(spec)
github jfinkhaeuser / prance / prance / cli.py View on Github external
"""Return a parser instance for the URL and the given parameters."""
  # Try the URL
  formatted = click.format_filename(url)
  click.echo('Processing "%s"...' % (formatted, ))

  from prance.util import fs
  fsurl = fs.abspath(url)
  import os.path
  if os.path.exists(fs.from_posix(fsurl)):
    url = fsurl

  # Create parser to use
  parser = None
  if resolve:
    click.echo(' -> Resolving external references.')
    parser = prance.ResolvingParser(url, lazy = True, backend = backend,
            strict = strict, encoding = encoding)
  else:
    click.echo(' -> Not resolving external references.')
    parser = prance.BaseParser(url, lazy = True, backend = backend,
            strict = strict, encoding = encoding)

  # XXX maybe enable tihs in debug mode or something.
  # click.echo(' -> Using backend: {0.backend}'.format(parser))
  return parser, formatted
github Flowminder / FlowKit / flowapi / flowapi / permissions.py View on Github external
----------
    flowmachine_query_schemas : dict
        Schema dict to turn into scopes list

    Yields
    ------
    str
        Scope strings

    Examples
    --------
    >>> list(schema_to_scopes({"FlowmachineQuerySchema": {"oneOf": [{"$ref": "DUMMY"}]},"DUMMY": {"properties": {"query_kind": {"enum": ["dummy"]}}},},))
    ["get_result&dummy", "run&dummy", "get_result&available_dates"],
    """
    yield from per_query_scopes(
        queries=ResolvingParser(spec_string=dumps(schema)).specification["components"][
            "schemas"
        ]["FlowmachineQuerySchema"]
    )
github StackStorm / st2 / st2common / st2common / cmd / validate_api_spec.py View on Github external
+ 'Provide a valid spec file or '
            + 'pass --generate-api-spec to genrate a spec.'
        )
        raise Exception(msg)

    if generate_spec:
        if not spec_file:
            raise Exception('Supply a path to write to spec file to.')

        spec_string = spec_loader.generate_spec('st2common', 'openapi.yaml.j2')

        with open(spec_file, 'w') as f:
            f.write(spec_string)
            f.flush()

    parser = ResolvingParser(spec_file)
    spec = parser.specification

    return _validate_definitions(spec)
github kiwicom / the-zoo / zoo / repos / views.py View on Github external
def _parse_file(path, base=None):
    try:
        parser = ResolvingParser(str(path))
        return parser.specification
    except (
        AssertionError,
        AttributeError,
        ComposerError,
        FileNotFoundError,
        ResolutionError,
        ScannerError,
        UnicodeDecodeError,
        ValidationError,
    ) as err:
        log.info(
            "repos.views.openapi.invalid", path=str(path.relative_to(base)), error=err
        )
github StackStorm-Exchange / stackstorm-slack / bin / generate_openapi.py View on Github external
def get_openapi_spec():
    parser = ResolvingParser(OPENAPI_JSON_URL)
    return parser.specification  # contains fully resolved specs as a dict