Skip to content

Commit

Permalink
Fix OM to allow detection of missing keywords (#737)
Browse files Browse the repository at this point in the history
In order to allow the PaYamlParser to detect when a keyword is missing, we need to ensure value types are allowed to be set to null. Also, to reduce memory footprint, collections are allowed to be null too.
  • Loading branch information
joem-msft authored Feb 13, 2025
1 parent 68a1f10 commit 2832eba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/Persistence/PaYaml/Models/NamedObjectCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models;

public static class NamedObjectCollectionExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNullOrEmpty<TValue>([NotNullWhen(false)] this IReadOnlyNamedObjectCollection<TValue>? collection)
where TValue : notnull
{
return collection is null || collection.Count == 0;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static NamedObjectMapping<TValue>? EmptyToNull<TValue>(this NamedObjectMapping<TValue>? collection)
where TValue : notnull
{
return collection?.Count == 0 ? null : collection;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static NamedObjectSequence<TValue>? EmptyToNull<TValue>(this NamedObjectSequence<TValue>? collection)
where TValue : notnull
{
Expand Down
14 changes: 12 additions & 2 deletions src/Persistence/PaYaml/Models/SchemaV3/ComponentDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.SchemaV3;

public enum ComponentDefinitionType
{
/// <summary>
/// Indicates a value which has either not been set or has been determined to be invalid.
/// </summary>
Invalid = 0,

CanvasComponent,
CommandComponent,
}

public enum ComponentPropertyKind
{
/// <summary>
/// Indicates a value which has either not been set or has been determined to be invalid.
/// </summary>
Invalid = 0,

Input,
Output,
InputFunction,
Expand Down Expand Up @@ -58,7 +68,7 @@ public record ComponentDefinition : IPaControlInstanceContainer
public abstract record ComponentCustomPropertyBase
{
[YamlMember(Order = -9, DefaultValuesHandling = DefaultValuesHandling.Preserve)]
public required ComponentPropertyKind PropertyKind { get; init; }
public required ComponentPropertyKind? PropertyKind { get; init; }

[YamlMember(Order = -8)]
public string? DisplayName { get; init; }
Expand Down Expand Up @@ -90,7 +100,7 @@ public record ComponentCustomPropertyParameter()
{
public string? Description { get; init; }

public bool IsOptional { get; init; }
public bool? IsOptional { get; init; }

public PaYamlPropertyDataType? DataType { get; init; }

Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ControlInstance(string controlType)
}

[property: YamlMember(Alias = "Control")]
public required string ControlType { get; init; }
public required string? ControlType { get; init; }

public string? Variant { get; init; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum DataSourceType
public record DataSourceInstance
{
[YamlMember(DefaultValuesHandling = DefaultValuesHandling.Preserve)]
public required DataSourceType Type { get; init; }
public required DataSourceType? Type { get; init; }
public string? ConnectorId { get; init; }
public NamedObjectMapping<string>? Parameters { get; init; }
}
9 changes: 6 additions & 3 deletions src/Persistence/PaYaml/Models/SchemaV3/PaModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.SchemaV3;
public record PaModule
{
public AppInstance? App { get; init; }
public NamedObjectMapping<ComponentDefinition> ComponentDefinitions { get; init; } = new();
public NamedObjectMapping<ScreenInstance> Screens { get; init; } = new();
public NamedObjectMapping<DataSourceInstance> DataSources { get; init; } = new();

public NamedObjectMapping<ComponentDefinition>? ComponentDefinitions { get; init; }

public NamedObjectMapping<ScreenInstance>? Screens { get; init; }

public NamedObjectMapping<DataSourceInstance>? DataSources { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.SchemaV3;

public enum PaYamlPropertyDataType
{
/// <summary>
/// Indicates an data type which has either not been explicitly set or has been determined to be invalid.
/// </summary>
Invalid = 0,

/// <summary>
/// aka Void. Only valid for function return types which are allowed to have side effects.
/// </summary>
Expand Down

0 comments on commit 2832eba

Please # to comment.