[英]C# Swashbuckle Annotations - define response headers
I use annotations like this from the package Swashbuckle.AspNetCore.Annotations to define responses for swagger:我使用来自 package Swashbuckle.AspNetCore.Annotations的注释来定义 swagger 的响应:
[SwaggerResponse(200, "OK", typeof(SampleResponseClass))]
Is it possible with this package to define also the headers of the response?这个 package 是否也可以定义响应的标头? And if not what other possibilities would there be?
如果不是,还有哪些其他可能性?
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.您可以创建过滤器来修改由
Swashbuckle.AspNetCore
生成的模型,以使用附加信息丰富文档。 You want to include additional information on an "operation", so you need to implement the IOperationFilter
interface.您想要包含有关“操作”的附加信息,因此您需要实现
IOperationFilter
接口。
I recommend checking out the source code for Swashbuckle.AspNetCore.Annotations
for examples of how you can implement the IOperationFilter
interface.我建议查看
Swashbuckle.AspNetCore.Annotations
的源代码,了解如何实现IOperationFilter
接口的示例。
I built some Swashbuckle filters a few years ago to support that.几年前我构建了一些 Swashbuckle 过滤器来支持它。
.NET Core: https://github.com/mattfrear/Swashbuckle.AspNetCore.Filters#add-a-response-header .NET 核心: https://github.com/mattfrear/Swashbuckle.AspNetCore.Filters#add-a-response-header
.NET Framework: https://github.com/mattfrear/Swashbuckle.Examples#add-a-response-header .NET 框架: https://github.com/mattfrear/Swashbuckle.Examples#add-a-response-header
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.