From c6a994d00c8029ec8753ab4019fc721a255a2ad1 Mon Sep 17 00:00:00 2001 From: "Per Christian B. Viken" Date: Wed, 18 Sep 2024 09:46:19 +0200 Subject: [PATCH] fix(lib): Handle ~/ in endpoint routes Fixes #76 --- CHANGELOG.md | 4 ++++ TypeContractor/TypeScript/ApiClientWriter.cs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bdbef5..0965b6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Fixed + +- Don't blindly append controller prefix to API client URLs (#76) + ## [0.12.5] - 2024-09-18 ### Fixed diff --git a/TypeContractor/TypeScript/ApiClientWriter.cs b/TypeContractor/TypeScript/ApiClientWriter.cs index b5594e5..2a81dfc 100644 --- a/TypeContractor/TypeScript/ApiClientWriter.cs +++ b/TypeContractor/TypeScript/ApiClientWriter.cs @@ -44,9 +44,9 @@ public string Write(ApiClient apiClient, IEnumerable allTypes, TypeS foreach (var endpoint in apiClient.Endpoints) { Logger.Log.Instance.LogDebug($" Processing endpoint {endpoint.Name}"); - var url = !string.IsNullOrWhiteSpace(apiClient.Prefix) && !endpoint.Route.StartsWith('/') + var url = !string.IsNullOrWhiteSpace(apiClient.Prefix) && !endpoint.Route.StartsWith('/') && !endpoint.Route.StartsWith("~/", StringComparison.Ordinal) ? $"{apiClient.Prefix}/{endpoint.Route}" - : endpoint.Route; + : endpoint.Route.Replace("~/", string.Empty); if (!_httpMethods.TryGetValue(endpoint.Method, out var method)) throw new NotImplementedException($"No mapping exists for {endpoint.Method}");