Ejemplo n.º 1
0
def includeme(config):
    """
    :type config: :class:`pyramid.config.Configurator`
    """
    settings = config.registry.settings
    swagger_versions = get_swagger_versions(settings)

    # for rendering /swagger.yaml
    config.add_renderer(
        'yaml',
        'pyramid_swagger.api.YamlRendererFactory',
    )

    # Add the SwaggerSchema to settings to make it available to the validation
    # tween and `register_api_doc_endpoints`
    settings['pyramid_swagger.schema12'] = None
    settings['pyramid_swagger.schema20'] = None

    # Store under two keys so that 1.2 and 2.0 can co-exist.
    if SWAGGER_12 in swagger_versions:
        settings['pyramid_swagger.schema12'] = get_swagger_schema(settings)

    if SWAGGER_20 in swagger_versions:
        settings['pyramid_swagger.schema20'] = get_swagger_spec(settings)

    config.add_tween("pyramid_swagger.tween.validation_tween_factory",
                     under=pyramid.tweens.EXCVIEW)

    config.add_renderer('pyramid_swagger', PyramidSwaggerRendererFactory())

    if settings.get('pyramid_swagger.enable_api_doc_views', True):
        if SWAGGER_12 in swagger_versions:
            register_api_doc_endpoints(
                config,
                settings['pyramid_swagger.schema12'].get_api_doc_endpoints())

        if SWAGGER_20 in swagger_versions:
            register_api_doc_endpoints(
                config,
                build_swagger_20_swagger_schema_views(config),
                base_path=settings.get('pyramid_swagger.base_path_api_docs',
                                       ''))
Ejemplo n.º 2
0
def includeme(config):
    """
    :type config: :class:`pyramid.config.Configurator`
    """
    settings = config.registry.settings
    swagger_versions = get_swagger_versions(settings)

    # for rendering /swagger.yaml
    config.add_renderer(
        'yaml', 'pyramid_swagger.api.YamlRendererFactory',
    )

    # Add the SwaggerSchema to settings to make it available to the validation
    # tween and `register_api_doc_endpoints`
    settings['pyramid_swagger.schema12'] = None
    settings['pyramid_swagger.schema20'] = None

    # Store under two keys so that 1.2 and 2.0 can co-exist.
    if SWAGGER_12 in swagger_versions:
        settings['pyramid_swagger.schema12'] = get_swagger_schema(settings)

    if SWAGGER_20 in swagger_versions:
        settings['pyramid_swagger.schema20'] = get_swagger_spec(settings)

    config.add_tween(
        "pyramid_swagger.tween.validation_tween_factory",
        under=pyramid.tweens.EXCVIEW
    )

    config.add_renderer('pyramid_swagger', PyramidSwaggerRendererFactory())

    if settings.get('pyramid_swagger.enable_api_doc_views', True):
        if SWAGGER_12 in swagger_versions:
            register_api_doc_endpoints(
                config,
                settings['pyramid_swagger.schema12'].get_api_doc_endpoints())

        if SWAGGER_20 in swagger_versions:
            register_api_doc_endpoints(
                config,
                build_swagger_20_swagger_schema_views(config),
                base_path=settings.get('pyramid_swagger.base_path_api_docs', ''))
Ejemplo n.º 3
0
def test_get_swagger_versions_unsupported():
    settings = {'pyramid_swagger.swagger_versions': ['10.0', '2.0']}
    with pytest.raises(ValueError) as excinfo:
        get_swagger_versions(settings)
    assert 'Swagger version 10.0 is not supported' in str(excinfo.value)
Ejemplo n.º 4
0
def test_get_swagger_versions_empty():
    settings = {'pyramid_swagger.swagger_versions': []}
    with pytest.raises(ValueError) as excinfo:
        get_swagger_versions(settings)
    assert 'pyramid_swagger.swagger_versions is empty' in str(excinfo.value)
Ejemplo n.º 5
0
def test_get_swagger_versions_success():
    for versions in (['1.2'], ['2.0'], ['1.2', '2.0']):
        settings = {'pyramid_swagger.swagger_versions': versions}
        assert set(versions) == get_swagger_versions(settings)
Ejemplo n.º 6
0
def test_get_swagger_versions_unsupported():
    settings = {'pyramid_swagger.swagger_versions': ['10.0', '2.0']}
    with pytest.raises(ValueError) as excinfo:
        get_swagger_versions(settings)
    assert 'Swagger version 10.0 is not supported' in str(excinfo.value)
Ejemplo n.º 7
0
def test_get_swagger_versions_empty():
    settings = {'pyramid_swagger.swagger_versions': []}
    with pytest.raises(ValueError) as excinfo:
        get_swagger_versions(settings)
    assert 'pyramid_swagger.swagger_versions is empty' in str(excinfo.value)
Ejemplo n.º 8
0
def test_get_swagger_versions_success():
    for versions in (['1.2'], ['2.0'], ['1.2', '2.0']):
        settings = {'pyramid_swagger.swagger_versions': versions}
        assert versions == get_swagger_versions(settings)
Ejemplo n.º 9
0
def test_get_swagger_versions(ini_app):
    settings = ini_app.app.registry.settings
    swagger_versions = get_swagger_versions(settings)
    assert swagger_versions == {'1.2', '2.0'}
Ejemplo n.º 10
0
def test_get_swagger_versions(ini_app):
    settings = ini_app.app.registry.settings
    swagger_versions = get_swagger_versions(settings)
    assert swagger_versions == {'1.2', '2.0'}