Response Model Schema is coming as empty object in Swagger - C# | Swashbuckle

3k views Asked by At

This is my 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);
            }
        }

Defination of ActivityLogResponse class:

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

In swagger JSON responses "type": "object" is coming instead of ActivityLogFilterOptions

See Responses in following Swagger Json:

    "/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

How to load ActivityLogFilterOptions here instead of {}?

0

There are 0 answers