.NET揚鞭模型模式只爲找UNION形成是空的(一個簡單的GET顯示正確的模型架構).NET揚鞭模型模式是空的 - 只有按聯盟GET形成
我如何能表現出良好的方法swagger的模型模式顯示一個空的模式?
.NET揚鞭模型模式只爲找UNION形成是空的(一個簡單的GET顯示正確的模型架構).NET揚鞭模型模式是空的 - 只有按聯盟GET形成
我如何能表現出良好的方法swagger的模型模式顯示一個空的模式?
使用SwaggerResponse像這樣的:
[SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(IEnumerable<int>))]
[SwaggerResponse(HttpStatusCode.BadRequest, Type = typeof(BadRequestErrorMessageResult))]
[SwaggerResponse(HttpStatusCode.NotFound, Type = typeof(NotFoundResult))]
public IHttpActionResult GetById(int id)
{
if (id > 0)
return Ok(new int[] { 1, 2 });
else if (id == 0)
return NotFound();
else
return BadRequest("id must be greater than 0");
}
你之間的區別是一個使用HttpResponseMessage
問題的部分是由@HelderSepu觀察,我發出的響應不是IEnumerable的(因爲Linq中的 「選擇」)。
所以我需要創建一個模型類,纔能有正確的模型架構:
namespace SupplierB_api.Models {
public class SupplierResponse {
public int SupplierID;
public string SupplierName;
public char SupplierType; }
}
然後,我用的是模型的Linq:
var SuppliersDistributor = entities.tblD.Take(5).AsEnumerable()
.Select(d => new SupplierResponse { SupplierID = d.distributor_id, SupplierName = d.distributor_name, SupplierType = 'D'});
var SuppliersPublisher = entities.tblN.Take(5).AsEnumerable()
.Select(p => new SupplierResponse { SupplierID = p.publisher_id, SupplierName = p.publisher_name, SupplierType = 'P' });
然後,我使用SwaggerResponse(由@HelderSepu所建議的):
[SwaggerResponse(HttpStatusCode.OK, "response", typeof(IOrderedEnumerable<SupplierResponse>))]