AspNetCoreOData
AspNetCoreOData copied to clipboard
Swagger - Multiple blocks are expanded simultaneously
Assemblies affected ASP.NET Core OData 8.x
Describe the bug When you click on the operation (block) in swagger, multiple blocks expanded instead of one.
Reproduce steps
- Run your sample ODataRoutingSample
- Go to http://localhost:64771/swagger
- Click on "GET /v1/Customers" block Expected result: only GET block expanded Actual result: "POST /v1/Customers" expanded too.
Screenshots

Additional info This happens because the same operationId generated in the swagger.json:
"/v1/Customers": { "get": { "tags": [ "Customers" ], "operationId": "v1/Customers", "responses": { "200": { "description": "Success" } } }, "post": { "tags": [ "Customers" ], "operationId": "v1/Customers", <<< must be unique
I don't see this being an AspNetCoreOData issue. Can you elaborate why you think it is?
Also, are you using OpenAPI v3 output on swagger?
I don't know who calculate operationId actually. I reproduced the issue on ASP.NET Core OData sample.
I also found a workaround with CustomOperationIds here. Maybe it should be a part of ASP.NET Core OData?
Also, are you using OpenAPI v3 output on swagger?
Yes, the used OpenAPI version is 3.0.1
@vladimirlashko Thanks for reporting this.
@julealgon Yes, You are right. I think it's not AspNetCore.OData issue. That's the swagger gen [Swashbuckle.AspNetCore] issue (Or a configuration problem). @vladimirlashko You'd better to follow up swagger gen to update the operationId?
In the sample, I also have another swagger gen. It's from this repo: https://github.com/microsoft/OpenAPI.NET.OData . (Unfortunately, that's also my original work. :)
If based on the format of operationId at here: https://github.com/microsoft/OpenAPI.NET.OData/blob/master/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetPostOperationHandler.cs#L48
the operationId should be unique.
But, SwashBulk doesn't know about OData. So, it simply uses the path item name as the operation Id.
@xuzhg Do you recommend to make an issue at Swashbuckle.AspNetCore?
Btw, I tried to create a default ASP.NET Core Web API project and there is no issue because no operationId exists at the swagger.json:

@vladimirlashko I can see in one of my non-OData projects here that the operationID is also not being generated.
When you tested the sample, was that sample using latest versions of all libraries? If so, something in the sample is causing these IDs to be generated. I'd assume the presence of OData in the project shouldn't affect that directly especially now that OData v8 uses standard routing.
Can you see if you spot anything suspicious between the sample and your project? Can you add OData to your project and check if that by itself starts generating operationIDs?
@julealgon The sample resided in the AspNetCoreOData repository (this repository). I use the latest version of the sources. I also updated Microsoft.OpenApi.OData and Swashbuckle.AspNetCore packages in this sample and the issue still reproduced on the sample.
I'd assume the presence of OData in the project shouldn't affect that directly especially now that OData v8 uses standard routing.
I think OData can affect OpenAPI cause it manipulates routing. E.g. in this code: https://github.com/OData/AspNetCoreOData/blob/main/sample/ODataRoutingSample/Controllers/ODataOpenApiController.cs#L39
Can you see if you spot anything suspicious between the sample and your project?
Nothing suspicious. Swashbuckle generates OperationIds with OData and does not generate without OData.
@julealgon The sample resided in the AspNetCoreOData repository (this repository). I use the latest version of the sources. I also updated Microsoft.OpenApi.OData and Swashbuckle.AspNetCore packages in this sample and the issue still reproduced on the sample.
I'd assume the presence of OData in the project shouldn't affect that directly especially now that OData v8 uses standard routing.
I think OData can affect OpenAPI cause it manipulates routing. E.g. in this code: https://github.com/OData/AspNetCoreOData/blob/main/sample/ODataRoutingSample/Controllers/ODataOpenApiController.cs#L39
Can you see if you spot anything suspicious between the sample and your project?
Nothing suspicious. Swashbuckle generates OperationIds with OData and does not generate without OData.
But, you are sending " ~/swagger" not sending " ~/$openapi", right?
@xuzhg Correct, I need " ~/swagger".
@vladimirlashko has that solved the issue?
@habbes What exactly? The issue is somewhere between ASP.NET Core OData and Swashbuckle. Please fix it OR please point me to the correct third-party repository so I will ask for fix there.
Hello, any news here? Thanks!
Probably a Swashbuckle issue. Try following:
// mvcBuilder of type IMvcBuilder.
mvcBuilder.Services.AddSwaggerGen(o =>
{
// Provide unique operation ID.
o.CustomOperationIds(x => string.Join("/", x.HttpMethod.ToLower(), x.RelativePath));
}
I see this also. I click on an API operation in Swagger UI and the entry above it and the entry I selected are both expanded. This only happens for ODataController.
https://github.com/AJMauger/sunstealer.mvc.odata
In Swagger 6.5.0 and OData 8.2.4 issue is still present, but workaround by specifying custom operation identifiers works well