【问题标题】:Issue referencing arrays subproperties on Swagger在 Swagger 上发布引用数组子属性
【发布时间】:2017-10-27 21:15:20
【问题描述】:

在方法中添加 [ProducesResponseType(typeof(IEnumerable), 200)] 时,我们会在生成 swagger 文档时遇到问题。数组/列表类型的子属性不会被引用,如下图所示。

如果我们将此属性设置为不为IEnumerable/List,而只是作为类类型,则响应类型属性生成良好,例如,

有什么建议吗?

【问题讨论】:

    标签: c# asp.net-core swagger swagger-ui swashbuckle


    【解决方案1】:

    据我所知,Swashbuckle 不能很好地处理继承。

    我们将可枚举的响应包装在一个对象中以防止JSON hijacking

    [ResponseType(typeof(ResponseWrapper<IEnumerable<Model>>))]
    

    作为一个副作用(或解决方法,如果你愿意的话),Swashbuckle 对此很满意,并且可以很好地生成文档。

    这里是ResponseWrapper

    sealed class ResponseWrapper<T>
    {
        public ResponseWrapper(T response)
        {
            Value = response;
        }
        public T Value { get; set; }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 2022-01-06
      • 2011-07-23
      • 1970-01-01
      • 2012-11-16
      相关资源
      最近更新 更多