-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added smart names for Named AnyOf with all referenced properties.
- Loading branch information
Showing
23 changed files
with
1,969 additions
and
1,309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/libs/OpenApiGenerator.Core/Helpers/SmartNamedAnyOfNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace OpenApiGenerator.Core.Helpers; | ||
|
||
public static class SmartNamedAnyOfNames | ||
{ | ||
public static string ComputeSmartName(string typeName, string className) | ||
{ | ||
var nameWords = SplitToWordsByUpperCharacters(typeName); | ||
var classNameWords = SplitToWordsByUpperCharacters(className); | ||
|
||
// Combine the unique strings from both collections | ||
return string.Concat( | ||
nameWords.Except(classNameWords)); | ||
} | ||
|
||
public static IReadOnlyList<string> SplitToWordsByUpperCharacters(string text) | ||
{ | ||
text = text ?? throw new ArgumentNullException(nameof(text)); | ||
|
||
var words = new List<string>(); | ||
var startIndex = 0; | ||
for (var i = 1; i < text.Length; i++) | ||
{ | ||
if (char.IsUpper(text[i])) | ||
{ | ||
words.Add(text.Substring(startIndex, i - startIndex)); | ||
startIndex = i; | ||
} | ||
} | ||
words.Add(text.Substring(startIndex)); | ||
|
||
return words; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.