让swagger.json包含模型

时间:2018-06-14 07:18:10

标签: asp.net-core swagger

如果我的控制器中有以下内容,则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?

0 个答案:

没有答案