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): """ 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): """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_request_content_type_header(self) -> Optional[openapi.Parameter]: if self.method not in ["POST", "PUT", "PATCH"]: return None consumes = get_consumes(self.get_parser_classes()) return openapi.Parameter( name="Content-Type", in_=openapi.IN_HEADER, type=openapi.TYPE_STRING, required=True, enum=consumes, description=_("Content type of the request body."), )
def get_consumes(self): """Return the MIME types this endpoint can consume. :rtype: list[str] """ return get_consumes(self.view.get_parsers())