如果我的控制器中有以下内容,则swagger.json将包含JobHeaderDto模型
[HttpGet("{id}", Name = "Get")]
public JobHeaderDto Get(int id)
{
var header1 = new JobHeaderDto
{
JobNumber = "1234",
Id = id,
CustomerPurchaseOrderNumber = "fred"
};
return header1;
}
但是,如果我有以下代码,那么该模型将不会包含在swagger.json
中 [HttpGet("{id}", Name = "Get")]
public IActionResult Get(int id)
{
var header1 = new JobHeaderDto
{
JobNumber = "1234",
Id = id,
CustomerPurchaseOrderNumber = "fred"
};
return Ok(header1);
}
JobHeaderDto的代码是
[DataContract]
public class JobHeaderDto
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string JobNumber { get; set; }
[DataMember]
public string CustomerPurchaseOrderNumber { get; set; }
}
我更喜欢第二种方式,但我怎么能大摇大摆地包含JobHeaderDto?