Skip to content

Commit

Permalink
Basic completeness
Browse files Browse the repository at this point in the history
  • Loading branch information
leedm777 committed Aug 29, 2013
1 parent 314b665 commit 108f0fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions swaggerpy/jsonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def __iter__(self):
for kv in self.items():
yield kv

def __len__(self):
"""Allow len(jsonified)
"""
return len(self.get_field_names())

def get_field_names(self):
"""Returns a list of the field names for this JSON object.
Expand Down
15 changes: 13 additions & 2 deletions swaggerpy/swagger_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def process_api_declaration(self, resources, resource, context):
if model_name != model.id:
raise SwaggerError("Model id doesn't match name", context)
# Convert models dict to list
resource.model_list = resource.models.values()

def process_resource_api(self, resources, resource, api, context):
required_fields = ['path', 'operations']
Expand All @@ -104,7 +103,6 @@ def process_model(self, resources, resource, model, context):
for (prop_name, prop) in model.properties:
prop.name = prop_name
# Convert properties dict to list
model.property_list = model.properties.values()

def process_property(self, resources, resource, model, prop,
context):
Expand All @@ -114,6 +112,19 @@ def process_type(self, swagger_type, context):
pass


class FlatenningProcessor(SwaggerProcessor):
"""Flattens model and property dictionaries into lists.
Makes Mustache possible to have a regular schema.
"""
def process_api_declaration(self, resources, resource, context):
resource.model_list = resource.models.values()

def process_model(self, resources, resource, model, context):
# Convert properties dict to list
model.property_list = model.properties.values()


def load_url(opener, url):
"""Download and parse JSON from a URL, wrapping in a Jsonify.
Expand Down
5 changes: 2 additions & 3 deletions swaggerpy_test/loader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class LoaderTest(unittest.TestCase):
def test_simple(self):
uut = swaggerpy.load_file('test-data/1.1/simple/resources.json')
self.assertEqual('1.1', uut.swaggerVersion)
self.assertEqual(1, len(uut.apis[0].api_declaration.model_list))
self.assertEqual(1, len(uut.apis[0].api_declaration.model_list))
self.assertEqual(1, len(uut.apis[0].api_declaration.models))
self.assertEqual(1, len(
uut.apis[0].api_declaration.model_list[0].property_list))
uut.apis[0].api_declaration.models.Simple.properties))

def test_processor(self):
uut = swaggerpy.load_file('test-data/1.1/simple/resources.json',
Expand Down

0 comments on commit 108f0fa

Please sign in to comment.