How to use the apispec.core.VALID_METHODS_OPENAPI_V2 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 algoo / hapic / tests / ext / unit / test_aiohttp.py View on Github external
        @hapic.with_api_doc()
        async def a_proxy(request):
            pass

        app = web.Application(debug=True)
        app.router.add_route(hdrs.METH_ANY, path="/", handler=a_proxy)
        hapic.set_context(
            AiohttpContext(app, default_error_builder=MarshmallowDefaultErrorBuilder())
        )

        doc = hapic.generate_doc("aiohttp", "testing")
        # INFO BS 2019-04-15: Prevent keep of OrderedDict
        doc = json.loads(json.dumps(doc))

        assert len(VALID_METHODS_OPENAPI_V2) == len(doc["paths"]["/"])
        for method in VALID_METHODS_OPENAPI_V2:
            assert method in doc["paths"]["/"]
github maximdanilchenko / aiohttp-apispec / aiohttp_apispec / aiohttp_apispec.py View on Github external
def _update_paths(self, data: dict, method: str, url_path: str):
        if method not in VALID_METHODS_OPENAPI_V2:
            return None
        for schema in data.pop("schemas", []):
            parameters = self.plugin.converter.schema2parameters(
                schema["schema"], **schema["options"]
            )
            data["parameters"].extend(parameters)

        existing = [p["name"] for p in data["parameters"] if p["in"] == "path"]
        data["parameters"].extend(
            {"in": "path", "name": path_key, "required": True, "type": "string"}
            for path_key in get_path_keys(url_path)
            if path_key not in existing
        )

        if "responses" in data:
            responses = {}
github Tribler / py-ipv8 / ipv8 / REST / rest_manager.py View on Github external
aiohttp_apispec = AiohttpApiSpec(
            app=self.root_endpoint.app,
            title="IPv8 REST API documentation",
            version="v2.2",  # Do not change manually! Handled by github_increment_version.py
            url="/docs/swagger.json",
            swagger_path="/docs",
        )
        if api_key:
            # Set security scheme and apply to all endpoints
            aiohttp_apispec.spec.options['security'] = [{'apiKey': []}]
            aiohttp_apispec.spec.components.security_scheme('apiKey', {'type': 'apiKey',
                                                                       'in': 'header',
                                                                       'name': 'X-Api-Key'})

        from apispec.core import VALID_METHODS_OPENAPI_V2
        if 'head' in VALID_METHODS_OPENAPI_V2:
            VALID_METHODS_OPENAPI_V2.remove('head')

        runner = web.AppRunner(self.root_endpoint.app, access_log=None)
        await runner.setup()
        # If localhost is used as hostname, it will randomly either use 127.0.0.1 or ::1
        self.site = web.TCPSite(runner, host, port, ssl_context=ssl_context)
        await self.site.start()
github Tribler / py-ipv8 / ipv8 / REST / rest_manager.py View on Github external
app=self.root_endpoint.app,
            title="IPv8 REST API documentation",
            version="v2.2",  # Do not change manually! Handled by github_increment_version.py
            url="/docs/swagger.json",
            swagger_path="/docs",
        )
        if api_key:
            # Set security scheme and apply to all endpoints
            aiohttp_apispec.spec.options['security'] = [{'apiKey': []}]
            aiohttp_apispec.spec.components.security_scheme('apiKey', {'type': 'apiKey',
                                                                       'in': 'header',
                                                                       'name': 'X-Api-Key'})

        from apispec.core import VALID_METHODS_OPENAPI_V2
        if 'head' in VALID_METHODS_OPENAPI_V2:
            VALID_METHODS_OPENAPI_V2.remove('head')

        runner = web.AppRunner(self.root_endpoint.app, access_log=None)
        await runner.setup()
        # If localhost is used as hostname, it will randomly either use 127.0.0.1 or ::1
        self.site = web.TCPSite(runner, host, port, ssl_context=ssl_context)
        await self.site.start()