Skip to content

Commit

Permalink
Fixes issues with schemas that don't specify a wrapping type
Browse files Browse the repository at this point in the history
  • Loading branch information
i8beef committed Jan 1, 2021
1 parent 57cbe4b commit a7f737f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class JsonSchemaExtensionsTests
[Theory]
[InlineData(TraitType.OnOff, null, GoogleType.Unknown)]
[InlineData(TraitType.OnOff, "on", GoogleType.Bool)]
[InlineData(TraitType.OpenClose, "openPercent", GoogleType.Numeric)]
[InlineData(TraitType.Modes, "currentModeSettings.test", GoogleType.String)]
[InlineData(TraitType.ColorSetting, "color.spectrumHsv.saturation", GoogleType.Numeric)]
[InlineData(TraitType.EnergyStorage, "capacityRemaining.[0].rawValue", GoogleType.Numeric)]
Expand All @@ -29,6 +30,7 @@ public void GetGoogleTypeForFlattenedPathReturns(TraitType traitType, string tar

[Theory]
[InlineData(TraitType.OnOff, "on")]
[InlineData(TraitType.OpenClose, "openPercent")]
[InlineData(TraitType.ColorSetting, "color.spectrumHsv.saturation")]
[InlineData(TraitType.EnergyStorage, "capacityRemaining.[0].rawValue")]
public void ValidateFlattenedPathReturnsTrue(TraitType traitType, string target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public static NJsonSchema.JsonSchema GetByFlattenedPath(this NJsonSchema.JsonSch
switch (schema.Type)
{
case NJsonSchema.JsonObjectType.Object:
case NJsonSchema.JsonObjectType.None:
// Treat unspecified types as possible subschemas
if (currentPathFragment == null)
return null;

Expand Down
34 changes: 17 additions & 17 deletions src/HomeAutio.Mqtt.GoogleHome/Models/Schema/CommandSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,8 @@ private static void ChangeLeafNodesToString(JsonSchema schema)
{
switch (schema.Type)
{
case JsonObjectType.Array:
if (schema.Item != null)
{
// Default single type array
ChangeLeafNodesToString(schema.Item);
}
else
{
// Tuple handling
foreach (var tupleSchema in schema.Items)
{
ChangeLeafNodesToString(tupleSchema);
}
}

break;
case JsonObjectType.Object:
case JsonObjectType.None:
foreach (var property in schema.Properties)
{
ChangeLeafNodesToString(property.Value);
Expand All @@ -138,7 +123,22 @@ private static void ChangeLeafNodesToString(JsonSchema schema)
}

break;
case JsonObjectType.None:
case JsonObjectType.Array:
if (schema.Item != null)
{
// Default single type array
ChangeLeafNodesToString(schema.Item);
}
else
{
// Tuple handling
foreach (var tupleSchema in schema.Items)
{
ChangeLeafNodesToString(tupleSchema);
}
}

break;
case JsonObjectType.Integer:
case JsonObjectType.Number:
case JsonObjectType.Boolean:
Expand Down

0 comments on commit a7f737f

Please sign in to comment.