Skip to content

Commit

Permalink
Directly pass through custom page schema files, and handle any valida…
Browse files Browse the repository at this point in the history
…tion in canvas (#439)

## Problem

Related to microsoft/Power-Fx#663, we're consolidating the type definition logic for this, and using yaml as the native format for it in the .msapp. As such, the .PALT tool does not need to do anything special to handle this file. 

## Solution
Removes special handling for schema.yaml

## Changes
Removes special handling for schema.yaml, associated POCOs, and passes the value through as text. 

## Validation
Testing integration with related changes is ongoing and this will not be checked in until all are ready.
  • Loading branch information
lesaltzm authored Sep 26, 2022
1 parent 43a2d91 commit 7fb6c53
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 95 deletions.
9 changes: 5 additions & 4 deletions src/PAModel/CanvasDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public class CanvasDocument
internal TemplatesJson _templates;
internal ThemesJson _themes;
internal ResourcesJson _resourcesJson;
internal ParameterSchema _parameterSchema;

// Dictionary with input schemas for custom pages used in the app through Navigate function, key is custom page logical name, value is parameter schema for that page
internal Dictionary<string, ParameterSchema> _customPageInputsMetadata;
// Yaml strings, handled by Canvas without interaction in PALT
internal string _parameterSchema;
internal string _customPageInputsMetadata;

internal AppCheckerResultJson _appCheckerResultJson;
internal Dictionary<string, PcfControl> _pcfControls = new Dictionary<string, PcfControl>(StringComparer.OrdinalIgnoreCase);

Expand Down Expand Up @@ -297,7 +298,7 @@ internal CanvasDocument(CanvasDocument other)
_header = other._header.JsonClone();
_properties = other._properties.JsonClone();
_parameterSchema = other._parameterSchema.JsonClone();
_customPageInputsMetadata = other._customPageInputsMetadata.JsonClone();
_customPageInputsMetadata = other._customPageInputsMetadata;
_publishInfo = other._publishInfo.JsonClone();
_templates = other._templates.JsonClone();
_themes = other._themes.JsonClone();
Expand Down
72 changes: 0 additions & 72 deletions src/PAModel/Schemas/ParameterSchema.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/PAModel/Serializers/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enum FileKind
AppTestParentControl,

// Schema.yaml describing app's parameters at top level.
Schema,
Defines,

// Custom page inputs for outbound custom page navigate calls.
CustomPageInputs,
Expand Down Expand Up @@ -121,7 +121,7 @@ public static FileEntry FromZip(ZipArchiveEntry z, string name = null)
{"Entities.json", FileKind.OldEntityJSon },
{"Properties.json", FileKind.Properties },
{"Header.json", FileKind.Header},
{"Schema.yaml", FileKind.Schema },
{"Defines.fx.yaml", FileKind.Defines },
{CustomPagesMetadataFileName, FileKind.CustomPageInputs },
{ChecksumMaker.ChecksumName, FileKind.Checksum },
{"AppCheckerResult.sarif", FileKind.AppCheckerResult },
Expand Down
30 changes: 25 additions & 5 deletions src/PAModel/Serializers/MsAppSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ private static T ToObject<T>(ZipArchiveEntry entry)
}
}


private static string AsString(ZipArchiveEntry entry)
{
using var stream = entry.Open();
using var textReader = new StreamReader(stream);
return textReader.ReadToEnd();
}

public static CanvasDocument Load(Stream streamToMsapp, ErrorContainer errors)
{
if (streamToMsapp == null)
Expand Down Expand Up @@ -124,11 +132,15 @@ public static CanvasDocument Load(Stream streamToMsapp, ErrorContainer errors)
dcsources = ToObject<DataComponentSourcesJson>(entry);
break;

case FileKind.Schema:
app._parameterSchema = ToObject<ParameterSchema>(entry);
case FileKind.Defines:
// We do not interact with this .yaml file from the .msapp, it can be passed straight through as text
// Validation is done in Canvas
app._parameterSchema = AsString(entry);
break;
case FileKind.CustomPageInputs:
app._customPageInputsMetadata = ToObject<Dictionary<string, ParameterSchema>>(entry);
// We do not interact with this .yaml file from the .msapp, it can be passed straight through as text
// Validation is done in Canvas
app._customPageInputsMetadata = AsString(entry);
break;

case FileKind.Properties:
Expand Down Expand Up @@ -611,12 +623,20 @@ private static IEnumerable<FileEntry> GetMsAppFiles(this CanvasDocument app, Err

if (app._parameterSchema != null)
{
yield return ToFile(FileKind.Schema, app._parameterSchema);
yield return new FileEntry
{
Name = FileEntry.GetFilenameForKind(FileKind.Defines),
RawBytes = Encoding.UTF8.GetBytes(app._parameterSchema)
};
}

if (app._customPageInputsMetadata != null)
{
yield return ToFile(FileKind.CustomPageInputs, app._customPageInputsMetadata);
yield return new FileEntry
{
Name = FileEntry.GetFilenameForKind(FileKind.CustomPageInputs),
RawBytes = Encoding.UTF8.GetBytes(app._customPageInputsMetadata)
};
}

var (publishInfo, logoFile) = app.TransformLogoOnSave();
Expand Down
18 changes: 9 additions & 9 deletions src/PAModel/Serializers/SourceSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ public static CanvasDocument LoadFromSource(string directory2, ErrorContainer er
{
switch (file.Kind)
{
case FileKind.Schema:
app._parameterSchema = file.ToObject<ParameterSchema>();
case FileKind.Defines:
// We do not interact with this .yaml file from the .msapp, it can be passed straight through as text
// Validation is done in Canvas
app._parameterSchema = file.GetContents();
break;
}
}
Expand All @@ -163,7 +165,7 @@ public static CanvasDocument LoadFromSource(string directory2, ErrorContainer er
LoadPcfControlTemplateFiles(errors, app, Path.Combine(directory2, PackagesDir, PcfControlTemplatesDir));

// Load used custom pages schema metadata
LoadCustomPagesSchemaMetadata(errors, app, Path.Combine(directory2, PackagesDir, FileEntry.CustomPagesMetadataFileName));
LoadCustomPagesSchemaMetadata(app, Path.Combine(directory2, PackagesDir, FileEntry.CustomPagesMetadataFileName));

foreach (var file in dir.EnumerateFiles(EntropyDir))
{
Expand Down Expand Up @@ -287,8 +289,6 @@ public static CanvasDocument Create(string appName, string packagesPath, IList<s

app._properties = DocumentPropertiesJson.CreateDefault(appName);
app._header = HeaderJson.CreateDefault();
app._parameterSchema = new ParameterSchema();
app._customPageInputsMetadata = new Dictionary<string, ParameterSchema>();

LoadTemplateFiles(errors, app, packagesPath, out var loadedTemplates);
app._entropy = new Entropy();
Expand Down Expand Up @@ -346,12 +346,12 @@ private static void LoadPcfControlTemplateFiles(ErrorContainer errors, CanvasDoc
}
}

private static void LoadCustomPagesSchemaMetadata(ErrorContainer errors, CanvasDocument app, string custompagesMetadataPath)
private static void LoadCustomPagesSchemaMetadata(CanvasDocument app, string custompagesMetadataPath)
{
if (File.Exists(custompagesMetadataPath))
{
DirectoryReader.Entry file = new DirectoryReader.Entry(custompagesMetadataPath);
app._customPageInputsMetadata = file.ToObject<Dictionary<string, ParameterSchema>>();
app._customPageInputsMetadata = file.GetContents();
}
}

Expand Down Expand Up @@ -548,7 +548,7 @@ public static void SaveAsSource(CanvasDocument app, string directory2, ErrorCont

if (app._customPageInputsMetadata != null)
{
dir.WriteAllJson(PackagesDir, FileKind.CustomPageInputs, app._customPageInputsMetadata);
dir.WriteAllText(PackagesDir, FileEntry.GetFilenameForKind(FileKind.CustomPageInputs), app._customPageInputsMetadata);
}

// Also add Screen and App templates (not xml, constructed in code on the server)
Expand Down Expand Up @@ -644,7 +644,7 @@ public static void SaveAsSource(CanvasDocument app, string directory2, ErrorCont

if (app._parameterSchema != null)
{
dir.WriteAllJson("", FileKind.Schema, app._parameterSchema);
dir.WriteAllText("", FileEntry.GetFilenameForKind(FileKind.Defines), app._parameterSchema);
}

var manifest = new CanvasManifestJson
Expand Down
Binary file removed src/PAModelTests/Apps/TestNavigatePageInputs.msapp
Binary file not shown.
3 changes: 0 additions & 3 deletions src/PAModelTests/PublicSurfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public void Test()
$"Microsoft.PowerPlatform.YamlConverter",
$"Microsoft.PowerPlatform.YamlPocoSerializer",
$"Microsoft.PowerPlatform.Formulas.Tools.Yaml.YamlWriter",

// Public schemas
$"Microsoft.PowerPlatform.Formulas.Tools.Schemas.ParameterSchema"
};

StringBuilder sb = new StringBuilder();
Expand Down

0 comments on commit 7fb6c53

Please sign in to comment.