IEdmModel.ConvertToOpenApi() throws System.InvalidOperationException when having dollar-count similar path in controller
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 68/100
Rechercherichtung
Beginne in src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs bei AppendBoundOperationOnNavigationSourcePath() in der Nähe von Zeile 950 und reproduziere den Fehler mit der im Issue beschriebenen Count()-Operation. Verfolge, wie AppendPath die IList verändert, und überprüfe anschließend, dass ConvertToOpenApi das Dokument ohne die Ausnahme zur Änderung der Collection erstellt, während du die Auswirkungen auf die Pfade von $count und Count() überprüfst.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
I have a Count() operation in an ODataController. When I call ConvertToOpenApi on the IEdmModel a System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' is thrown ( in src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs).
Assemblies affected
occurs at least in:
- Microsoft.OpenApi.OData 1.7.4
- Microsoft.OpenApi.OData 2.0.0 preview 8
Steps to reproduce
In an ODataController, add a dollar-count-similar operation, eg:
[HttpGet]
[Description("Shows the total count of entities")]
public async Task<IActionResult> Count()
{
return await CountEntities();
}
Add the function to the ODataConventionModelBuilder, eg:
builder.EntityType<Entity>().Collection.Function(nameof(EntitiesController.Count)).Returns<int>();
Create the IEdmModel and call
var edmModel = odataBuilder.GetEdmModel();
var document = edmModel.ConvertToOpenApi();
Expected result
The OpenApiDocument gets created.
Actual result
System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'
Following the StackTrace the reason is:
AppendBoundOperationOnNavigationSourcePath() has a foreach on IList, which calls AppendPath(newPath);, which results in a modification of the paths, if a dollar-count-similar path is found, hence resulting in the InvalidOperationException.
Additional detail
Creating a copy of the collection before iterating over it in ODataPathProvider.cs L950 would work in my use-case, but keeps the $count and Count() operations in the openapi specification. Don't know if that is a problem.
foreach (var subPath in value.ToList())
...
As a workaround - not using dollar-similar-paths in your OData operations removes the issue as well ;)
- Vorherrschende Sprache
- C#
- Sterne
- 240
- Forks
- 70
- Ø Merge
- 7 Std. 59 Min.
- Gemergte PRs (30 T.)
- 13
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/OpenAPI.NET.OData
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 58/100
microsoft/OpenAPI.NET.OData#852 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
microsoft/OpenAPI.NET.OData#833 ·
-
status:needs-more-information
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
microsoft/OpenAPI.NET.OData#723 · 1 Kommentar · 1 Reaktion ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
microsoft/OpenAPI.NET.OData#720 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
microsoft/OpenAPI.NET.OData#710 · 2 Kommentare · 1 Reaktion ·
Alle Issues in microsoft/OpenAPI.NET.OData
Ähnliche Issues
-
bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
azurenoops/spin_agent#975 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
SubtitleEdit/subtitleedit#15108 · 1 Kommentar ·