This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathFilterSet.cs
129 lines (111 loc) · 4.77 KB
/
FilterSet.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.Collections;
using System.Collections.Generic;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters;
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
{
/// <summary>
/// The filter set that will be used while generating OpenAPI specification document.
/// </summary>
public sealed class FilterSet : IEnumerable<IFilter>
{
private IList<IFilter> _filters = new List<IFilter>();
private static FilterSet _defaultFilterSet;
/// <summary>
/// Initializes a new instance of the <see cref="FilterSet"/> class.
/// </summary>
public FilterSet()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FilterSet"/> class.
/// </summary>
/// <param name="filterSet">Filter set to be copied from.</param>
public FilterSet(FilterSet filterSet)
{
if (filterSet == null)
{
return;
}
// We create a new instance of FilterSet per call as a safeguard
// against unintentional modification of the private _defaultFilterSet.
foreach (IFilter filter in filterSet)
{
Add(filter);
}
}
/// <summary>
/// Add the new filter into the filter set.
/// </summary>
/// <param name="filter">The filter.</param>
public void Add(IFilter filter)
{
_filters.Add(filter);
}
/// <summary>
/// Gets the default filter sets.
/// </summary>
public static FilterSet GetDefaultFilterSet(FilterSetVersion version)
{
if (_defaultFilterSet == null)
{
_defaultFilterSet = new FilterSet();
switch(version)
{
case FilterSetVersion.V1:
//Document config filters
_defaultFilterSet.Add(new DocumentVariantAttributesFilter());
//Document filters
_defaultFilterSet.Add(new AssemblyNameToInfoFilter());
_defaultFilterSet.Add(new UrlToServerFilter());
_defaultFilterSet.Add(new MemberSummaryToSchemaDescriptionFilter());
//Operation config filters
_defaultFilterSet.Add(new CommonAnnotationFilter());
//Operation filters
_defaultFilterSet.Add(new GroupToTagFilter());
_defaultFilterSet.Add(new ParamToParameterFilter());
_defaultFilterSet.Add(new ParamToRequestBodyFilter());
_defaultFilterSet.Add(new RemarksToDescriptionFilter());
_defaultFilterSet.Add(new ResponseToResponseFilter());
_defaultFilterSet.Add(new SummaryToSummaryFilter());
//Pre processing operation filters
_defaultFilterSet.Add(new ConvertAlternativeParamTagsFilter());
_defaultFilterSet.Add(new PopulateInAttributeFilter());
_defaultFilterSet.Add(new BranchOptionalPathParametersFilter());
//Post processing document filters
_defaultFilterSet.Add(new RemoveFailedGenerationOperationFilter());
return _defaultFilterSet;
default:
throw new FilterSetVersionNotSupportedException(version.ToString());
}
}
return new FilterSet(_defaultFilterSet);
}
/// <summary>
/// Get the enumerator.
/// </summary>
/// <returns>The enumerator.</returns>
public IEnumerator<IFilter> GetEnumerator()
{
foreach (var filter in _filters)
{
yield return filter;
}
}
/// <summary>
/// Get the enumerator.
/// </summary>
/// <returns>The enumerator.</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}