Exemple #1
0
def get_api_def(spec_path, api_slug=None, extra_fields={}, template_path=None):
    """
    Instantiate an ApiDef instance only if we haven't done so already. This
    saves the trouble of fetching & parsing API specs more than once.
    """
    if spec_path in cached_openapi_specs.keys():
        return cached_openapi_specs[spec_path]

    apidef = ApiDef(spec_path,
                    api_slug=api_slug,
                    extra_fields=extra_fields,
                    template_path=template_path)
    cached_openapi_specs[spec_path] = apidef
    return apidef
Exemple #2
0
    def from_openapi(self, spec_path):
        """
        Create a target from an API spec path.
        """

        openapi = ApiDef.from_path(spec_path)
        t = {
            "name": openapi.api_slug,
            "display_name": openapi.api_title,
        }

        self.config["pages"] = [{
            "openapi_specification": spec_path,
            "api_slug": openapi.api_slug,
            "targets": [openapi.api_slug],
        }]
        self.data = t
        openapi.add_metadata(self.data)
        self.config["targets"].append(t)
Exemple #3
0
    def expand_openapi_spec(self, page_data):
        """Expand OpenAPI Spec placeholders into a full page list"""
        assert OPENAPI_SPEC_KEY in page_data.keys()

        logger.debug("Expanding OpenAPI spec from placeholder: %s" % page_data)
        api_slug = page_data.get(API_SLUG_KEY, None)
        extra_fields = {}
        merge_dicts(self.data, extra_fields, RESERVED_KEYS_TARGET)
        merge_dicts(page_data, extra_fields, [OPENAPI_SPEC_KEY, API_SLUG_KEY])

        template_path = page_data.get(OPENAPI_TEMPLATE_PATH_KEY, None)
        swagger = ApiDef.from_path(page_data[OPENAPI_SPEC_KEY], api_slug,
                                   extra_fields, template_path)
        skip_pp = self.config.get("skip_preprocessor", False)
        made_pages = []
        for p in swagger.create_pagelist():
            more_filters = self.data.get("filters", [])
            po = DactylPage(self.config, p, skip_pp, more_filters)
            # Special case for filters; concatenate filter lists,
            # with target's filters first.
            if "filters" in self.data:
                po.gain_filters(self.data["filters"])
            made_pages.append(po)
        return made_pages