-
Notifications
You must be signed in to change notification settings - Fork 9.9k
/
ApiVisibilityConvention.cs
35 lines (31 loc) · 1.27 KB
/
ApiVisibilityConvention.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.AspNetCore.Mvc.ApplicationModels;
/// <summary>
/// A <see cref="IActionModelConvention"/> that sets Api Explorer visibility.
/// </summary>
public class ApiVisibilityConvention : IActionModelConvention
{
/// <inheritdoc />
public void Apply(ActionModel action)
{
if (!ShouldApply(action))
{
return;
}
if (action.Controller.ApiExplorer.IsVisible == null && action.ApiExplorer.IsVisible == null)
{
// Enable ApiExplorer for the action if it wasn't already explicitly configured.
action.ApiExplorer.IsVisible = true;
}
}
/// <summary>
/// Determines if this instance of <see cref="IActionModelConvention"/> applies to a specified <paramref name="action"/>.
/// </summary>
/// <param name="action">The <see cref="ActionModel"/>.</param>
/// <returns>
/// <see langword="true"/> if the convention applies, otherwise <see langword="false"/>.
/// Derived types may override this method to selectively apply this convention.
/// </returns>
protected virtual bool ShouldApply(ActionModel action) => true;
}