parser.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:raml2doc 作者: openconnectivityfoundation 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号