Add better warnings about WithOpenApi potentially being useless #59927
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
feature-openapi
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Hi!
In #59180 the following is said:
I've been playing around a lot with
Microsoft.AspNetCore.OpenApi
. I tried to useWithOpenApi
to edit some parameter descriptions, change operation responses, etc... It seemed a lot easier than creating a global transformer (which is why I am so happy about #59180 !). I was pulling my hair out, because it didn't work at all. The debugger told me things were being added to the OpenAPI definitions, but they weren't showing up in the document.Then, by chance, I read the XML comments:
Now that
Microsoft.AspNetCore.OpenAPI
supports document generation, it's really weird thatWithOpenApi
does not play along.This cost me quite a bit of time. The fact that I had to find it in the XML comments is not obvious enough.
Therefore, I believe we should do better than XML comments.
Describe the solution you'd like
Analyzer
Therefore, I believe we should consider either adding an analyzer that warns people about
WithOpenApi
being a no-op when only using Microsoft.AspNetCore.OpenApi.This way it's way more obvious when you're doing something wrong. It will save a lot of time and frustration.
Deprecation
Perhaps we should even deprecate
WithOpenApi
and let Swashbuckle/NSwag deal with this on their own? This would be a breaking change, though.. But maybe for the best?I really wonder why ASP.NET Core's own OpenAPI generation library should have methods that are only used by 3rd party libraries.
Now that Swashbuckle's not included by default anymore,
WithOpenApi
is code that is included in most (new) ASP.NET Core projects that won't do anything, and can only cause confusion. I do not remember anything like this in ASP.NET Core's public API like this, though that may also be ignorance.Additional context
No response
The text was updated successfully, but these errors were encountered: