From 9071dbf2e7819e2ff2aeae3a39e2b27e9c1d8076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Zago=C5=BEen?= Date: Fri, 26 Apr 2019 16:20:32 +0200 Subject: [PATCH 1/4] Pin PyYAML to 3.13. PyYAML>=5.1 introduces a backwards-incompatible change with regards to the YAML parser. Until this package is made compatible, just stick with the old version. See https://msg.pyyaml.org/load --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 42d8819..4cc92a3 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ long_description=README + '\n\n' + CHANGES, install_requires=[ 'setuptools', - 'PyYAML>=3.10', + 'PyYAML==3.13', 'six>=1.9.0', ], tests_require=[ From 4704d7d9e7a323135238d728b3232dae9ecc9667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Zago=C5=BEen?= Date: Thu, 25 Apr 2019 20:13:42 +0200 Subject: [PATCH 2/4] Fix unit tests to expect OrderedDict instead of dict. The parser outputs OrderedDict instances. Tests were not fixed after this change :o --- tests/test_parser_functional.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_parser_functional.py b/tests/test_parser_functional.py index 58693f5..f9ef1d5 100644 --- a/tests/test_parser_functional.py +++ b/tests/test_parser_functional.py @@ -8,6 +8,13 @@ except ImportError: from xml.etree.ElementTree import Element as XMLElement +try: + from collections import OrderedDict +except ImportError: + # For python 2.6 additional package ordereddict should be installed + from ordereddict import OrderedDict + + class RootParseTestCase(SampleParseTestCase): """ Test parsing of: @@ -332,7 +339,7 @@ def test_method_body_json_parsed(self): "required": False, "type": "object" }) - self.assertEqual(appjson.example, '{ "input": "hola" }') + self.assertEqual(appjson.example, OrderedDict([(u'input', u'hola')])) self.assertIsNone(appjson.formParameters) def test_method_body_xml_parsed(self): @@ -387,7 +394,7 @@ def test_method_responses_desc_body_parsed(self): self.assertEqual(len(responses[200].body), 1) self.assertEqual( responses[200].body['application/json'].example, - '{ "key": "value" }') + OrderedDict([(u'key', u'value')])) self.assertEqual( responses[200].body['application/json'].schema, 'league-json') @@ -482,7 +489,7 @@ def test_complex_resourcetypes_parsed(self): self.assertEqual(len(post.responses), 1) resp200 = post.responses[200] self.assertEqual(resp200.body['application/json'].example, - '{ "message": "Foo" }') + OrderedDict([(u'message', u'Foo')])) class TraitsParseTestCase(SampleParseTestCase): @@ -536,7 +543,7 @@ def test_traits_responses_parsed(self): resp200 = data.traits['orderable'].responses[200] self.assertEqual(len(resp200.body), 1) self.assertEqual(resp200.body['application/json'].example, - '{ "message": "Bar" }') + OrderedDict([(u'message', u'Bar')])) class SecuritySchemesParseTestCase(SampleParseTestCase): @@ -601,7 +608,7 @@ def test_describedby_body_parsed(self): self.assertEqual(len(body), 2) appjson = body['application/json'] self.assertDictEqual(appjson.schema, {"foo": "bar"}) - self.assertEqual(appjson.example, '{ "input": "hola" }') + self.assertEqual(appjson.example, OrderedDict([(u'input', u'hola')])) self.assertIsNone(appjson.formParameters) xmlbody = body['text/xml'] self.assertIsInstance(xmlbody.schema, XMLElement) @@ -627,7 +634,7 @@ def test_describedby_responses_parsed(self): self.assertEqual(resp401.description, 'Bad or expired token') self.assertEqual(len(resp401.body), 1) self.assertEqual(resp401.body['application/json'].example, - '{ "message": "fail" }') + OrderedDict([(u'message', u'fail')])) self.assertIsNone(resp401.body['application/json'].schema) def test_describedby_not_provided(self): From da8e87d8f564a936dec32bc306708560fc23fc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Zagoz=CC=8Cen?= Date: Fri, 26 Apr 2019 01:30:32 +0200 Subject: [PATCH 3/4] Use !include content as a string. --- pyraml/parser.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pyraml/parser.py b/pyraml/parser.py index 7889f9d..b3d2f3a 100644 --- a/pyraml/parser.py +++ b/pyraml/parser.py @@ -62,13 +62,6 @@ def _handle_load(self, data): if isinstance(data, ParserRamlInclude): file_content, file_type = self._load_resource(data.file_name) - if not _is_mime_type_raml(file_type): - - file_content_dict = {} - file_content_dict['fileName'] = data.file_name - file_content_dict['content'] = file_content - file_content = json.dumps(file_content_dict) - if _is_mime_type_raml(file_type): new_relative_path = _calculate_new_relative_path( self.relative_path, data.file_name) From 1bcb5f152905c2ada02430afbf729fbb155bce27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Zago=C5=BEen?= Date: Fri, 26 Apr 2019 10:57:27 +0200 Subject: [PATCH 4/4] Fix test to expect a dict instance. --- tests/test_parser_functional.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_parser_functional.py b/tests/test_parser_functional.py index f9ef1d5..60b0249 100644 --- a/tests/test_parser_functional.py +++ b/tests/test_parser_functional.py @@ -208,7 +208,7 @@ def test_regression_include_body_example_json(self): data = self.load('include-body-example-json.yaml') responses = data.resources['/me'].methods['get'].responses[200] json_response = responses.body['application/json'] - self.assertEqual(json_response.example, '{"foo": "bar"}') + self.assertEqual(json_response.example, {u'foo': u'bar'}) class ResourceParseTestCase(SampleParseTestCase):