private List<PostmanData> GetPostmanDatas(ApiDescription api) { var postmandatas = new List<PostmanData>(); var apiModel = Configuration.GetHelpPageApiModel(api.GetFriendlyId()); var raw = apiModel.SampleRequests.Values.FirstOrDefault(); if (raw == null) return postmandatas; var pdata = JsonConvert.DeserializeObject<Dictionary<string,string>>(raw.ToString()); postmandatas.AddRange(pdata.Select(model => new PostmanData {key = model.Key, value = model.Value})); return postmandatas; }
private static ApiInfo GetApiInfo(ApiDescription desc) { var api = new ApiInfo() { Name = desc.GetFriendlyId() }; api.Method = desc.HttpMethod.Method; api.Route = GetRoute(desc); api.RouteParameters = GetRouteParameters(desc); api.QueryParameters = GetQueryParameters(desc); api.BodyParameter = GetBodyParameter(desc); api.ComplexTypes = GetComplexTypes(api.BodyParameter); return api; }
public static void ParseResponse(Trace trace, HttpResponseMessage response) { try { var responseBody = response.Content; trace.Response = responseBody.ReadAsStringAsync().Result; trace.Status = ((int)response.StatusCode).ToString(); if (trace.Response.Length > 0 && !trace.Status.Equals("429")) { trace.ResponseBodyLength = responseBody.Headers.ContentLength; var ad = response.RequestMessage.GetActionDescriptor(); if (ad != null) { var action = new ApiDescription { HttpMethod = response.RequestMessage.Method, RelativePath = response.RequestMessage.RequestUri.PathAndQuery.Substring(1) }; var fid = action.GetFriendlyId(); trace.FriendlyURI = APIUriList.FirstOrDefault(x => x.Equals(fid, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrWhiteSpace(trace.FriendlyURI)) trace.FriendlyURI = APIUriList.FirstOrDefault(x => x.StartsWith(fid, StringComparison.OrdinalIgnoreCase)); trace.Action = ad.ControllerDescriptor.ControllerName + " / " + ad.ActionName; } if (TraceList.Count >= 64) TraceList.RemoveAt(0); TraceList.Add(trace); } } catch (Exception) { } }