public override void OnResultExecuting(ResultExecutingContext context) { var query = (ObjectResult)context.Result; if (query == null) { throw new Exception("Unable to retreive value of IQueryable from context result."); } var apiController = context.Controller as ApiBaseController; if (apiController == null) { throw new InvalidOperationException("It is not an Api Controller!!!"); } dynamic pagedList = query.Value; var outputItems = (List <dynamic>)_outputModel.GetMethod("BuildResponseItems") .Invoke(null, new object[] { pagedList.List }); dynamic outputData = ApiOutputModel.Build(pagedList, apiController.Url, outputItems); context.HttpContext.Response.Headers.Add("X-Pagination", pagedList.GetHeader().ToJson()); context.Result = new JsonResult(outputData); }
public Task ProcessOutput(ApiResponseModel response, ApiOutputModel output) { var expression = JsonPathGrammar.Parse(output.Expression); var value = expression.Evaluate(response.JsonResponse); output.Value = value; return(TaskConstants.Completed); }
public Task ProcessOutput(ApiResponseModel response, ApiOutputModel output) { switch (response.ContentType) { case ContentTypes.ApplicationJson: return(OutputProcessorRegistry.GetProcessor(ApiOutputType.JsonPath).ProcessOutput(response, output)); default: throw new Exception($"No output processor defined for Content-Type: {response.ContentType}"); } }
public void Parse(ICollection<ApiDescription> apiDescriptions, string fileName) { List<ApiOutputModel> apis = new List<ApiOutputModel>(); foreach (var api in apiDescriptions) { var a = new ApiOutputModel(); a.HttpMethod = api.HttpMethod.ToString(); a.UrlTemplate = api.RelativePath.ToLower(); a.ServiceName = api.ActionDescriptor.ControllerDescriptor.ControllerName; a.MethodName = api.ActionDescriptor.ActionName; apis.Add(a); } WriteToFile(apis, fileName); }
public void Parse(ICollection <ApiDescription> apiDescriptions, string fileName) { List <ApiOutputModel> apis = new List <ApiOutputModel>(); foreach (var api in apiDescriptions) { var a = new ApiOutputModel(); a.HttpMethod = api.HttpMethod.ToString(); a.UrlTemplate = api.RelativePath.ToLower(); a.ServiceName = api.ActionDescriptor.ControllerDescriptor.ControllerName; a.MethodName = api.ActionDescriptor.ActionName; apis.Add(a); } WriteToFile(apis, fileName); }