|
6 | 6 | namespace JsonApiDotNetCore.OpenApi.Swashbuckle.SwaggerComponents; |
7 | 7 |
|
8 | 8 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] |
| 9 | +#if NET6_0 |
9 | 10 | internal sealed class EndpointOrderingFilter : IDocumentFilter |
| 11 | +#else |
| 12 | +internal sealed partial class EndpointOrderingFilter : IDocumentFilter |
| 13 | +#endif |
10 | 14 | { |
11 | | - private static readonly Regex RelationshipNameInUrlPattern = |
12 | | - new($@".*{JsonApiRoutingTemplate.PrimaryEndpoint}/(?>{JsonApiRoutingTemplate.RelationshipsPart}\/)?(\w+)", RegexOptions.Compiled); |
| 15 | + private const string PatternText = $@".*{JsonApiRoutingTemplate.PrimaryEndpoint}/(?>{JsonApiRoutingTemplate.RelationshipsPart}\/)?(?<RelationshipName>\w+)"; |
| 16 | + |
| 17 | +#if NET6_0 |
| 18 | + private const RegexOptions RegexOptionsNet60 = RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture; |
| 19 | + private static readonly Regex RelationshipNameInUrlPattern = new(PatternText, RegexOptionsNet60); |
| 20 | +#endif |
13 | 21 |
|
14 | 22 | public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) |
15 | 23 | { |
@@ -39,8 +47,18 @@ private static bool IsSecondaryEndpoint(KeyValuePair<string, OpenApiPathItem> en |
39 | 47 |
|
40 | 48 | private static string GetRelationshipName(KeyValuePair<string, OpenApiPathItem> entry) |
41 | 49 | { |
42 | | - Match match = RelationshipNameInUrlPattern.Match(entry.Key); |
| 50 | + Match match = RelationshipNameInUrlRegex().Match(entry.Key); |
| 51 | + |
| 52 | + return match.Success ? match.Groups["RelationshipName"].Value : string.Empty; |
| 53 | + } |
43 | 54 |
|
44 | | - return match.Success ? match.Groups[1].Value : string.Empty; |
| 55 | +#if NET6_0 |
| 56 | + private static Regex RelationshipNameInUrlRegex() |
| 57 | + { |
| 58 | + return RelationshipNameInUrlPattern; |
45 | 59 | } |
| 60 | +#else |
| 61 | + [GeneratedRegex(PatternText, RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture)] |
| 62 | + private static partial Regex RelationshipNameInUrlRegex(); |
| 63 | +#endif |
46 | 64 | } |
0 commit comments