You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
More thorough support for retrieving OpenAPI routes in a case-sensitive manner (#59568)
* When retrieving optione, use the lowercase document name, too
* Added tests for checking if options monitor uses case-insensitive document name for OpenAPI version retrieval
* Add XML comments to prevent bugs in the future
* Improve comments on existing test
* Add new tests for DocumentProvider which should also work case-insensitively
* Fix build by adding necessary XML comment
* Fix build of tests
* Improve comments
* Fix incorrect tests
* Fix bugs around case-sensitive document names
* Implemented PR comments
// We need to retrieve the document name in a case-insensitive manner
34
-
// to support case-insensitive document name resolution.
35
-
// Keyed Services are case-sensitive by default, which doesn't work well for document names in ASP.NET Core
36
-
// as routing in ASP.NET Core is case-insensitive by default.
33
+
// We need to retrieve the document name in a case-insensitive manner to support case-insensitive document name resolution.
34
+
// The document service is registered with a key equal to the document name, but in lowercase.
35
+
// The GetRequiredKeyedService() method is case-sensitive, which doesn't work well for OpenAPI document names here,
36
+
// as the document name is also used as the route to retrieve the document, so we need to ensure this is lowercased to achieve consistency with ASP.NET Core routing.
37
+
// The same goes for the document options below, which is also case-sensitive, and thus we need to pass in a case-insensitive document name.
38
+
// See OpenApiServiceCollectionExtensions.cs for more info.
// We need to retrieve the document name in a case-insensitive manner to support case-insensitive document name resolution.
47
+
// The document service is registered with a key equal to the document name, but in lowercase.
48
+
// The GetRequiredKeyedService() method is case-sensitive, which doesn't work well for OpenAPI document names here,
49
+
// as the document name is also used as the route to retrieve the document, so we need to ensure this is lowercased to achieve consistency with ASP.NET Core routing.
50
+
// See OpenApiServiceCollectionExtensions.cs for more info.
Copy file name to clipboardExpand all lines: src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiEndpointRouteBuilderExtensionsTests.cs
// When we receive an OpenAPI document, we use an OptionsMonitor to retrieve OpenAPI options which are stored with a key equal the requested document name.
185
+
// This key is case-sensitive. If the document doesn't exist, the options monitor return a default instance, in which the OpenAPI version is set to v3.
186
+
// This could cause bugs! You'd get your document, but depending on the casing you used in the document name you passed to the function, you'll receive different OpenAPI document versions.
187
+
// We want to prevent this from happening. Therefore:
188
+
// By setting up a v2 document on the "casesensitive" route and requesting it on "CaseSensitive",
189
+
// we can test that the we've configured the options monitor to retrieve the options in a case-insensitive manner.
190
+
// If it is case-sensitive, it would return a default instance with OpenAPI version v3, which would cause this test to fail!
191
+
// However, if it would return the v2 instance, which was configured on the lowercase - case-insensitive - documentname, the test would pass!
192
+
// For more info, see OpenApiEndpointRouteBuilderExtensions.cs
// When we generate an OpenAPI document, we use an OptionsMonitor to retrieve OpenAPI options which are stored with a key equal the requested document name.
50
+
// This key is case-sensitive. If the document doesn't exist, the options monitor return a default instance, in which the OpenAPI version is set to v3.
51
+
// This could cause bugs! You'd get your document, but depending on the casing you used in the document name you passed to the function, you'll receive different OpenAPI document versions.
52
+
// We want to prevent this from happening. Therefore:
53
+
// By setting up a v2 document on the "casesensitive" route and requesting it on "CaseSensitive",
54
+
// we can test that the we've configured the options monitor to retrieve the options in a case-insensitive manner.
55
+
// If it is case-sensitive, it would return a default instance with OpenAPI version v3, which would cause this test to fail!
56
+
// However, if it would return the v2 instance, which was configured on the lowercase - case-insensitive - documentname, the test would pass!
0 commit comments