简体   繁体   English

C# Swashbuckle 注释 - 定义响应标头

[英]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接口的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM