コード例 #1
0
ファイル: parser.py プロジェクト: gooli/pyraml-parser
def parse_method(ctx):
    """ Parse RAML resource method.

    Parsing happens in a separate function(here) because of need to
    parse ``is`` key as ``is_`` field.

    :param ctx: ParseContext object which contains RamlMethod
    :type ctx: ParseContext

    :param parent_object: RamlRoot, RamlResource or RamlResourceType object
    :type parent_object: RamlRoot or RamlResource or RamlResourceType

    :return: RamlMethod or None
    :rtype: RamlMethod
    """

    method = RamlMethod()
    method.description = ctx.get_property_with_schema(
        "description", RamlMethod.description)
    method.body = ctx.get_property_with_schema("body", RamlMethod.body)
    method.baseUriParameters = ctx.get_property_with_schema(
        "baseUriParameters", RamlMethod.baseUriParameters)
    method.headers = ctx.get_property_with_schema(
        "headers", RamlMethod.headers)
    method.protocols = ctx.get_property_with_schema(
        "protocols", RamlMethod.protocols)
    method.responses = ctx.get_property_with_schema(
        "responses", RamlMethod.responses)
    method.is_ = ctx.get_property_with_schema(
        RamlMethod.is_.field_name, RamlMethod.is_)
    method.queryParameters = ctx.get_property_with_schema(
        "queryParameters", RamlMethod.queryParameters)
    method.securedBy = ctx.get_property_with_schema(
        'securedBy', RamlMethod.securedBy)
    return method
コード例 #2
0
ファイル: parser.py プロジェクト: jinchoe/raml2doc
def parse_resource(c, property_name, parent_object):
    """
    Parse and extract resource with name

    :param c:
    :type c: ParseContext

    :param parent_object: RamlRoot object or RamlResource object
    :type parent_object: RamlRoot or RamlResource

    :param property_name: resource name to extract
    :type property_name: str

    :return: RamlResource  or None
    :rtype: RamlResource
    """
    property_value = c.get(property_name)
    if not property_value:
        return None

    resource = RamlResource(uri=property_name)
    new_context = ParseContext(property_value, c.relative_path)
    resource.description = new_context.get_string_property("description")
    resource.displayName = new_context.get_string_property("displayName")
    resource.is_ = new_context.get_string_property("is")
    resource.queryParameters = new_context.get_property_with_schema(
        "queryParameters", RamlMethod.queryParameters)
    if isinstance(parent_object, RamlResource):
        resource.parentResource = parent_object

    # Parse methods
    methods = OrderedDict()
    for _http_method in ["get", "post", "put", "delete", "head"]:
        _method = new_context.get(_http_method)
        if _method:
            _method = parse_method(ParseContext(_method, c.relative_path),
                                   resource)
            methods[_http_method] = _method
        elif _http_method in new_context.data:
            # workaround: if _http_method is already in new_context.data than
            # it's marked as !!null
            _method = RamlMethod(notNull=True)
            methods[_http_method] = _method

    if len(methods):
        resource.methods = methods

    # Parse resources
    resources = OrderedDict()
    for property_name in new_context.__iter__():
        if property_name.startswith("/"):
            resources[property_name] = parse_resource(new_context,
                                                      property_name, resource)

    if resources > 0:
        resource.resources = resources

    return resource
コード例 #3
0
ファイル: parser.py プロジェクト: jinchoe/raml2doc
def parse_method(c, parent_object):
    """
    Parse RAML method

    :param c: ParseContext object which contains RamlMethod
    :type c: ParseContext

    :param parent_object: RamlRoot, RamlResource or RamlResourceType object
    :type parent_object: RamlRoot or RamlResource or RamlResourceType

    :return: RamlMethod  or None
    :rtype: RamlMethod
    """

    method = RamlMethod()
    method.responses = c.get_property_with_schema("responses",
                                                  RamlMethod.responses)
    method.description = c.get_string_property("description")
    #print "parse_method", method.description
    #print "parse_method",c.data
    context = ParseContext(c.get("body"), c.relative_path)
    method.body = parse_body(context)
    method.queryParameters = c.get_property_with_schema(
        "queryParameters", RamlMethod.queryParameters)
    method.is_ = c.get_string_property("is")

    return method
コード例 #4
0
ファイル: parser.py プロジェクト: econchick/pyraml-parser
def parse_method(c, parent_object):
    """
    Parse RAML method

    :param c: ParseContext object which contains RamlMethod
    :type c: ParseContext

    :param parent_object: RamlRoot, RamlResource or RamlResourceType object
    :type parent_object: RamlRoot or RamlResource or RamlResourceType

    :return: RamlMethod  or None
    :rtype: RamlMethod
    """

    method = RamlMethod()
    method.responses = c.get_property_with_schema("responses", RamlMethod.responses)
    method.description = c.get_string_property("description")
    method.body = parse_body(ParseContext(c.get("body"), c.relative_path), method)
    return method
コード例 #5
0
ファイル: parser.py プロジェクト: jinchoe/raml2doc
def parse_resource_type(c):
    """
    Parse and extract resourceType

    :param c: ParseContext object
    :type c: ParseContext

    :return: RamlResource  or None
    :rtype: RamlResource
    """

    json_resource_types = c.get('resourceTypes')
    if not json_resource_types:
        return None

    # We got list of dict from c.get('resourceTypes') so we need to convert it to dict
    #print json_resource_types[0], c.relative_path
    resource_types_context = ParseContext(json_resource_types[0],
                                          c.relative_path)

    resource_types = {}

    for rtype_name in resource_types_context:
        new_c = ParseContext(resource_types_context.get(rtype_name),
                             resource_types_context.relative_path)

        rtype_obj = RamlResourceType()
        rtype_obj.type = new_c.get_string_property("type")
        rtype_obj.is_ = new_c.get_property_with_schema("is",
                                                       RamlResourceType.is_)

        # Parse methods
        methods = OrderedDict()
        for _http_method in ["get", "post", "put", "delete", "head"]:
            _method = new_c.get(_http_method)
            if _method:
                _method = ParseContext(
                    _method, new_c.relative_path).get_property_with_schema(
                        'traits', Reference(RamlTrait))
                methods[_http_method] = _method
            elif _http_method in new_c.data:
                # workaround: if _http_method is already in new_context.data than
                # it's marked as !!null
                _method = RamlMethod(notNull=True)
                methods[_http_method] = _method

        if len(methods):
            rtype_obj.methods = methods

        resource_types[rtype_name] = rtype_obj

    return resource_types
コード例 #6
0
ファイル: parser.py プロジェクト: elifiner/pyraml-parser
def parse_resource_methods(resource_ctx):
    """ Parse existing HTTP_METHODS from a resource_ctx. """
    methods = OrderedDict()
    for _http_method in HTTP_METHODS:
        if _http_method not in resource_ctx:
            continue
        _method = resource_ctx.get(_http_method)
        if _method:
            methods[_http_method] = parse_method(
                ParseContext(_method, resource_ctx.relative_path))
        else:
            methods[_http_method] = RamlMethod(notNull=True)
    return methods
コード例 #7
0
ファイル: parser.py プロジェクト: elifiner/pyraml-parser
def parse_method(ctx):
    """ Parse RAML resource method.

    Parsing happens in a separate function(here) because of need to
    parse ``is`` key as ``is_`` field.

    :param ctx: ParseContext object which contains RamlMethod
    :type ctx: ParseContext

    :param parent_object: RamlRoot, RamlResource or RamlResourceType object
    :type parent_object: RamlRoot or RamlResource or RamlResourceType

    :return: RamlMethod or None
    :rtype: RamlMethod
    """

    method = RamlMethod()
    method.description = ctx.get_property_with_schema("description",
                                                      RamlMethod.description)
    method.body = ctx.get_property_with_schema("body", RamlMethod.body)
    method.baseUriParameters = ctx.get_property_with_schema(
        "baseUriParameters", RamlMethod.baseUriParameters)
    method.headers = ctx.get_property_with_schema("headers",
                                                  RamlMethod.headers)
    method.protocols = ctx.get_property_with_schema("protocols",
                                                    RamlMethod.protocols)
    method.responses = ctx.get_property_with_schema("responses",
                                                    RamlMethod.responses)
    method.is_ = ctx.get_property_with_schema(RamlMethod.is_.field_name,
                                              RamlMethod.is_)
    method.queryParameters = ctx.get_property_with_schema(
        "queryParameters", RamlMethod.queryParameters)
    method.securedBy = ctx.get_property_with_schema('securedBy',
                                                    RamlMethod.securedBy)
    return method