Skip to content

Commit 268e85d

Browse files
committed
Merge pull request #10 from econchick/master
Temp fix for py3 builds; mock out writes to file
2 parents 5ce220e + ff44947 commit 268e85d

21 files changed

+339
-27
lines changed

ramlfications/data/supported_mime_types.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

ramlfications/loader.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,19 @@ def _yaml_include(self, loader, node):
2727
# Get the path out of the yaml file
2828
file_name = os.path.join(os.path.dirname(loader.name), node.value)
2929

30+
file_ext = os.path.splitext(file_name)[1]
31+
parsable_ext = [".yaml", ".yml", ".raml", ".json"]
32+
33+
if file_ext not in parsable_ext:
34+
with open(file_name) as inputfile:
35+
return inputfile.read()
36+
3037
with open(file_name) as inputfile:
31-
return yaml.load(inputfile)
38+
try:
39+
return yaml.load(inputfile)
40+
except yaml.loader.ConstructorError:
41+
msg = "Recursively-including files not supported."
42+
raise LoadRAMLError(msg)
3243

3344
def _ordered_load(self, stream, loader=yaml.Loader):
3445
"""
@@ -61,3 +72,6 @@ def load(self, raml):
6172
except yaml.parser.ParserError as e:
6273
msg = "Error parsing RAML: {0}".format(e)
6374
raise LoadRAMLError(msg)
75+
except yaml.constructor.ConstructorError as e:
76+
msg = "Error parsing RAML: {0}".format(e)
77+
raise LoadRAMLError(msg)

ramlfications/parser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ def docs():
117117
return docs or None
118118

119119
def schemas():
120-
return raml.get("schemas")
120+
_schemas = raml.get("schemas")
121+
if not _schemas:
122+
return None
123+
schemas = []
124+
for schema in _schemas:
125+
value = load_schema(list(itervalues(schema))[0])
126+
schemas.append({list(iterkeys(schema))[0]: value})
127+
return schemas or None
121128

122129
def secured_by():
123130
return raml.get("securedBy")

ramlfications/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ def parse_xml_data(xml_data):
103103
return all_mime_types
104104

105105

106-
def save_data(mime_types):
107-
current_dir = os.path.dirname(os.path.realpath(__file__))
108-
data_dir = os.path.join(current_dir, "data")
109-
output_file = os.path.join(data_dir, "supported_mime_types.json")
110-
106+
def save_data(output_file, mime_types):
111107
with open(output_file, "w") as f:
112108
json.dump(mime_types, f)
113109

@@ -140,6 +136,11 @@ def setup_logger():
140136
log.debug("Data received; parsing...")
141137
xml_data = xml_to_dict(raw_data)
142138
mime_types = parse_xml_data(xml_data)
143-
save_data(mime_types)
139+
140+
current_dir = os.path.dirname(os.path.realpath(__file__))
141+
data_dir = os.path.join(current_dir, "data")
142+
output_file = os.path.join(data_dir, "supported_mime_types.json")
143+
144+
save_data(output_file, mime_types)
144145

145146
log.debug("Done! Supported IANA MIME media types have been updated.")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#%RAML 0.8
2+
title: Sample API Demo - Cyclic Includes
3+
version: v1
4+
first: !include includes/first-level-includes.raml
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#%RAML 0.8
2+
title: Sample API Demo - Invalid Tag in Includes
3+
version: v1
4+
incorrect: !include: includes/invalid_yaml_tag.raml
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "foo",
3+
"false": true
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Foo
2+
3+
*Bacon ipsum dolor* amet pork belly _doner_ rump brisket. [Cupim jerky shoulder][0] ball tip, jowl bacon meatloaf shank kielbasa turducken corned beef beef turkey porchetta.
4+
5+
### Doner meatball pork belly andouille drumstick sirloin
6+
7+
Porchetta picanha tail sirloin kielbasa, pig meatball short ribs drumstick jowl. Brisket swine spare ribs picanha t-bone. Ball tip beef tenderloin jowl doner andouille cupim meatball. Porchetta hamburger filet mignon jerky flank, meatball salami beef cow venison tail ball tip pork belly.
8+
9+
[0]: https://baconipsum.com/?paras=1&type=all-meat&start-with-lorem=1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<root>
3+
<false>true</false>
4+
<name>foo</name>
5+
</root>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#%RAML 0.8
2+
foo: bar
3+
baz: blah
4+
second: !include second_level_includes/second-includes.raml

0 commit comments

Comments
 (0)