Пример #1
0
        /// <summary>
        /// Returns a value indicating whether the specified action is visible to the API Explorer.
        /// </summary>
        /// <param name="action">The <see cref="ActionDescriptor">action</see> to evaluate.</param>
        /// <returns>True if the <paramref name="action"/> is visible; otherwise, false.</returns>
        protected bool IsVisible(ActionDescriptor action)
        {
            var ignoreApiExplorerSettings = !Options.UseApiExplorerSettings;

            if (ignoreApiExplorerSettings)
            {
                return(true);
            }

            return(action.GetProperty <ApiExplorerModel>()?.IsODataVisible() ??
                   action.GetProperty <ControllerModel>()?.ApiExplorer?.IsODataVisible() ??
                   false);
        }
        /// <summary>
        /// Determines whether the specified action is deprecated for the provided API version.
        /// </summary>
        /// <param name="actionDescriptor">The <see cref="ActionDescriptor">action</see> to evaluate.</param>
        /// <param name="apiVersion">The <see cref="ApiVersion">API version</see> to evaluate.</param>
        /// <returns>True if the specified <paramref name="actionDescriptor">action</paramref> is deprecated for the
        /// <paramref name="apiVersion">API version</paramref>; otherwise, false.</returns>
        public virtual bool IsDeprecated(ActionDescriptor actionDescriptor, ApiVersion apiVersion)
        {
            Arg.NotNull(actionDescriptor, nameof(actionDescriptor));
            Arg.NotNull(apiVersion, nameof(apiVersion));

            var model = actionDescriptor.GetProperty <ApiVersionModel>();

            if (model != null && !model.IsApiVersionNeutral && model.DeprecatedApiVersions.Contains(apiVersion))
            {
                return(true);
            }

            model = actionDescriptor.GetProperty <ControllerModel>()?.GetProperty <ApiVersionModel>();

            return(model != null && !model.IsApiVersionNeutral && model.DeprecatedApiVersions.Contains(apiVersion));
        }
        public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
        {
            if (!routeContext.HttpContext.Items.ContainsKey(JsonRpcConstants.NestedPipelineItemKey))
            {
                return(false);
            }

            var call           = routeContext.HttpContext.GetJsonRpcCall();
            var methodMetadata = action.GetProperty <MethodMetadata>();
            var matcher        = routeContext.HttpContext.RequestServices.GetRequiredService <IMethodMatcher>();

            return(matcher.IsMatch(methodMetadata, call.Method));
        }
        /// <summary>
        /// Determines whether the specified action should be explored for the indicated API version.
        /// </summary>
        /// <param name="actionDescriptor">The <see cref="ActionDescriptor">action</see> to evaluate.</param>
        /// <param name="apiVersion">The <see cref="ApiVersion">API version</see> for action being explored.</param>
        /// <returns>True if the action should be explored; otherwise, false.</returns>
        protected virtual bool ShouldExploreAction(ActionDescriptor actionDescriptor, ApiVersion apiVersion)
        {
            Arg.NotNull(actionDescriptor, nameof(actionDescriptor));
            Arg.NotNull(apiVersion, nameof(actionDescriptor));

            var model = actionDescriptor.GetProperty <ApiVersionModel>();

            if (model != null)
            {
                if (model.IsApiVersionNeutral || model.DeclaredApiVersions.Contains(apiVersion))
                {
                    return(true);
                }

                if (model.DeclaredApiVersions.Count > 0)
                {
                    return(false);
                }
            }

            model = actionDescriptor.GetProperty <ControllerModel>()?.GetProperty <ApiVersionModel>();

            return(model != null && (model.IsApiVersionNeutral || model.DeclaredApiVersions.Contains(apiVersion)));
        }