您可以使用自定义过滤器扩展、过滤和自定义架构:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore#extend-generator-with-operation-schema--document-filters
我确实使用它来为每个请求装饰更多的标头字段(例如授权标头)。我不确定它是否适用于整个端点。但也许值得一试。
更新(已编辑)
这是一个添加整个端点的示例 IDocumentFilter:
private class DocumentFilterAddFakes : IDocumentFilter
{
private PathItem FakePathItem(int i)
{
var x = new PathItem();
x.Get = new Operation()
{
Tags = new[] { "Fake" },
OperationId = "Fake_Get" + i.ToString(),
Consumes = null,
Produces = new[] { "application/json", "text/json", "application/xml", "text/xml" },
Parameters = new List<IParameter>()
{
new NonBodyParameter() // Can also be BodyParameter
{
Name = "id",
@In = "path",
Required = true,
Type = "integer",
Format = "int32",
@Default = 8
}
},
};
x.Get.Responses = new Dictionary<string, Response>();
x.Get.Responses.Add("200", new Response() { Description = "OK", Schema = new Schema() { Type = "string" } });
return x;
}
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
for (int i = 0; i < 10; i++)
swaggerDoc.paths.Add("/Fake/" + i + "/{id}", FakePathItem(i));
}
}