From 271edc539118f95e891d2b2f35d12028d47fb014 Mon Sep 17 00:00:00 2001 From: Matthew Jackson <123390480+mjaksn@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:07:20 -0500 Subject: [PATCH] Fix OdsContext handling in Swagger generation (#832) --- .../Models/OpenApiMetadataRequest.cs | 2 +- .../EnabledOpenApiMetadataDocumentProvider.cs | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Application/EdFi.Ods.Features/OpenApiMetadata/Models/OpenApiMetadataRequest.cs b/Application/EdFi.Ods.Features/OpenApiMetadata/Models/OpenApiMetadataRequest.cs index f9c411754a..4b614d31db 100644 --- a/Application/EdFi.Ods.Features/OpenApiMetadata/Models/OpenApiMetadataRequest.cs +++ b/Application/EdFi.Ods.Features/OpenApiMetadata/Models/OpenApiMetadataRequest.cs @@ -18,7 +18,7 @@ public class OpenApiMetadataRequest public string CompositeCategoryName { get; set; } - public string SchoolYear { get; set; } + public string OdsContext { get; set; } public string InstanceId { get; set; } diff --git a/Application/EdFi.Ods.Features/OpenApiMetadata/Providers/EnabledOpenApiMetadataDocumentProvider.cs b/Application/EdFi.Ods.Features/OpenApiMetadata/Providers/EnabledOpenApiMetadataDocumentProvider.cs index 9ca462bbb2..9fd1fdacb7 100644 --- a/Application/EdFi.Ods.Features/OpenApiMetadata/Providers/EnabledOpenApiMetadataDocumentProvider.cs +++ b/Application/EdFi.Ods.Features/OpenApiMetadata/Providers/EnabledOpenApiMetadataDocumentProvider.cs @@ -65,19 +65,19 @@ public bool TryGetSwaggerDocument(HttpRequest request, out string document) return false; } - document = GetMetadataForContent(openApiContent, request, openApiMetadataRequest.SchoolYear, openApiMetadataRequest.InstanceId, openApiMetadataRequest.TenantIdentifierFromRoute); + document = GetMetadataForContent(openApiContent, request, openApiMetadataRequest.OdsContext, openApiMetadataRequest.InstanceId, openApiMetadataRequest.TenantIdentifierFromRoute); return true; } - private string GetMetadataForContent(OpenApiContent content, HttpRequest request, string schoolYear, string instanceId, string tenantIdentifier) + private string GetMetadataForContent(OpenApiContent content, HttpRequest request, string odsContextName, string instanceId, string tenantIdentifier) { - var schoolYearRouteValue = string.IsNullOrEmpty(schoolYear) ? string.Empty : $"{schoolYear}/"; + var odsContextRouteValue = string.IsNullOrEmpty(odsContextName) ? string.Empty : $"{odsContextName}/"; var instanceIdRouteValue = string.IsNullOrEmpty(instanceId) ? string.Empty : $"{instanceId}/"; var tenantIdentifierRouteValue = string.IsNullOrEmpty(tenantIdentifier) ? string.Empty : $"{tenantIdentifier}/"; - string basePath = request.PathBase.Value.EnsureSuffixApplied("/") + tenantIdentifierRouteValue + schoolYearRouteValue + content.BasePath.EnsureSuffixApplied("/") + instanceIdRouteValue; + string basePath = request.PathBase.Value.EnsureSuffixApplied("/") + tenantIdentifierRouteValue + odsContextRouteValue + content.BasePath.EnsureSuffixApplied("/") + instanceIdRouteValue; return content.Metadata .Replace("%HOST%", Host()) @@ -87,7 +87,7 @@ private string GetMetadataForContent(OpenApiContent content, HttpRequest request string TokenUrl() { var rootUrl = request.RootUrl(this._reverseProxySettings); - return $"{rootUrl}/" + tenantIdentifierRouteValue + schoolYearRouteValue + $"{instanceId}oauth/token"; + return $"{rootUrl}/" + tenantIdentifierRouteValue + odsContextRouteValue + $"{instanceId}oauth/token"; } string Host() => $"{request.Host(this._reverseProxySettings)}:{request.Port(this._reverseProxySettings)}"; @@ -99,6 +99,8 @@ private OpenApiMetadataRequest CreateOpenApiMetadataRequest(string path) // this is less effort that rewriting the open api metadata cache. var openApiMetadataRequest = new OpenApiMetadataRequest(); + var odsContextVariableName = _odsContextRoutePath?.TrimStart('{').TrimEnd('}'); + var matcher = new RouteMatcher(); foreach (var routeInformation in _routeInformations) @@ -129,9 +131,9 @@ private OpenApiMetadataRequest CreateOpenApiMetadataRequest(string path) } } - if (values.ContainsKey("schoolYear")) + if (odsContextVariableName != null && values.ContainsKey(odsContextVariableName)) { - openApiMetadataRequest.SchoolYear = values["schoolYear"] + openApiMetadataRequest.OdsContext = values[odsContextVariableName] .ToString(); }