Path helper for Flask-RESTy views.

        :param view: An `ApiView` object.
341290
def path_helper(self, path, view, **kwargs):
        
        super(FlaskRestyPlugin, self).path_helper(
            path=path,
            view=view,
            **kwargs
        )

        resource = self.get_state().views[view]
        rule = self._rules[resource.rule]

        operations = defaultdict(Operation)
        view_instance = view()
        view_instance.spec_declaration(view, operations, self)

        # add path arguments
        parameters = []
        for arg in rule.arguments:
            parameters.append({
                'name': arg,
                'in': 'path',
                'required': True,
                'type': 'string',
            })
        if parameters:
            operations['parameters'] = parameters

        path.path = FlaskPlugin.flaskpath2openapi(resource.rule)
        path.operations = dict(**operations)
1120132
function(selector, view) {
    // If the `view` argument exists, then a selector was passed in.  This code
    // path will forward the selector on to `setView`.
    if (view) {
      return this.setView(selector, view, true);
    }

    // If no `view` argument is defined, then assume the first argument is the
    // View, somewhat now confusingly named `selector`.
    return this.setView(selector, true);
  }
533215
def add_view(self, view):
        

        self.add_child(view)
        self.views.append(view)
405650
def register_views(self, app):
        

        # Wrap the views in an arbitrary number of decorators.
        def wrap_view(view):
            if self.decorators:
                for decorator in self.decorators:
                    view = decorator(view)
            return view

        if self.config.get('swagger_ui', True):
            uiversion = self.config.get('uiversion', 3)
            blueprint = Blueprint(
                self.config.get('endpoint', 'flasgger'),
                __name__,
                url_prefix=self.config.get('url_prefix', None),
                subdomain=self.config.get('subdomain', None),
                template_folder=self.config.get(
                    'template_folder', 'ui{0}/templates'.format(uiversion)
                ),
                static_folder=self.config.get(
                    'static_folder', 'ui{0}/static'.format(uiversion)
                ),
                static_url_path=self.config.get('static_url_path', None)
            )

            blueprint.add_url_rule(
                self.config.get('specs_route', '/apidocs/'),
                'apidocs',
                view_func=wrap_view(APIDocsView().as_view(
                    'apidocs',
                    view_args=dict(config=self.config)
                ))
            )

            # backwards compatibility with old url style
            blueprint.add_url_rule(
                '/apidocs/index.html',
                view_func=lambda: redirect(url_for('flasgger.apidocs'))
            )
        else:
            blueprint = Blueprint(
                self.config.get('endpoint', 'flasgger'),
                __name__
            )

        for spec in self.config['specs']:
            self.endpoints.append(spec['endpoint'])
            blueprint.add_url_rule(
                spec['route'],
                spec['endpoint'],
                view_func=wrap_view(APISpecsView.as_view(
                    spec['endpoint'],
                    loader=partial(
                        self.get_apispecs, endpoint=spec['endpoint'])
                ))
            )

        app.register_blueprint(blueprint)
1201208
def view(self, *args, **kwargs):
        
        def decorator(f):
            kwargs.setdefault("view_class", self.view_class)
            return self.add_view(as_view(*args, **kwargs)(f))
        return decorator
1247874
def update_view(self, view_id, attributes):
        
        if not isinstance(attributes, dict):
            raise TypeError('Must be of type dict')
        attribute_data = json.dumps(attributes)
        return self.transport.PUT(url='/view/{}'.format(view_id),
                                  body=attribute_data, type='application/json')
1230779
def add_view(self, path: str, handler: AbstractView,
                 **kwargs: Any) -> AbstractRoute:
        
        return self.add_route(hdrs.METH_ANY, path, handler, **kwargs)
1265454
def _api_all_views(self):
        
        response.content_type = 'application/json; charset=utf-8'

        try:
            # Get the JSON value of the stat view
            limits = json.dumps(self.stats.getAllViewsAsDict())
        except Exception as e:
            abort(404, "Cannot get views (%s)" % (str(e)))
        return limits
72957
def find_route_by_view_name(self, view_name):
        
        if not view_name:
            return (None, None)

        for uri, route in self.routes_all.items():
            if route.name == view_name:
                return uri, route

        return (None, None)
1365823
def process_view(self, request, view_func, view_args, view_kwargs):
        
        try:
            if ignore_path(request.path):
                TrackedRequest.instance().tag("ignore_transaction", True)

            view_name = request.resolver_match._func_path
            span = TrackedRequest.instance().current_span()
            if span is not None:
                span.operation = "Controller/" + view_name
                Context.add("path", request.path)
                Context.add("user_ip", RemoteIp.lookup_from_headers(request.META))
                if getattr(request, "user", None) is not None:
                    Context.add("username", request.user.get_username())
        except Exception:
            pass
1040174
def route(view, endpoint=None, methods=None, defaults=None, **options):
    
    if not endpoint:
        endpoint = view
    if not methods:
        methods = ['GET']
    return dict(
        view_func=LazyView(view),
        endpoint=endpoint,
        methods=methods,
        defaults=defaults,
        **options
    )
1290665
def build_swagger_12_api_declaration_view(api_declaration_json):
    
    def view_for_api_declaration(request):
        # Note that we rewrite basePath to always point at this server's root.
        return dict(
            api_declaration_json,
            basePath=str(request.application_url),
        )
    return view_for_api_declaration
391543
def route(self, url_rule, name=None, options=None):
        ''''''
        # TODO: change options kwarg to defaults
        def decorator(f):
            view_name = name or f.__name__
            self.add_url_rule(url_rule, f, name=view_name, options=options)
            return f
        return decorator
460398
def redirect(view=None, url=None, **kwargs):
    
    if view:
        if url:
            kwargs["url"] = url
        url = flask.url_for(view, **kwargs)
    current_context.exit(flask.redirect(url))
131203
def _add_url_route(self, endpoint, rule, view_func, method):
        
        if self.api_prefix:
            rule = self.api_prefix + rule

        if self.endpoint_prefix:
            endpoint = self.endpoint_prefix + endpoint

        self.app.add_url_rule(
            rule,
            endpoint,
            self._apply_auth(view_func),
            methods=[method]
        )
793708
def get_request_from_view_args(self, view, args, kwargs):
        
        if len(args) > 1 and isinstance(args[1], sanic.request.Request):
            req = args[1]
        else:
            req = args[0]
        assert isinstance(
            req, sanic.request.Request
        ), "Request argument not found for handler"
        return req
823268
def url_for(obj, **kw):
    
    if isinstance(obj, str):
        return flask_url_for(obj, **kw)

    try:
        return current_app.default_view.url_for(obj, **kw)
    except KeyError:
        if hasattr(obj, "_url"):
            return obj._url
        elif hasattr(obj, "url"):
            return obj.url

    raise BuildError(repr(obj), kw, "GET")