質問

You can decorate a controller or action method with the ApiExplorerSettingsAttribute setting the IgnoreApi property to NOT generate help info. If you try to apply the same to an action method's attribute, you get an error:

public HttpResponseMessage Post([ApiExplorerSettings(IgnoreApi = true)]HttpRequestMessage request, ... )

Error 2 Attribute 'ApiExplorerSettings' is not valid on this declaration type. It is only valid on 'class, method' declarations.

A common convention for keeping your controller actions testable is to accept an HttpRequestMessage parameter, but this is an implementation detail, not something your API consumers should know about.

How can I prevent the ApiExplorer from including this parameter when it generates the help page?

役に立ちましたか?

解決

For clarity...by this "if you try to apply the same to an action method's attribute", did you mean you were trying to apply to the parameter?

-A quick fix would be is to add an additional check to the existing CancellationToken check that we have in this file: \Areas\HelpPage\Views\Help\DisplayTemplates\Parameters.cshtml

// Don't show CancellationToken because it's a special parameter
    if (!typeof(CancellationToken).IsAssignableFrom(parameter.ParameterDescriptor.ParameterType))
    {

-Also, you could avoid having HttpRequestMessage as a parameter on action as you can get the current request from the Request property on the controller, but you wanted it as a parameter for testing...is it?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top