def get_schema(self, request=None, public=False): """ allow CORS in Google Cloud Endpoint """ endpoints = self.get_endpoints(request) components = ReferenceResolver(openapi.SCHEMA_DEFINITIONS, force_init=True) extra = dict(components) extra['x-google-endpoints'] = [ {'name': f"\"{os.environ.get('OPENAPI_HOST')}\"", 'allowCors': True} ] extra['x-google-allow'] = 'all' self.consumes = get_consumes(api_settings.DEFAULT_PARSER_CLASSES) self.produces = get_produces(api_settings.DEFAULT_RENDERER_CLASSES) paths, prefix = self.get_paths(endpoints, components, request, public) security_definitions = self.get_security_definitions() if security_definitions: security_requirements = self.get_security_requirements( security_definitions) else: security_requirements = None url = self.url if url is None and request is not None: url = request.build_absolute_uri() return openapi.Swagger( info=self.info, paths=paths, consumes=self.consumes or None, produces=self.produces or None, security_definitions=security_definitions, security=security_requirements, _url=url, _prefix=prefix, _version=self.version, **extra,)
def get_schema(self, request=None, public=False): """ Rewrite parent class to add 'responses' in components """ endpoints = self.get_endpoints(request) components = self.reference_resolver_class( openapi.SCHEMA_DEFINITIONS, "responses", force_init=True ) self.consumes = get_consumes(api_settings.DEFAULT_PARSER_CLASSES) self.produces = get_produces(api_settings.DEFAULT_RENDERER_CLASSES) paths, prefix = self.get_paths(endpoints, components, request, public) security_definitions = self.get_security_definitions() if security_definitions: security_requirements = self.get_security_requirements(security_definitions) else: security_requirements = None url = self.url if url is None and request is not None: url = request.build_absolute_uri() return openapi.Swagger( info=self.info, paths=paths, consumes=self.consumes or None, produces=self.produces or None, security_definitions=security_definitions, security=security_requirements, _url=url, _prefix=prefix, _version=self.version, **dict(components), )
def get_schema(self, request=None, public=False): """Generate a :class:`.Swagger` object representing the API schema. :param request: the request used for filtering accessible endpoints and finding the spec URI :type request: rest_framework.request.Request or None :param bool public: if True, all endpoints are included regardless of access through `request` :return: the generated Swagger specification :rtype: openapi.Swagger """ endpoints = self.get_endpoints(request) components = ReferenceResolver(openapi.SCHEMA_DEFINITIONS, force_init=True) self.consumes = get_consumes(api_settings.DEFAULT_PARSER_CLASSES) self.produces = get_produces(api_settings.DEFAULT_RENDERER_CLASSES) paths, prefix = self.get_paths(endpoints, components, request, public) security_definitions = self.get_security_definitions(endpoints) security_requirements = [] url = self.url if url is None and request is not None: url = request.build_absolute_uri() return openapi.Swagger(info=self.info, paths=paths, consumes=self.consumes or None, produces=self.produces or None, security_definitions=security_definitions, security=security_requirements, _url=url, _prefix=prefix, _version=self.version, **dict(components))
def get_schema(self, request=None, public=False): schema_urls = utils.get_swagger_urls() config_aggregator = { 'info': { 'title': 'API Gateway', 'description': '', 'version': '1.0' }, 'apis': schema_urls, 'produces': [ 'application/json', 'application/x-www-form-urlencoded', 'multipart/form-data' ], 'consumes': [ 'application/json', 'application/x-www-form-urlencoded', 'multipart/form-data' ], } sw_aggregator = SwaggerAggregator(config_aggregator) swagger_spec = sw_aggregator.generate_swagger() endpoints = self.get_endpoints(request) components = openapi.ReferenceResolver(openapi.SCHEMA_DEFINITIONS) paths, prefix = self.get_paths(endpoints, components, request, public) paths.update(swagger_spec['paths']) components['definitions'].update(swagger_spec['definitions']) url = self.url if url is None and request is not None: url = request.build_absolute_uri() return openapi.Swagger(info=self.info, paths=paths, consumes=swagger_spec['consumes'], produces=swagger_spec['produces'], security_definitions=swagger_spec.get( 'security_definitions', None), security=swagger_spec.get('security', None), _url=url, _version=self.version, _prefix=prefix, **dict(components))