IEdmModel.ConvertToOpenApi() throws System.InvalidOperationException when having dollar-count similar path in controller
Maintainer antworten meist innerhalb von 1 Tag
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
- 2 Std. 8 Min.
- Gemergte PRs (30 T.)
- 9
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
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 · 1 Kommentar · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
microsoft/OpenAPI.NET.OData#833 ·
Maintainer antworten meist innerhalb von 1 Tag
-
status:needs-more-information
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
microsoft/OpenAPI.NET.OData#723 · 1 Kommentar · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Action bound to abstract entity type is not present in OpenAPI output when using hidi to convert from CSDLEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
microsoft/OpenAPI.NET.OData#720 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
microsoft/OpenAPI.NET.OData#710 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in microsoft/OpenAPI.NET.OData
Ähnliche Issues
-
[Bug]: Missing extensions in Agent Card capabilities in v0.3 compat modeEvtl. vergeben @hwanders hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
a2aproject/a2a-dotnet#514 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
agentic-workflows untriaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
VS Code
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
AlamoEngine-Tools/pg-starwarsgame-lsp#207 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
elsa-workflows/elsa-core#8593 ·
Maintainer antworten meist innerhalb von 1 Tag
-
GpioController.QueryComponentInformation() throws NotSupportedException with RaspberryPi3DriverOffenuntriaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100