Example #1
0
    def get_schema(self, request=None, public=False):
        """ Generate a OpenAPI schema. """
        reset_generator_stats()
        result = build_root_object(
            paths=self.parse(request, public),
            components=self.registry.build(
                spectacular_settings.APPEND_COMPONENTS),
            version=self.api_version or getattr(request, "version", None),
        )
        for hook in spectacular_settings.POSTPROCESSING_HOOKS:
            result = hook(result=result,
                          generator=self,
                          request=request,
                          public=public)

        # Basically I'm doing it to get pulp logo at redoc page
        result["info"]["x-logo"] = {
            "url":
            "https://pulp.plan.io/attachments/download/517478/pulp_logo_word_rectangle.svg"
        }

        # Adding plugin version config
        result["info"]["x-pulp-app-versions"] = {}
        for app in pulp_plugin_configs():
            result["info"]["x-pulp-app-versions"][app.label] = app.version

        # Adding current host as server (it will provide a default value for the bindings)
        server_url = "http://localhost:24817" if not request else request.build_absolute_uri(
            "/")
        result["servers"] = [{"url": server_url}]

        return normalize_result_object(result)
Example #2
0
    def get_schema(self, request=None, public=False):
        """ Generate a OpenAPI schema. """
        reset_generator_stats()
        result = build_root_object(
            paths=self.parse(request, public),
            components=self.registry.build(spectacular_settings.APPEND_COMPONENTS),
        )
        for hook in spectacular_settings.POSTPROCESSING_HOOKS:
            result = hook(result=result, generator=self, request=request, public=public)

        return sanitize_result_object(normalize_result_object(result))