def parse(c, relative_path):
"""
Parse RAML file
:param c: file content
:type c: str
:return:
"""
# Read RAML header
first_line, c = c.split('\n', 1)
raml_version = _validate_raml_header(first_line)
#includes = None
# Adding yaml !include support before calling the load function
#try:
# includes = yaml.add_constructor("!include", yaml_include)
#except:
# pass
context = ParseContext(yaml.load(c), relative_path)
root = RamlRoot(raml_version=raml_version)
root.title = context.get_string_property('title', True)
schemas = context.get_string_property('schemas')
root.schemas = schemas
root.baseUri = context.get_string_property('baseUri')
root.version = context.get_string_property('version')
root.mediaType = context.get_string_property('mediaType')
root.documentation = context.get_property_with_schema('documentation', RamlRoot.documentation)
root.traits = parse_traits(context, RamlRoot.traits.field_name)
root.resourceTypes = parse_resource_type(context)
resources = OrderedDict()
for property_name in context.__iter__():
if property_name.startswith("/"):
resources[property_name] = parse_resource(context, property_name, root)
if resources > 0:
root.resources = resources
return root
评论列表
文章目录