How to use the apispec.APISpec function in apispec

To help you get started, we’ve selected a few apispec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marshmallow-code / apispec / tests / test_ext_marshmallow_openapi.py View on Github external
def test_openapi_tools_validate_v2():
    ma_plugin = MarshmallowPlugin()
    spec = APISpec(
        title="Pets", version="0.1", plugins=(ma_plugin,), openapi_version="2.0"
    )
    openapi = ma_plugin.converter

    spec.components.schema("Category", schema=CategorySchema)
    spec.components.schema("Pet", {"discriminator": "name"}, schema=PetSchema)

    spec.path(
        view=None,
        path="/category/{category_id}",
        operations={
            "get": {
                "parameters": [
                    {"name": "q", "in": "query", "type": "string"},
                    {
                        "name": "category_id",
github 4Catalyzer / flask-resty / tests / test_swagger.py View on Github external
def test_definition_autogeneration(views):
    spec = APISpec(
        title='test api',
        version='0.1.0',
        plugins=(FlaskRestyPlugin(),),
    )

    spec.add_path(view=views['foo_list'])

    assert 'FooSchema' in spec.to_dict()['definitions']
github marshmallow-code / apispec / tests / test_ext_marshmallow.py View on Github external
def test_schema_uses_ref_if_available_name_resolver_returns_none_v2(self):
        def resolver(schema):
            return None

        spec = APISpec(
            title="Test auto-reference",
            version="0.1",
            openapi_version="2.0",
            plugins=(MarshmallowPlugin(schema_name_resolver=resolver),),
        )
        spec.components.schema("Pet", schema=PetSchema)
        spec.path(
            path="/pet", operations={"get": {"responses": {200: {"schema": PetSchema}}}}
        )
        get = get_paths(spec)["/pet"]["get"]
        assert get["responses"]["200"]["schema"] == build_ref(spec, "schema", "Pet")
github marshmallow-code / apispec / tests / test_ext_combination.py View on Github external
def check_web_framework_and_marshmallow_plugin(web_framework_plugin, **kwargs_for_add_path):
    """Check schemas passed in web framework view function docstring are parsed by MarshmallowPlugin"""
    spec = APISpec(
        title='Swagger Petstore',
        version='1.0.0',
        plugins=[web_framework_plugin(), MarshmallowPlugin()],
        openapi_version='2.0',
    )
    spec.add_path(**kwargs_for_add_path)
    expected = {
        'type': 'object',
        'properties': {
            'id': {'type': 'integer', 'format': 'int32', 'description': 'Pet id', 'readOnly': True},
            'name': {'type': 'string', 'description': 'Pet name'},
        },
        'required': ['name'],
    }
    assert spec.to_dict()['paths']['/hello']['get']['responses'][200]['schema'] == expected
github alysivji / falcon-batteries-included / app / __init__.py View on Github external
# Authentication
from .utilities import user_loader  # noqa

auth_backend = JWTAuthBackend(user_loader, secret_key=SECRET_KEY)
auth_middleware = FalconAuthMiddleware(auth_backend, exempt_routes=["/swagger"])

# Falcon
app_middleware = [
    auth_middleware,
    SQLAlchemySessionManager(db),
    SerializationMiddleware(),
]
api = falcon.API(middleware=app_middleware)

# Documentation
spec = APISpec(
    title="Movie Recommendation",
    version="0.0.1",
    openapi_version="2.0",
    info=dict(description="An example project API"),
    plugins=[FalconPlugin(api), MarshmallowPlugin()],
)

from . import routes  # noqa
from . import apispec  # noqa
github beer-garden / beer-garden / src / app / beer_garden / api / http / __init__.py View on Github external
def _load_swagger(url_specs, title=None):

    global api_spec
    api_spec = APISpec(
        title=title,
        version="1.0",
        plugins=("apispec.ext.marshmallow", "apispec.ext.tornado"),
    )

    # Schemas from Marshmallow
    api_spec.definition("Parameter", schema=ParameterSchema)
    api_spec.definition("Command", schema=CommandSchema)
    api_spec.definition("Instance", schema=InstanceSchema)
    api_spec.definition("Request", schema=RequestSchema)
    api_spec.definition("System", schema=SystemSchema)
    api_spec.definition("LoggingConfig", schema=LoggingConfigSchema)
    api_spec.definition("Event", schema=EventSchema)
    api_spec.definition("User", schema=PrincipalSchema)
    api_spec.definition("Role", schema=RoleSchema)
    api_spec.definition("Queue", schema=QueueSchema)
github Channelstream / channelstream / channelstream / wsgi_views / server.py View on Github external
tags:
          - "OpenApi 2.0 spec"
          summary: "Return openapi spec
          purposes"
          description: ""
          operationId: "api_spec"
          consumes:
          - "application/json"
          produces:
          - "application/json"
          parameters:
          responses:
            200:
              description: "Success"
        """
        spec = APISpec(
            title="Channelstream API",
            version="0.7.0",
            openapi_version="2.0.0",
            plugins=(MarshmallowPlugin(),),
        )
        spec.components.schema("ConnectBody", schema=schemas.ConnectBodySchema)
        spec.components.schema("SubscribeBody", schema=schemas.SubscribeBodySchema)
        spec.components.schema("UnsubscribeBody", schema=schemas.UnsubscribeBodySchema)
        spec.components.schema("UserStateBody", schema=schemas.UserStateBodySchema)
        spec.components.schema(
            "MessagesBody", schema=schemas.MessageBodySchema(many=True)
        )
        spec.components.schema("MessageBody", schema=schemas.MessageBodySchema())
        spec.components.schema(
            "MessageEditBody", schema=schemas.MessageEditBodySchema(many=True)
        )
github tribe29 / checkmk / cmk / gui / plugins / openapi / restful_objects / specification.py View on Github external
},
        {
            'name': 'Request Schemas',
            'tags': []
        },
    ],
    'x-ignoredHeaderParameters': [
        'User-Agent',
        'X-Test-Header',
    ],
    'security': [{
        'BearerAuth': []
    }]
}

SPEC = apispec.APISpec("Checkmk REST API",
                       "0.3.2",
                       apispec.utils.OpenAPIVersion("3.0.2"),
                       plugins=[
                           plugins.ValueTypedDictMarshmallowPlugin(),
                           apispec_oneofschema.MarshmallowPlugin(),
                       ],
                       **OPTIONS)
SPEC.components.security_scheme(
    'BearerAuth',
    {
        'type': 'http',
        'scheme': 'bearer',
        'in': 'header',
        'description': 'The format of the header-value is "Bearer $automation_user '
                       '$automation_user_password"\n\nExample: `Bearer hansdampf miezekatze123`',
        'bearerFormat': 'username password',
github algoo / hapic / hapic / doc / main.py View on Github external
Generate an OpenApi 2.0 documentation. Th given context will be used
        to found controllers matching with given DecoratedController.
        :param controllers: List of DecoratedController to match with context
        controllers
        :param context: a context instance
        :param title: The generated doc title
        :param description: The generated doc description
        :param wildcard_method_replacement: If wild card found as method in
        operations consider these given methods as replacement. If not provided
        all OpenAPI v2 valid methods will be used.
        :return: a apispec documentation dict
        """
        main_plugin = hapic.processor_class.create_apispec_plugin()

        plugins = (main_plugin,)
        spec = APISpec(
            title=title,
            info=dict(description=description),
            version=version,
            plugins=plugins,
            openapi_version="2.0",
        )

        schema_usages = []  # type: typing.List[SchemaUsage]
        # Parse used schema and pre-index them into apispec plugin
        for controller in controllers:
            description = controller.description

            for description_item in [
                description.input_body,
                description.input_path,
                description.input_query,
github jmcarp / flask-apispec / flask_apispec / extension.py View on Github external
def make_apispec(title='flask-apispec', version='v1'):
    return APISpec(
        title=title,
        version=version,
        plugins=[MarshmallowPlugin()],
    )