Skip to content

Commit

Permalink
Fixes command examples on output with a rather ugly string modification
Browse files Browse the repository at this point in the history
  • Loading branch information
i8beef committed Jan 1, 2021
1 parent 3638536 commit 017de79
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using HomeAutio.Mqtt.GoogleHome.ActionFilters;
using HomeAutio.Mqtt.GoogleHome.Extensions;
using HomeAutio.Mqtt.GoogleHome.Models;
Expand Down Expand Up @@ -259,10 +260,34 @@ public IActionResult Examples([Required] string traitId)
var commandName = commandSchema.Command.ToEnumString();
foreach (var commandExample in commandSchema.Examples)
{
// Transform on the way out to keep pure examples in schemas
var wrappedExample = new StringBuilder();
wrappedExample.AppendLine("{");
wrappedExample.Append($" \"{commandName}\": ");

if (commandExample.Example == string.Empty)
{
wrappedExample.AppendLine("null");
}
else
{
var exampleLines = commandExample.Example.Split(Environment.NewLine);
for (var i = 0; i < exampleLines.Length; i++)
{
// Handle indent modification
if (i != 0)
wrappedExample.Append(" ");

wrappedExample.AppendLine(exampleLines[i]);
}
}

wrappedExample.Append("}");

commandExamples.Add(new SchemaExample
{
Comment = $"{commandName}<br/>{commandExample.Comment}",
Example = commandExample.Example
Example = wrappedExample.ToString()
});
}
}
Expand Down

0 comments on commit 017de79

Please sign in to comment.