How to use the prance.util.formats 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_convert.py View on Github external
def test_convert_petstore_json(petstore_json):
  converted, content_type = convert.convert_str(petstore_json)

  # Check correct content type
  assert 'json' in content_type

  # Parsing can't fail.
  from prance.util import formats
  parsed = formats.parse_spec(converted, content_type = content_type)

  # Assert the correct target version
  assert 'openapi' in parsed
  assert parsed['openapi'].startswith('3.')
github jfinkhaeuser / prance / tests / test_util_resolver.py View on Github external
def get_specs(fname):
  specs = fs.read_file(fname)

  from prance.util import formats
  specs = formats.parse_spec(specs, fname)

  return specs
github jfinkhaeuser / prance / tests / test_convert.py View on Github external
def test_convert_petstore_yaml(petstore_yaml):
  converted, content_type = convert.convert_str(petstore_yaml)

  # Check correct content type
  assert 'yaml' in content_type

  # Parsing can't fail.
  from prance.util import formats
  parsed = formats.parse_spec(converted, content_type = content_type)

  # Assert the correct target version
  assert 'openapi' in parsed
  assert parsed['openapi'].startswith('3.')
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_formats.py View on Github external
def test_format_info_yaml():
  ctype, ext = formats.format_info('yaml')
  assert 'yaml' in ctype
  assert 'yaml' in ext
github jfinkhaeuser / prance / tests / test_util_formats.py View on Github external
def test_parse_json_ctype():
  json = '{ "foo": "bar" }'

  parsed = formats.parse_spec(json, None, content_type = 'application/json')
  assert parsed['foo'] == 'bar', 'Did not parse with explicit JSON'
github jfinkhaeuser / prance / prance / cli.py View on Github external
def __write_to_file(filename, specs):  # noqa: N802
  """
  Write specs to the given filename.

  This takes into account file name extensions as per `fs.write_file`.
  """
  from prance.util import fs, formats
  contents = formats.serialize_spec(specs, filename)
  fs.write_file(filename, contents)
github jfinkhaeuser / prance / prance / convert.py View on Github external
options.update(kwargs)
    spec = parser_or_spec.specification
  else:
    # We must assume a specification
    klass = parser_klass or BaseParser
    options = kwargs.copy()
    spec = parser_or_spec

  # print('Class', klass)
  # print('Options', options)
  # print('Spec', spec)

  # We have to serialize the specs in order to convert them. Let's use
  # YAML.
  from .util import formats
  serialized = formats.serialize_spec(spec, content_type = 'text/yaml')

  # Convert serialized
  converted, ctype = convert_str(serialized, content_type = 'text/yaml')

  # Create parser with options
  result = klass(spec_string = converted, **options)
  return result
github python-microservices / pyms / pyms / flask / services / swagger.py View on Github external
def merge_swagger_file(main_file: str):
    """
    Generate swagger into a single file
    :param main_file: Swagger file path
    :return:
    """
    input_file = Path(main_file)
    output_file = Path(input_file.parent, 'swagger-complete.yaml')

    contents = formats.serialize_spec(
        specs=get_bundled_specs(input_file),
        filename=output_file,
    )
    fs.write_file(filename=output_file,
                  contents=contents,
                  encoding='utf-8')