dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.48k stars 10.04k forks source link

OpenApi won't Contains those Controllers If the Controller not starts with [ApiController] Attribute #58938

Open yangbocheng opened 12 hours ago

yangbocheng commented 12 hours ago

Is there an existing issue for this?

Describe the bug

Simply create a newest NET 9 aspnetcore webapi, then add Microsoft.AspNetCore.OpenApi and Scalar.AspNetCore. Then add a new Controller without [ApiController], this contoller's actions won't be included in openapi json

Expected Behavior

Controllers without [ApiController] should be included in openapi json

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

NET 9

Anything else?

No response

yangbocheng commented 12 hours ago

The reason to not use the [ApiController] is : Need manual validate some form fields, or api parameters in Project OpenApi won't Contains those Controllers If the Controller not starts with [ApiController] Attribute

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
  <PackageReference Include="Scalar.AspNetCore" Version="1.2.36" />
</ItemGroup>

so if remove the [ApiController] from Test1Controller.cs , then this won't show in openapi/v1.json Image Image Image