响应模型模式在Swagger中作为空对象 - C#| Swashbuckle

时间:2016-12-21 12:30:09

标签: c# asp.net-web-api swagger swagger-ui swashbuckle

这是我的API:

/// <summary>
        /// Gets activity logs.
        /// </summary>
        /// <param name="locationId">Location id.</param>
        /// <param name="filter">Activity log filter options.</param>
        [ResponseType(typeof(ActivityLogResponse))]
        public async Task<HttpResponseMessage> FetchActivityLogs(int locationId, ActivityLogFilterOptions filter)
        {
            try
            {
                var response = await _activityLogLogic.GetActivityLogs(CHIdentity.User, locationId, filter);
                return Request.CreateResponse(HttpStatusCode.OK, response);
            }
            catch (HttpRequestException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message + "\n" + ex.InnerException.Message);
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
            }
        }

ActivityLogResponse类的定义:

 public class ActivityLogResponse
    { 
       public List<ActivityLogMessage> ActivityLogs { get; set; }
       Logs { get; set; }
    }

招摇的是JSON 回复 "type": "object"而不是ActivityLogFilterOptions

请参阅以下Swagger Json中的Responses

    "/api/locations/{locationId}/FetchActivityLogs": {
        "post": {
            "tags": ["ActivityLog"],
            "summary": "Gets activity logs.",
            "operationId": "ActivityLog_FetchActivityLogs",
            "consumes": ["application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded"],
            "produces": ["application/json", "text/json", "application/xml", "text/xml"],
            "parameters": [{
                    "name": "locationId",
                    "in": "path",
                    "description": "Location id.",
                    "required": true,
                    "type": "integer",
                    "format": "int32"
                }, {
                    "name": "filter",
                    "in": "body",
                    "description": "Activity log filter options.",
                    "required": true,
                    "schema": {
                        "$ref": "#/definitions/ActivityLogFilterOptions"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "OK",
                    "schema": {
                        "type": "object"
                    }
                }
            }
        }
    },

enter image description here

如何在此处加载ActivityLogFilterOptions而不是{}

0 个答案:

没有答案