Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Smithy.CSharpGenerator/Utils/NamingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Smithy.CSharpGenerator.Utils
{
public static class NamingUtils
{
public static string PascalCase(string id)
{ public static string PascalCase(string id)
{
if (string.IsNullOrEmpty(id)) return id;
var parts = id.Split(new[] { '.', '#', '_' }, System.StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -18,5 +17,22 @@ public static string PascalCase(string id)
}
return sb.ToString();
}

public static string KebabCase(string id)
{
if (string.IsNullOrEmpty(id)) return id;
var sb = new StringBuilder();

for (int i = 0; i < id.Length; i++)
{
if (i > 0 && char.IsUpper(id[i]))
{
sb.Append('-');
}
Comment on lines +25 to +31
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider enhancing the KebabCase method to better handle sequences of uppercase letters (e.g., abbreviations like 'XMLHttpRequest') to ensure consistent and expected output, or document the current behavior clearly.

Suggested change
for (int i = 0; i < id.Length; i++)
{
if (i > 0 && char.IsUpper(id[i]))
{
sb.Append('-');
}
bool previousWasUpper = false;
for (int i = 0; i < id.Length; i++)
{
if (char.IsUpper(id[i]))
{
if (i > 0 && !previousWasUpper)
{
sb.Append('-');
}
previousWasUpper = true;
}
else
{
previousWasUpper = false;
}

Copilot uses AI. Check for mistakes.
sb.Append(char.ToLower(id[i]));
}

return sb.ToString();
}
}
}
40 changes: 40 additions & 0 deletions Smithy.Model/SmithyModelExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Linq;

namespace Smithy.Model
{
/// <summary>
/// Extension methods for SmithyModel to simplify shape access
/// </summary>
public static class SmithyModelExtensions
{
/// <summary>
/// Get a shape by its ID from the model
/// </summary>
/// <typeparam name="T">The type of shape to retrieve</typeparam>
/// <param name="model">The Smithy model</param>
/// <param name="shapeId">The ID of the shape to retrieve</param>
/// <returns>The shape with the specified ID, or null if not found</returns>
public static T GetShape<T>(this SmithyModel model, string shapeId) where T : Shape
{
if (model == null || string.IsNullOrEmpty(shapeId))
return null;

Check warning on line 21 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference return.

Check warning on line 21 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference return.

Check warning on line 21 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 21 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

return model.Shapes.OfType<T>().FirstOrDefault(s => s.Id == shapeId);

Check warning on line 23 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference return.

Check warning on line 23 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

/// <summary>
/// Get a shape by its ID from the model
/// </summary>
/// <param name="model">The Smithy model</param>
/// <param name="shapeId">The ID of the shape to retrieve</param>
/// <returns>The shape with the specified ID, or null if not found</returns>
public static Shape GetShape(this SmithyModel model, string shapeId)
{
if (model == null || string.IsNullOrEmpty(shapeId))
return null;

Check warning on line 35 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference return.

Check warning on line 35 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

return model.Shapes.FirstOrDefault(s => s.Id == shapeId);

Check warning on line 37 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / coverage

Possible null reference return.

Check warning on line 37 in Smithy.Model/SmithyModelExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}
}
}
Loading