I use annotations like this from the package Swashbuckle.AspNetCore.Annotations to define responses for swagger:
[SwaggerResponse(200, "OK", typeof(SampleResponseClass))]
Is it possible with this package to define also the headers of the response? And if not what other possibilities would there be?
2
Answers
From what I can tell, there are no pre-existing annotations can be used to describe headers; but you could create your own.
You can create filters that modify the models produces by
Swashbuckle.AspNetCore
to enrich the document with additional information. You want to include additional information on an "operation", so you need to implement theIOperationFilter
interface.I recommend checking out the source code for
Swashbuckle.AspNetCore.Annotations
for examples of how you can implement theIOperationFilter
interface.I built some Swashbuckle filters a few years ago to support that.
.NET Core:
https://github.com/mattfrear/Swashbuckle.AspNetCore.Filters#add-a-response-header
.NET Framework:
https://github.com/mattfrear/Swashbuckle.Examples#add-a-response-header