From 09af4454368a89e6ebf31a55f4e8e2989ed75273 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Tue, 9 Nov 2021 01:44:31 +0100 Subject: [PATCH] Make sure that the /v1/command endpoint actually ignores the parameter default value during json serialization if its null, instead of making it an empty string --- src/Web/Controllers/Commands/CommandController.cs | 2 +- src/Web/Controllers/Commands/ResponseCommandParam.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Web/Controllers/Commands/CommandController.cs b/src/Web/Controllers/Commands/CommandController.cs index 8505698..52b2241 100644 --- a/src/Web/Controllers/Commands/CommandController.cs +++ b/src/Web/Controllers/Commands/CommandController.cs @@ -27,7 +27,7 @@ public class CommandController : ControllerBase Params = cmd.Parameters.Select(dict => new ResponseCommandParam() { Summary = dict.Value.Summary, - Default = dict.Value.DefaultValue, + Default = string.IsNullOrEmpty(dict.Value.DefaultValue) ? null : dict.Value.DefaultValue, Type = dict.Value.Type }).ToList() }); diff --git a/src/Web/Controllers/Commands/ResponseCommandParam.cs b/src/Web/Controllers/Commands/ResponseCommandParam.cs index 2acbca5..c99a113 100644 --- a/src/Web/Controllers/Commands/ResponseCommandParam.cs +++ b/src/Web/Controllers/Commands/ResponseCommandParam.cs @@ -8,7 +8,8 @@ public record ResponseCommandParam public string Summary { get; set; } [JsonPropertyName("default")] - public string Default { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Default { get; set; } [JsonPropertyName("type")] public string Type { get; set; }