9
9
10
10
namespace ApiGenerator . Domain . Specification
11
11
{
12
-
13
12
// ReSharper disable once ClassNeverInstantiated.Global
14
13
public class UrlInformation
15
14
{
16
- public IDictionary < string , QueryParameters > Params { get ; set ; } = new SortedDictionary < string , QueryParameters > ( ) ;
15
+ private static readonly string [ ] DocumentApiParts = { "index" , "id" } ;
17
16
18
- [ JsonProperty ( "paths" ) ]
19
- private IReadOnlyCollection < string > OriginalPaths { get ; set ; }
17
+ private List < UrlPath > _paths ;
18
+
19
+ private List < UrlPath > _pathsWithDeprecation ;
20
+
21
+ public bool IsDocumentApi => IsADocumentRoute ( Parts ) ;
22
+
23
+ public bool IsPartless => ! Parts . Any ( ) ;
20
24
21
25
[ JsonProperty ( "parts" ) ]
22
26
public IDictionary < string , UrlPart > OriginalParts { get ; set ; }
23
27
24
- [ JsonProperty ( "deprecated_paths" ) ]
25
- private IReadOnlyCollection < DeprecatedPath > DeprecatedPaths { get ; set ; }
28
+ public IDictionary < string , QueryParameters > Params { get ; set ; } = new SortedDictionary < string , QueryParameters > ( ) ;
29
+
30
+ // Include deprecated paths to ensure these are not removed (a breaking change) during 7.x releases.
31
+ // For historical reasons, constructors for deprecated paths which specified a type where removed in 7.0 and
32
+ // therefore we don't include those in generation to avoid them being re-added.
33
+ public IReadOnlyCollection < UrlPart > Parts => Paths . Union ( PathsWithDeprecations . Where ( x => x . Parts . All ( p => p . Name != "type" ) ) )
34
+ . SelectMany ( p => p . Parts )
35
+ . DistinctBy ( p => p . Name )
36
+ . ToList ( ) ;
26
37
27
- private List < UrlPath > _paths ;
28
38
public IReadOnlyCollection < UrlPath > Paths
29
39
{
30
40
get
@@ -36,14 +46,13 @@ public IReadOnlyCollection<UrlPath> Paths
36
46
}
37
47
}
38
48
39
- private List < UrlPath > _pathsWithDeprecation ;
40
49
public IReadOnlyCollection < UrlPath > PathsWithDeprecations
41
50
{
42
51
get
43
52
{
44
53
if ( _pathsWithDeprecation != null && _pathsWithDeprecation . Count > 0 ) return _pathsWithDeprecation ;
45
54
46
- var paths = Paths ?? new UrlPath [ ] { } ;
55
+ var paths = Paths ?? new UrlPath [ ] { } ;
47
56
if ( DeprecatedPaths == null || DeprecatedPaths . Count == 0 ) return Paths ;
48
57
if ( OriginalParts == null ) return Paths ;
49
58
@@ -58,8 +67,7 @@ public IReadOnlyCollection<UrlPath> PathsWithDeprecations
58
67
var withoutDeprecatedAliases = DeprecatedPaths
59
68
. Select ( deprecatedPath => new
60
69
{
61
- deprecatedPath ,
62
- parts = new HashSet < string > ( OriginalParts . Keys . Where ( k => deprecatedPath . Path . Contains ( $ "{{{k}}}") ) )
70
+ deprecatedPath , parts = new HashSet < string > ( OriginalParts . Keys . Where ( k => deprecatedPath . Path . Contains ( $ "{{{k}}}") ) )
63
71
} )
64
72
. GroupBy ( t => t . parts , HashSet < string > . CreateSetComparer ( ) )
65
73
. Where ( grouped => ! canonicalPartNameLookup . Any ( set => set . SetEquals ( grouped . Key ) ) )
@@ -74,32 +82,23 @@ public IReadOnlyCollection<UrlPath> PathsWithDeprecations
74
82
var finalPathsWithDeprecations = new List < UrlPath > ( _pathsWithDeprecation . Count ) ;
75
83
76
84
foreach ( var path in _pathsWithDeprecation )
77
- {
78
85
if ( path . Deprecation is null &&
79
86
DeprecatedPaths . SingleOrDefault ( p => p . Path . Equals ( path . Path , StringComparison . OrdinalIgnoreCase ) ) is { } match )
80
- {
81
87
finalPathsWithDeprecations . Add ( new UrlPath ( match , OriginalParts , Paths ) ) ;
82
- }
83
88
else
84
- {
85
89
finalPathsWithDeprecations . Add ( path ) ;
86
- }
87
- }
88
90
89
91
_pathsWithDeprecation = finalPathsWithDeprecations ;
90
92
91
93
return _pathsWithDeprecation ;
92
94
}
93
95
}
94
96
97
+ [ JsonProperty ( "deprecated_paths" ) ]
98
+ private IReadOnlyCollection < DeprecatedPath > DeprecatedPaths { get ; set ; }
95
99
96
- public IReadOnlyCollection < UrlPart > Parts => Paths . SelectMany ( p => p . Parts ) . DistinctBy ( p => p . Name ) . ToList ( ) ;
97
-
98
- public bool IsPartless => ! Parts . Any ( ) ;
99
-
100
- private static readonly string [ ] DocumentApiParts = { "index" , "id" } ;
101
-
102
- public bool IsDocumentApi => IsADocumentRoute ( Parts ) ;
100
+ [ JsonProperty ( "paths" ) ]
101
+ private IReadOnlyCollection < string > OriginalPaths { get ; set ; }
103
102
104
103
public static bool IsADocumentRoute ( IReadOnlyCollection < UrlPart > parts ) =>
105
104
parts . Count ( ) == DocumentApiParts . Length
@@ -115,6 +114,5 @@ public bool TryGetDocumentApiPath(out UrlPath path)
115
114
path = new UrlPath ( mostVerbosePath . Path , OriginalParts , mostVerbosePath . Parts ) ;
116
115
return true ;
117
116
}
118
-
119
117
}
120
118
}
0 commit comments