コード例 #1
0
ファイル: __init__.py プロジェクト: jenner/ramlfications
def validate(raml, config_file=None):
    """
    Module helper function to validate a RAML File.  First loads \
    the RAML file \
    with :py:class:`.loader.RAMLLoader` then validates with \
    :py:func:`.validate.validate_raml`.

    :param str raml: Either string path to the RAML file, a file object, \or
        a string representation of RAML.
    :param str config_file:  String path to desired config file, if any.
    :return: No return value if successful
    :raises LoadRAMLError: If error occurred trying to load the RAML file
        (see :py:class:`.loader.RAMLLoader`)
    :raises InvalidRootNodeError: API metadata is invalid according to RAML \
        `specification <http://raml.org/spec.html>`_.
    :raises InvalidResourceNodeError: API resource endpoint is invalid \
        according to RAML `specification <http://raml.org/spec.html>`_.
    :raises InvalidParameterError: Named parameter is invalid \
        according to RAML `specification <http://raml.org/spec.html>`_.
    :raises InvalidRAMLError: RAML file is invalid according to RAML \
        `specification <http://raml.org/spec.html>`_.
    """
    loader = load(raml)
    config = setup_config(config_file)
    config["validate"] = True
    parse_raml(loader, config)
コード例 #2
0
def validate(raml, config_file=None):
    """
    Module helper function to validate a RAML File.  First loads \
    the RAML file \
    with :py:class:`.loader.RAMLLoader` then validates with \
    :py:func:`.validate.validate_raml`.

    :param str raml: Either string path to the RAML file, a file object, \or
        a string representation of RAML.
    :param str config_file:  String path to desired config file, if any.
    :return: No return value if successful
    :raises LoadRAMLError: If error occurred trying to load the RAML file
        (see :py:class:`.loader.RAMLLoader`)
    :raises InvalidRootNodeError: API metadata is invalid according to RAML \
        `specification <http://raml.org/spec.html>`_.
    :raises InvalidResourceNodeError: API resource endpoint is invalid \
        according to RAML `specification <http://raml.org/spec.html>`_.
    :raises InvalidParameterError: Named parameter is invalid \
        according to RAML `specification <http://raml.org/spec.html>`_.
    :raises InvalidRAMLError: RAML file is invalid according to RAML \
        `specification <http://raml.org/spec.html>`_.
    """
    loader = load(raml)
    config = setup_config(config_file)
    config["validate"] = True
    parse_raml(loader, config)
コード例 #3
0
def test_resource_type_empty_mapping_headers():
    raml_file = os.path.join(EXAMPLES + "empty-mapping.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    base_res_type = api.resource_types[0]

    assert len(base_res_type.headers) == 3
    assert base_res_type.headers[-1].description is None
コード例 #4
0
def test_resource_type_empty_mapping_headers():
    raml_file = os.path.join(EXAMPLES + "empty-mapping.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    base_res_type = api.resource_types[0]

    assert len(base_res_type.headers) == 3
    assert base_res_type.headers[-1].description is None
コード例 #5
0
ファイル: __init__.py プロジェクト: postatum/ramlfications
def validate(raml, config_file=None):
    """
    Module helper function to validate a RAML File.  First loads \
    the RAML file \
    with :py:class:`.loader.RAMLLoader` then validates with \
    :py:func:`.validate.validate_raml`.

    :param str raml: Either string path to the RAML file, a file object, \or
        a string representation of RAML.
    :param str config_file:  String path to desired config file, if any.
    :return: No return value if successful
    :raises LoadRAMLError: If error occurred trying to load the RAML file
        (see :py:class:`.loader.RAMLLoader`)
    :raises InvalidRamlFileError: If error occurred trying to validate the RAML
        file (see :py:mod:`.validate`)

    """
    loader = load(raml)
    config = setup_config(config_file)
    config["validate"] = True
    parse_raml(loader, config)
コード例 #6
0
def test_resource_response_no_desc():
    raml_file = os.path.join(EXAMPLES + "empty-mapping.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    res = api.resources[-1]
    response = res.responses[-1]

    assert response.code == 204
    assert response.description is None
コード例 #7
0
def test_resource_response_no_desc():
    raml_file = os.path.join(EXAMPLES + "empty-mapping.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    res = api.resources[-1]
    response = res.responses[-1]

    assert response.code == 204
    assert response.description is None
コード例 #8
0
def test_resource_type_empty_mapping():
    raml_file = os.path.join(EXAMPLES + "empty-mapping-resource-type.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    assert len(api.resource_types) == 1

    res = api.resource_types[0]

    assert res.name == "emptyType"
    assert res.raw == {}
コード例 #9
0
def test_resource_type_empty_mapping():
    raml_file = os.path.join(EXAMPLES + "empty-mapping-resource-type.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    assert len(api.resource_types) == 1

    res = api.resource_types[0]

    assert res.name == "emptyType"
    assert res.raw == {}
コード例 #10
0
def decode_raml(bytestring, base_url=None):
    loader = RAMLLoader(base_url)
    data = loader.load(bytestring)
    config = setup_config()
    config['validate'] = False
    raml = parse_raml(data, config)

    content = {}
    for resource in raml.resources:
        fields = []
        encoding = ''

        for param in resource.uri_params or []:
            field = coreapi.Field(param.name, param.required, location='path')
            fields.append(field)

        for param in resource.query_params or []:
            field = coreapi.Field(param.name, param.required, location='query')
            fields.append(field)

        if resource.body:
            body = resource.body[0]
            encoding = body.mime_type

            for form_param in body.form_params or []:
                field = coreapi.Field(param.name,
                                      param.required,
                                      location='form')
                fields.append(field)

            if body.schema:
                schema_fields = expand_schema(body.schema)
                fields.extend(schema_fields)

        link = coreapi.Link(url=resource.absolute_uri,
                            action=resource.method.lower(),
                            encoding=encoding,
                            fields=fields)
        content[resource.display_name] = link

    return coreapi.Document(title=raml.title, url=base_url, content=content)
コード例 #11
0
ファイル: __init__.py プロジェクト: postatum/ramlfications
def parse(raml, config_file=None):
    """
    Module helper function to parse a RAML File.  First loads the RAML file
    with :py:class:`.loader.RAMLLoader` then parses with
    :py:func:`.parser.parse_raml` to return a :py:class:`.raml.RAMLRoot`
    object.

    :param raml: Either string path to the RAML file, a file object, or \
        a string representation of RAML.
    :param str config_file:  String path to desired config file, if any.
    :return: parsed API
    :rtype: RAMLRoot
    :raises LoadRAMLError: If error occurred trying to load the RAML file
        (see :py:class:`.loader.RAMLLoader`)
    :raises RAMLParserError: If error occurred during parsing of RAML file
        (see :py:class:`.raml.RAMLRoot`)
    :raises InvalidRamlFileError: RAML file is invalid according to RAML \
        `specification <http://raml.org/spec.html>`_.
    """
    loader = load(raml)
    config = setup_config(config_file)
    return parse_raml(loader, config)
コード例 #12
0
def parse(raml, config_file=None):
    """
    Module helper function to parse a RAML File.  First loads the RAML file
    with :py:class:`.loader.RAMLLoader` then parses with
    :py:func:`.parser.parse_raml` to return a :py:class:`.raml.RAMLRoot`
    object.

    :param raml: Either string path to the RAML file, a file object, or \
        a string representation of RAML.
    :param str config_file:  String path to desired config file, if any.
    :return: parsed API
    :rtype: RAMLRoot
    :raises LoadRAMLError: If error occurred trying to load the RAML file
        (see :py:class:`.loader.RAMLLoader`)
    :raises InvalidRootNodeError: API metadata is invalid according to RAML \
        `specification <http://raml.org/spec.html>`_.
    :raises InvalidResourceNodeError: API resource endpoint is invalid \
        according to RAML `specification <http://raml.org/spec.html>`_.
    :raises InvalidParameterError: Named parameter is invalid \
        according to RAML `specification <http://raml.org/spec.html>`_.
    """
    loader = load(raml)
    config = setup_config(config_file)
    return parse_raml(loader, config)
コード例 #13
0
def test_parse_raml(raml):
    config_file = os.path.join(EXAMPLES, "twitter-config.ini")
    config = setup_config(config_file)
    root = pw.parse_raml(raml, config)
    assert isinstance(root, RootNode)
コード例 #14
0
def test_parse_raml(loaded_raml):
    config = setup_config(EXAMPLES + "test-config.ini")
    root = pw.parse_raml(loaded_raml, config)
    assert isinstance(root, RootNode)
コード例 #15
0
def api(raml):
    config_file = os.path.join(EXAMPLES, "twitter-config.ini")
    config = setup_config(config_file)
    return pw.parse_raml(raml, config)
コード例 #16
0
def md_includes():
    raml_file = os.path.join(EXAMPLES + "md_includes.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.parse_raml(loaded_raml_file, config)
コード例 #17
0
ファイル: test_parser.py プロジェクト: wade1990/ramlfications
def inherited_resources():
    raml_file = os.path.join(EXAMPLES, "resource-type-inherited.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config["validate"] = False
    return pw.parse_raml(loaded_raml, config)
コード例 #18
0
ファイル: test_parser.py プロジェクト: wade1990/ramlfications
def resource_protocol():
    raml_file = os.path.join(EXAMPLES, "protocols.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)
コード例 #19
0
def api():
    raml_str = os.path.join(EXAMPLES, "simple-tree.raml")
    loaded_raml = load_file(raml_str)
    config_file = os.path.join(EXAMPLES + "test-config.ini")
    config = setup_config(config_file)
    return parser.parse_raml(loaded_raml, config)
コード例 #20
0
def uri_param_resources():
    raml_file = os.path.join(EXAMPLES, "preserve-uri-order.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)
コード例 #21
0
def resource_protocol():
    raml_file = os.path.join(EXAMPLES, "protocols.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)
コード例 #22
0
def test_parse_raml(raml):
    config_file = os.path.join(EXAMPLES, "twitter-config.ini")
    config = setup_config(config_file)
    root = pw.parse_raml(raml, config)
    assert isinstance(root, RootNode)
コード例 #23
0
def resources():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    api = pw.parse_raml(loaded_raml_file, config)
    return api.resources
コード例 #24
0
def undef_uri_params_resources():
    raml_file = os.path.join(EXAMPLES, "undefined-uri-params.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)
コード例 #25
0
def external_resource_with_multiple_methods():
    raml_file = os.path.join(
        EXAMPLES + "external_resource_with_multiple_methods.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.parse_raml(loaded_raml_file, config)
コード例 #26
0
ファイル: test_parser.py プロジェクト: wade1990/ramlfications
def uri_param_resources():
    raml_file = os.path.join(EXAMPLES, "preserve-uri-order.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)
コード例 #27
0
def resources():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    api = pw.parse_raml(loaded_raml_file, config)
    return api.resources
コード例 #28
0
ファイル: test_parser.py プロジェクト: wade1990/ramlfications
def undef_uri_params_resources():
    raml_file = os.path.join(EXAMPLES, "undefined-uri-params.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)
コード例 #29
0
def md_includes():
    raml_file = os.path.join(EXAMPLES + "md_includes.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.parse_raml(loaded_raml_file, config)
コード例 #30
0
def test_parse_raml(loaded_raml):
    config = setup_config(EXAMPLES + "test-config.ini")
    root = pw.parse_raml(loaded_raml, config)
    assert isinstance(root, RootNode)
コード例 #31
0
def api(raml):
    config_file = os.path.join(EXAMPLES, "twitter-config.ini")
    config = setup_config(config_file)
    return pw.parse_raml(raml, config)
コード例 #32
0
def inherited_resources():
    raml_file = os.path.join(EXAMPLES, "resource-type-inherited.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config["validate"] = False
    return pw.parse_raml(loaded_raml, config)