在.NET中,我可以使用我的方法上的XML标记和标记自动生成文档。 e.g。
// DELETE: api/MyType
/// <summary>
/// Deletes a MyType with specified ID
/// </summary>
/// <param name="key">The ID of the MyType to delete</param>
/// <returns>The data for the deleted MyType</returns>
[HttpDelete]
[ProducesResponseType(typeof(MyType), 200)]
这种方法效果很好,除非我有一个非常深的嵌套对象。当swashbuckle从[ProducesResponseType]生成文档时,它会在树下直接递归每个属性,这可能是巨大的。我只想要对象本身的顶级属性。
有可能这样做吗?
生成的对象响应文档如下所示
"IsAvlOverride": true,
"Notes": "string",
"DateRejected": "2018-02-26T21:53:26.127Z",
"GeometryType": 0,
"PrimaryTagId": 0,
"OptimisticLockField": 0,
"Atplot": [
{
"UniqueId": "string",
"Hrid": "string",
"CreatedBy": 0,
"CreatedOn": "2018-02-26T21:53:26.127Z",
"ModifiedBy": 0,
"ModifiedOn": "2018-02-26T21:53:26.127Z",
"AtpLotId": 0,
"AtpId": 0,
"LotId": 0,
"ItemInspect": "string",
"DateInspect": "2018-02-26T21:53:26.127Z",
"TimeInspect": "2018-02-26T21:53:26.127Z",
"DateApproved": "2018-02-26T21:53:26.127Z",
"ApprovedById": 0,
"ApprovalComments": "string",
"OptimisticLockField": 0,
"Approval": [
{
"UniqueId": "string",
"Hrid": "string",
"CreatedBy": 0,
"CreatedOn": "2018-02-26T21:53:26.127Z",
"ModifiedBy": 0,
"ModifiedOn": "2018-02-26T21:53:26.127Z",
"ApprovalId": 0,
"ApprovalItemTypeId": 0,
"ApprovalSubtypeId": 0,
"RequestToId": 0,
"RequestById": 0,
"RequestText": "string",
"RequestDate": "2018-02-26T21:53:26.127Z",
"RequiredDate": "2018-02-26T21:53:26.127Z",
"EmailDate": "2018-02-26T21:53:26.127Z",
"ResponseDate": "2018-02-26T21:53:26.127Z",
"ResponseText": "string",
"ApprovalStatusTypeId": 0,
"ProjectId": 0,
"CloseOutDate": "2018-02-26T21:53:26.127Z",
etc...
我希望它看起来像;
"IsAvlOverride": true,
"Notes": "string",
"DateRejected": "2018-02-26T21:53:26.127Z",
"GeometryType": 0,
"PrimaryTagId": 0,
"OptimisticLockField": 0,
"Atplot": [Atplot_object]
答案 0 :(得分:0)
我不认为你问的是个好主意...
任何尝试使用您的API的人都无法获得完整的模型
但您可以在模型上使用[JsonIgnore]
来忽略字段/属性
答案 1 :(得分:0)
感谢domaindrivendev在github问题上,你可以轻松做到的最好是降低噪音,如下所示。它对我有用
app.UseSwaggerUI(c =>
{
c.DefaultModelRendering(ModelRendering.Model);
c.DefaultModelExpandDepth(1);
});