def render_page(page, info):
    from flask_restful_swagger.registry import get_current_registry

    req_registry = get_current_registry()
    url = req_registry['basePath']
    if url.endswith('/'):
        url = url.rstrip('/')

    st = StorageSingleton()
    templates = st.templates

    conf = {
        'base_url': url + st.api_spec_static,
        'full_base_url': url + st.api_spec_static
    }
    if info is not None:
        conf.update(info)

    if page in templates:
        template = templates[page]
    else:
        with open(os.path.join(root_path, 'static', page), 'r') as fs:
            template = Template(fs.read())
            templates[page] = template

    mime = mimetypes.guess_type(page)[0]
    return Response(template.render(conf), mimetype=mime)
    def get(self, **kwargs):
        req_registry = get_current_registry()

        if not kwargs:
            file_path = "index.html"
        else:
            keys = sorted(kwargs.keys())
            file_path = '/'.join(
                kwargs[k].strip('/') for k in keys if kwargs[k] is not None
            )

        if file_path in [  # TODO: refactor to TemplateResource
            "index.html",
            "o2c.html",
            "swagger-ui.js",
            "swagger-ui.min.js",
            "lib/swagger-oauth.js",
        ]:
            conf = {'resource_list_url': req_registry['spec_endpoint_path']}
            return render_page(file_path, conf)

        mime = mimetypes.guess_type(file_path)[0]

        file_path = os.path.join(root_path, 'static', file_path)
        if os.path.exists(file_path):
            return send_file(file_path, mimetype=mime)
        abort(404)
    def get(self, **kwargs):
        req_registry = get_current_registry()

        if not kwargs:
            file_path = "index.html"
        else:
            keys = sorted(kwargs.keys())
            file_path = '/'.join(kwargs[k].strip('/') for k in keys
                                 if kwargs[k] is not None)

        if file_path in [  # TODO: refactor to TemplateResource
                "index.html",
                "o2c.html",
                "swagger-ui.js",
                "swagger-ui.min.js",
                "lib/swagger-oauth.js",
        ]:
            conf = {'resource_list_url': req_registry['spec_endpoint_path']}
            return render_page(file_path, conf)

        mime = mimetypes.guess_type(file_path)[0]

        file_path = os.path.join(root_path, 'static', file_path)
        if os.path.exists(file_path):
            return send_file(file_path, mimetype=mime)
        abort(404)
def render_page(page, info):
    from flask_restful_swagger.registry import get_current_registry

    req_registry = get_current_registry()
    url = req_registry['basePath']
    if url.endswith('/'):
        url = url.rstrip('/')

    st = StorageSingleton()
    templates = st.templates

    conf = {
        'base_url': url + st.api_spec_static,
        'full_base_url': url + st.api_spec_static
    }
    if info is not None:
        conf.update(info)

    if page in templates:
        template = templates[page]
    else:
        with open(os.path.join(root_path, 'static', page), 'r') as fs:
            template = Template(fs.read())
            templates[page] = template

    mime = mimetypes.guess_type(page)[0]
    return Response(template.render(conf), mimetype=mime)
 def get(self):
     req_registry = get_current_registry()
     if request.path.endswith('.html'):
         return render_homepage(
             req_registry['basePath'] +
             req_registry['spec_endpoint_path'] +
             '/_/resource_list.json'
         )
     return req_registry
def swagger_endpoint(api, resource, path):
    endpoint = SwaggerEndpoint(resource, path)
    req_registry = get_current_registry(api=api)
    req_registry.setdefault('apis', []).append(endpoint.__dict__)

    return SwaggerResourceMeta(
        SwaggerResource.__name__,
        SwaggerResource.__bases__,
        dict(SwaggerResource.__dict__),
        _swagger_endpoint=endpoint,
    )
Exemple #7
0
def swagger_endpoint(api, resource, path):
    endpoint = SwaggerEndpoint(resource, path)
    req_registry = get_current_registry(api=api)
    req_registry.setdefault('apis', []).append(endpoint.__dict__)

    return SwaggerResourceMeta(
        SwaggerResource.__name__,
        SwaggerResource.__bases__,
        dict(SwaggerResource.__dict__),
        _swagger_endpoint=endpoint,
    )
    def get(self):
        req_registry = get_current_registry()
        path = req_registry['basePath'] + req_registry['spec_endpoint_path']

        return {
            "apiVersion": req_registry['apiVersion'],
            "swaggerVersion": req_registry['swaggerVersion'],
            "apis": [{
                "path": path,
                "description": req_registry['description']
            }]
        }