Skip to content

Fixes generating patch operations in TSP. Closes #1172 #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025
Merged
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
12 changes: 10 additions & 2 deletions dev-proxy-plugins/TypeSpec/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ override public string ToString()
sb.AppendLine($"@useAuth({Auth.ToString()})");
}
sb.Append($"op {Name}(");
sb.AppendJoin(", ", Parameters.Select(p => p.ToString()));
sb.AppendJoin(", ", Parameters.Select(p => p.ToString(this)));
sb.Append("): ");
sb.AppendJoin(" | ", Responses.Select(r => r.GetModelName()));
sb.Append(';');
Expand Down Expand Up @@ -266,11 +266,19 @@ internal class Parameter
public required string Name { get; init; }
public string? Value { get; init; }

override public string ToString()
public override string ToString()
{
throw new NotImplementedException("Use ToString(Operation op) instead.");
}

public string ToString(Operation op)
{
var value = Value?.IndexOfAny([' ', '/', '-', ';']) == -1
? Value
: $"\"{Value}\"";
value = op.Method == HttpVerb.Patch && In == ParameterLocation.Body
? $"MergePatchUpdate<{value}>"
: value;
if (Name.IndexOf('-') > -1)
{
var target = Name;
Expand Down