From 6a3367f1a4cb7a761a15a4508468be9453962c92 Mon Sep 17 00:00:00 2001 From: Waldek Mastykarz Date: Mon, 12 May 2025 15:38:31 +0200 Subject: [PATCH] Fixes generating patch operations in TSP. Closes #1172 --- dev-proxy-plugins/TypeSpec/Http.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dev-proxy-plugins/TypeSpec/Http.cs b/dev-proxy-plugins/TypeSpec/Http.cs index 93c4cb19..0bf558fc 100644 --- a/dev-proxy-plugins/TypeSpec/Http.cs +++ b/dev-proxy-plugins/TypeSpec/Http.cs @@ -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(';'); @@ -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;