首页 > 解决方案 > Swagger-net(或 swashbuckle):如何在 xml 请求中设置命名空间?

问题描述

有没有办法使用 Swagger-net 生成带有 xml 命名空间的示例请求?还是花花公子?

我在想类似的东西:

 [SwaggerResponseExample(HttpStatusCode.OK,
 typeof(ResponseExample), xmlnamespace="wanted xml namespace goes here...")]

标签: swaggerswashbuckleswashbuckle.examples

解决方案


在 Swagger-Net 中,SwaggerResponse您可以这样称呼它:

[SwaggerResponse(400, "Bad request")]
public class SwaggerAnnotatedController : ApiController
{
    [SwaggerResponseRemoveDefaults]
    [SwaggerResponse(HttpStatusCode.Created, Type = typeof(int), MediaType = "text", Examples = 123)]
    [SwaggerResponse(HttpStatusCode.BadRequest, "Invalid message", typeof(HttpError))]
    public int Create(Message message)
    {
        throw new NotImplementedException();
    }

    [SwaggerResponse( 200, Type = typeof( IEnumerable<Message> ), TypeName = "Messages" )]
    public IEnumerable<Message> GetAll()
    {
        throw new NotImplementedException();
    }

但我从来不需要 xmlnamespace 所以没有这样的选择:

https://github.com/heldersepu/Swagger-Net/blob/master/Swagger.Net/Swagger/Annotations/SwaggerResponseAttribute.cs

但是,如果您可以提供有关如何使用 xmlnamespace 的精确详细信息,我可以添加它。


推荐阅读