From 9d014e631059eae0950df7d11464b63f6fb1a08e Mon Sep 17 00:00:00 2001 From: Gino Canessa Date: Thu, 1 Jun 2023 17:14:06 +0200 Subject: [PATCH] Core: Fixed ToPascalDotNotation utils. --- .../FhirNameConventionExtensions.cs | 43 +++++++++++++++---- .../Models/FhirTypeBase.cs | 2 +- .../Models/FhirUtils.cs | 4 +- .../Language/Info.cs | 1 + 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.Health.Fhir.CodeGenCommon/Extensions/FhirNameConventionExtensions.cs b/src/Microsoft.Health.Fhir.CodeGenCommon/Extensions/FhirNameConventionExtensions.cs index cb9fe5ff7..0408d86e9 100644 --- a/src/Microsoft.Health.Fhir.CodeGenCommon/Extensions/FhirNameConventionExtensions.cs +++ b/src/Microsoft.Health.Fhir.CodeGenCommon/Extensions/FhirNameConventionExtensions.cs @@ -378,25 +378,50 @@ public static string ToLowerSnakeCaseWord(this IEnumerable words, bool r /// A string extension method that converts this object to a pascal dot case. /// /// The word to act on. - /// (Optional) True to remove delimiters. /// The given data converted to a string. - public static string ToPascalDotCase(this string word, bool removeDelimiters = true) - => ToPascalCase(word, removeDelimiters, "."); + public static string ToPascalDotCase(this string word) + { + if (string.IsNullOrEmpty(word)) + { + return string.Empty; + } + + return string.Join('.', word.Split(_wordDelimiters, _wordSplitOptions).Select(w => w.ToPascalCase(false))); + } /// A string extension method that converts this object to a pascal dot case. /// The words. - /// (Optional) True to remove delimiters. /// The given data converted to a string. - public static string[] ToPascalDotCase(this string[] words, bool removeDelimiters = true) - => ToPascalCase(words, removeDelimiters, "."); + public static string[] ToPascalDotCase(this string[] words) + { + if (!(words?.Any() ?? false)) + { + return Array.Empty(); + } + + string[] output = new string[words.Length]; + + for (int i = 0; i < words.Length; i++) + { + output[i] = ToPascalDotCase(words[i]); + } + + return output; + } /// /// An IEnumerable<string> extension method that converts this object to a pascal dot case /// word. /// /// The words. - /// (Optional) True to remove delimiters. /// The given data converted to a string. - public static string ToPascalDotCaseWord(this IEnumerable words, bool removeDelimiters = true) - => ToPascalCaseWord(words, removeDelimiters, "."); + public static string ToPascalDotCaseWord(this IEnumerable words) + { + if (!(words?.Any() ?? false)) + { + return string.Empty; + } + + return string.Join('.', words.Select(w => w.ToPascalDotCase())); + } } diff --git a/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirTypeBase.cs b/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirTypeBase.cs index 62dc3628a..5e93d957d 100644 --- a/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirTypeBase.cs +++ b/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirTypeBase.cs @@ -252,7 +252,7 @@ public string NameForExport( case NamingConvention.PascalDotNotation: { - string value = _path.ToPascalDotCase(true); + string value = _path.ToPascalDotCase(); if ((reservedWords != null) && reservedWords.Contains(value)) diff --git a/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirUtils.cs b/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirUtils.cs index ade248e8d..779762ab9 100644 --- a/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirUtils.cs +++ b/src/Microsoft.Health.Fhir.CodeGenCommon/Models/FhirUtils.cs @@ -247,7 +247,7 @@ public static string ToConvention( case NamingConvention.PascalDotNotation: { - return value.ToPascalDotCase(true); + return value.ToPascalDotCase(); } case NamingConvention.PascalCase: @@ -305,7 +305,7 @@ public static string SanitizedToConvention(string sanitized, NamingConvention co case NamingConvention.PascalDotNotation: { - return sanitized.ToPascalDotCase(true); + return sanitized.ToPascalDotCase(); } case NamingConvention.PascalCase: diff --git a/src/Microsoft.Health.Fhir.SpecManager/Language/Info.cs b/src/Microsoft.Health.Fhir.SpecManager/Language/Info.cs index 379f65e67..9a1a4a97e 100644 --- a/src/Microsoft.Health.Fhir.SpecManager/Language/Info.cs +++ b/src/Microsoft.Health.Fhir.SpecManager/Language/Info.cs @@ -5,6 +5,7 @@ using System.IO; using System.Text.Json; +using Microsoft.Health.Fhir.CodeGenCommon.Extensions; using Microsoft.Health.Fhir.SpecManager.Manager; namespace Microsoft.Health.Fhir.SpecManager.Language