jdiegodcp / ramlfications

Python parser for RAML
https://ramlfications.readthedocs.org
Apache License 2.0
234 stars 50 forks source link

Error gracefully for empty mappings #30

Closed econchick closed 8 years ago

econchick commented 8 years ago

parser.py fails when the RAML file has an empty mapping, e.g.:

/foo:
  get:
    responses:
      200:
        body:
          text/plain:

the following traceback occurs:

----> 1 api = parse(RAML_FILE, CONFIG)

/Users/lynnroot/.virtualenvs/spotify-raml/lib/python2.7/site-packages/ramlfications/__init__.pyc in parse(raml, config_file)
     66     loader = load(raml)
     67     config = setup_config(config_file)
---> 68     return parse_raml(loader, config)
     69
     70

/Users/lynnroot/.virtualenvs/spotify-raml/lib/python2.7/site-packages/ramlfications/parser.pyc in parse_raml(loaded_raml, config)
     37     root.resource_types = create_resource_types(root.raml_obj, root)
     38     root.resources = create_resources(root.raml_obj, [], root,
---> 39                                       parent=None)
     40     if config.get("validate"):
     41         attr.validate(root)

/Users/lynnroot/.virtualenvs/spotify-raml/lib/python2.7/site-packages/ramlfications/parser.pyc in create_resources(node, resources, root, parent)
    748                                         method=m,
    749                                         parent=parent,
--> 750                                         root=root)
    751                     resources.append(child)
    752             else:

/Users/lynnroot/.virtualenvs/spotify-raml/lib/python2.7/site-packages/ramlfications/parser.pyc in create_node(name, raw_data, method, parent, root)
   1206         headers=headers(),
   1207         body=body(),
-> 1208         responses=responses(),
   1209         uri_params=uri_params(),
   1210         base_uri_params=base_uri_params(),

/Users/lynnroot/.virtualenvs/spotify-raml/lib/python2.7/site-packages/ramlfications/parser.pyc in responses()
   1012                     raw={k: v},
   1013                     method=method,
-> 1014                     desc=v.get("description"),
   1015                     headers=resp_headers(v.get("headers", {})),
   1016                     body=resp_body(v.get("body", {})),

AttributeError: 'NoneType' object has no attribute 'get'

This is ugly and shouldn't happen :)

econchick commented 8 years ago

Addressed in #34 - will be included in release 0.1.6