在 Swagger 上发布引用数组子属性
Issue referencing arrays subproperties on Swagger
将 [ProducesResponseType(typeof(IEnumerable), 200)] 添加到方法时,我们在生成 swagger 文档时遇到问题。 array/list 类型的子属性未被引用,如下图所示。
如果我们将此属性设置为IEnumerable/List,就像class类型一样,响应类型属性会很好地生成,例如
有什么建议吗?
据我所知,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; }
}
将 [ProducesResponseType(typeof(IEnumerable), 200)] 添加到方法时,我们在生成 swagger 文档时遇到问题。 array/list 类型的子属性未被引用,如下图所示。
如果我们将此属性设置为IEnumerable/List,就像class类型一样,响应类型属性会很好地生成,例如
有什么建议吗?
据我所知,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; }
}