Unique Swagger Description per Version #899
-
Using the ApiExplorer package, we can customize the description of the OpenApi document. However, looking through the examples you have out there (which are very helpful by the way), I don't see a way to make that unique per version / group name. Is this something that is supported? If not, is there an easy way to add this? If adding myself, it would have to be done through dependency injection. That is the only requirement. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
There is a long thread about this in #516, which also includes some possible solutions. The crux of the problem is two-fold:
Both of these limitations make it difficult to do anything different; specifically, a group per name per API version. The list effectively has to be flattened to make anything work. If you put in the effort to change the UI, it's not an insane amount of work to group the code the way you want. Most people don't want to put in that much work though. Currently, the rules are:
Enough people have asked about this, that I can see adding an enhancement that would enable a 3rd+ option. That would enable a flattened, two-part group name without having to roll a bunch of infrastructure yourself. Hopefully that answers your question and gives you a direction to go. I've mentally filed away this idea, but if you'd like to queue up formal enhancement issue, I'll endorse it. 😄 |
Beta Was this translation helpful? Give feedback.
-
📣 Follow up. Enough people have asked about this over the years, that I've taken a hard look at how this would be implemented. A new feature is coming in The new configuration will look like: services.AddApiVersioning()
.AddApiExplorer( options =>
{
options.GroupNameFormat = "'v'VVV";
options.FormatGroupName = (groupName, apiVersion) => $"{groupName}-{apiVersion}";
}); Let's say your controller looked like: [ApiVersion( 1.0 )]
[ApiController]
[ApiExplorerSettings( GroupName = "Example" )]
[Route( "[controller]" )]
public class ExampleController : ControllerBase
{
[HttpGet]
public IActionResult Get() => Ok();
} The final group name will become I'm working on the PR now. |
Beta Was this translation helpful? Give feedback.
📣 Follow up.
Enough people have asked about this over the years, that I've taken a hard look at how this would be implemented. A new feature is coming in
6.2
that will accommodate this type of group name.The new configuration will look like:
Let's say your controller looked like: