public HttpResponseMessage GetSections([FromUri] OpenApiMetadaSectionsRequest request) { var content = new StringContent( JsonConvert.SerializeObject( _openApiMetadataCacheProvider.GetAllSectionDocuments(request.Sdk) .Select(x => GetSwaggerSectionDetailsForCacheItem(x, request)))); var eTag = new EntityTagHeaderValue(HashHelper.GetSha256Hash(content.ToString()).ToHexString().DoubleQuoted()); if (ActionContext.Request.Headers.IfNoneMatch.Contains(eTag)) { return(new HttpResponseMessage(HttpStatusCode.NotModified)); } var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = content, Headers = { ETag = eTag } }; result.Content.Headers.ContentType = new MediaTypeHeaderValue(SwaggerDocumentHelper.ContentType); return(result); }
private SwaggerSectionDetails GetSwaggerSectionDetailsForCacheItem(OpenApiContent apiContent, OpenApiMetadaSectionsRequest request) { // Construct fully qualified metadata url var url = new Uri( new Uri(new Uri(Request.RootUrl(_useProxyHeaders).EnsureSuffixApplied("/")), "metadata/"), GetMetadataUrlSegmentForCacheItem(apiContent, request.SchoolYearFromRoute)); return(new SwaggerSectionDetails { EndpointUri = url.AbsoluteUri, Name = apiContent.Name.NormalizeCompositeTermForDisplay('-').Replace(" ", "-"), Prefix = apiContent.Section.EqualsIgnoreCase(OpenApiMetadataSections.SwaggerUi) ? string.Empty : apiContent.Section }); }