File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
src/Microsoft.OpenApi/Validations/Rules Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
+ using System ;
4
5
using System . Collections . Generic ;
5
6
using System . Text . RegularExpressions ;
6
7
using Microsoft . OpenApi . Models ;
@@ -35,21 +36,21 @@ public static class OpenApiPathsRules
35
36
}
36
37
} ) ;
37
38
39
+ private static readonly Regex regexPath = new Regex ( "\\ {([^/]+)\\ }" , RegexOptions . Compiled , TimeSpan . FromMilliseconds ( 100 ) ) ;
38
40
/// <summary>
39
41
/// A relative path to an individual endpoint. The field name MUST begin with a slash.
40
42
/// </summary>
41
43
public static ValidationRule < OpenApiPaths > PathMustBeUnique =>
42
44
new ValidationRule < OpenApiPaths > (
43
45
( context , item ) =>
44
46
{
45
- const string regexPath = "\\ {([^/]+)\\ }" ;
46
47
var hashSet = new HashSet < string > ( ) ;
47
48
48
49
foreach ( var path in item . Keys )
49
50
{
50
51
context . Enter ( path ) ;
51
52
52
- var pathSignature = Regex . Replace ( path , regexPath , "{}" ) ;
53
+ var pathSignature = regexPath . Replace ( path , "{}" ) ;
53
54
54
55
if ( ! hashSet . Add ( pathSignature ) )
55
56
context . CreateError ( nameof ( PathMustBeUnique ) ,
You can’t perform that action at this time.
0 commit comments