Skip to content

Commit

Permalink
Move Yaml Validator into Persistence Part 1 (#697)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Petrochuk <[email protected]>
  • Loading branch information
abaskk-msft and petrochuk authored Jul 17, 2024
1 parent 34a336d commit 1cf22bb
Show file tree
Hide file tree
Showing 33 changed files with 58 additions and 264 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ jobs:
- name: Test - PAModel
run: dotnet bin/Debug/PAModelTests/PAModelTests.dll

- name: Test - YamlValidator
run: dotnet bin/Debug/YamlValidator.Tests/YamlValidator.Tests.dll

- name: Test - Persistence.Tests Yaml Files (ubuntu & macos)
run: ./scripts/PersistenceValidate.sh
if: ${{ runner.os != 'Windows' }}

- name: Test - Persistence.Tests Yaml Files (windows)
run: ./scripts/PersistenceValidate.ps1
if: ${{ runner.os == 'Windows' }}

- name: Restore workloads for samples
run: dotnet workload restore samples/MauiMsApp/MauiMsApp.csproj

Expand Down
23 changes: 0 additions & 23 deletions scripts/PersistenceValidate.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/PersistenceValidate.sh

This file was deleted.

13 changes: 0 additions & 13 deletions src/PASopa.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerPlatform.Pow
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence.Tests", "Persistence.Tests\Persistence.Tests.csproj", "{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YamlValidator", "YamlValidator\YamlValidator.csproj", "{F0AD11CE-E634-4945-A6B1-7866CDE0059C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YamlValidator.Tests", "YamlValidator.Tests\YamlValidator.Tests.csproj", "{8BA5DD4B-9423-4827-AF37-540E0300DB9A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7361DB16-D534-4E0E-8597-BE22317DEF47}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Expand Down Expand Up @@ -56,22 +52,13 @@ Global
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD}.Release|Any CPU.Build.0 = Release|Any CPU
{F0AD11CE-E634-4945-A6B1-7866CDE0059C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0AD11CE-E634-4945-A6B1-7866CDE0059C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0AD11CE-E634-4945-A6B1-7866CDE0059C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0AD11CE-E634-4945-A6B1-7866CDE0059C}.Release|Any CPU.Build.0 = Release|Any CPU
{8BA5DD4B-9423-4827-AF37-540E0300DB9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BA5DD4B-9423-4827-AF37-540E0300DB9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BA5DD4B-9423-4827-AF37-540E0300DB9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BA5DD4B-9423-4827-AF37-540E0300DB9A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8AD94CC0-7330-4880-A8E0-177B37CDB27B} = {4993E606-484B-46D9-892E-7AE9CE8D4423}
{8AB1C901-FE5E-44BF-AA21-B8F20A9D7CDD} = {4993E606-484B-46D9-892E-7AE9CE8D4423}
{8BA5DD4B-9423-4827-AF37-540E0300DB9A} = {4993E606-484B-46D9-892E-7AE9CE8D4423}
{7361DB16-D534-4E0E-8597-BE22317DEF47} = {794D8C68-BF6F-49C8-BCA5-AA52D8F45EF4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
1 change: 1 addition & 0 deletions src/Persistence.Tests/Persistence.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<None Include="_TestData\**\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

<None Include="..\schemas-tests\pa-yaml\v3.0\Examples\**\*.yaml" LinkBase="_TestData\SchemaV3_0\Examples\">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Persistence.Tests.YamlValidator;
public class ValidatorTest
{

private static readonly string _validPath = Path.Combine(".", "_TestData", "ValidYaml") +
private static readonly string _validPath = Path.Combine(".", "_TestData", "ValidatorTests", "ValidYaml") +
Path.DirectorySeparatorChar;

private static readonly string _invalidPath = Path.Combine(".", "_TestData", "InvalidYaml") +
private static readonly string _invalidPath = Path.Combine(".", "_TestData", "ValidatorTests", "InvalidYaml") +
Path.DirectorySeparatorChar;

private readonly JsonSchema _schema;
Expand All @@ -22,7 +22,7 @@ public class ValidatorTest
public ValidatorTest()
{
var schemaFileLoader = new SchemaLoader();
_schema = schemaFileLoader.Load(Constants.DefaultSchemaPath);
_schema = schemaFileLoader.Load();
var resultVerbosity = new VerbosityData(Constants.Verbose);
_yamlValidator = new Validator(resultVerbosity.EvalOptions, resultVerbosity.JsonOutputOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PublicSign>true</PublicSign>
<!-- Workaround for version range https://github.com/NuGet/Home/issues/11842 -->
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<NoWarn>$(NoWarn);NU1601</NoWarn>
<NoWarn>$(NoWarn);NU1601;CA1822</NoWarn>
</PropertyGroup>

<ItemGroup Label="Global usings">
Expand All @@ -43,6 +43,14 @@
<PackageReference Include="Microsoft.PowerFx.Core" Version="1.2.0" />
<PackageReference Include="YamlDotNet" Version="$(YamlDotNetVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
<PackageReference Include="JsonSchema.Net" Version="7.1.0" />
<PackageReference Include="Yaml2JsonNode" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
<Content Include="..\..\docs\pa.yaml-schema.json" Link="YamlValidator\schema\pa.yaml-schema.json" CopyToOutputDirectory="PreserveNewest" />
<Content Include="..\..\docs\subschemas\control-type-schema.json" Link="YamlValidator\schema\subschemas\control-type-schema.json" CopyToOutputDirectory="PreserveNewest" />
<Content Include="..\..\docs\subschemas\control-property-schema.json" Link="YamlValidator\schema\subschemas\control-property-schema.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;
public class SchemaLoader
{
private const string _schemaFolderPath = "subschemas";
private static readonly string _schemaPath = Path.Combine(".", "YamlValidator", "schema", "pa.yaml-schema.json");

public JsonSchema Load(string schemaPath)
public JsonSchema Load()
{
var node = JsonSchema.FromFile(schemaPath);
var schemaFolder = Path.GetDirectoryName(schemaPath);
var node = JsonSchema.FromFile(_schemaPath);
var schemaFolder = Path.GetDirectoryName(_schemaPath);
var subschemaPaths = Directory.GetFiles($@"{schemaFolder}{Path.DirectorySeparatorChar}{_schemaFolderPath}",
$"*{Constants.JsonFileExtension}");

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public class Orchestrator
public class ValidationProcessor
{
private readonly YamlLoader _fileLoader;
private readonly SchemaLoader _schemaLoader;
private readonly Validator _validator;

public Orchestrator(YamlLoader fileLoader, SchemaLoader schemaLoader, Validator validator)
public ValidationProcessor(YamlLoader fileLoader, SchemaLoader schemaLoader, Validator validator)
{
_fileLoader = fileLoader;
_schemaLoader = schemaLoader;
Expand All @@ -18,12 +18,11 @@ public Orchestrator(YamlLoader fileLoader, SchemaLoader schemaLoader, Validator

public void RunValidation(ValidationRequest inputData)
{
var schemaPath = inputData.SchemaPath;
var path = inputData.FilePath;
var pathType = inputData.FilePathType;

var yamlData = _fileLoader.Load(path, pathType);
var serializedSchema = _schemaLoader.Load(schemaPath);
var serializedSchema = _schemaLoader.Load();

foreach (var yamlFileData in yamlData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public readonly record struct ValidationRequest(string FilePath, string SchemaPath, string FilePathType);
public readonly record struct ValidationRequest(string FilePath, string FilePathType);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions src/Persistence/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"version": 1,
"dependencies": {
"net8.0": {
"JsonSchema.Net": {
"type": "Direct",
"requested": "[7.1.0, )",
"resolved": "7.1.0",
"contentHash": "4DmCZQdVLNolzghMVK1oO49jZpvx7wVCP3OQEzxU5GK/OEhHcg+CAiAR8P/z69PT7STEIlguxb35nkFndZl2WA==",
"dependencies": {
"JsonPointer.Net": "5.0.0"
}
},
"Microsoft.Extensions.Logging": {
"type": "Direct",
"requested": "[8.0.0, )",
Expand Down Expand Up @@ -30,12 +39,40 @@
"System.Collections.Immutable": "6.0.0"
}
},
"Yaml2JsonNode": {
"type": "Direct",
"requested": "[2.1.0, )",
"resolved": "2.1.0",
"contentHash": "7rjrWyPVZGnd/udlNDAZWg24+4LMltQq1CJLKpoGA1Ee8YVVtqoqAWfdB2U0KhkkdBijPd694VIfdACvSLX9/A==",
"dependencies": {
"YamlDotNet": "15.1.2"
}
},
"YamlDotNet": {
"type": "Direct",
"requested": "[15.1.6, )",
"resolved": "15.1.6",
"contentHash": "T/cQEK/KHK96Q8kytJ4iUGDXg1/fj2Qtk6rCQeIlHYU1zTeyGVHW0QNZgREQyxZpygGMDMmrXNWt0sj5TsQnjA=="
},
"Humanizer.Core": {
"type": "Transitive",
"resolved": "2.14.1",
"contentHash": "lQKvtaTDOXnoVJ20ibTuSIOf2i0uO0MPbDhd1jm238I+U/2ZnRENj0cktKZhtchBMtCUSRQ5v4xBCUbKNmyVMw=="
},
"Json.More.Net": {
"type": "Transitive",
"resolved": "2.0.1.2",
"contentHash": "uF3QeiaXEfH92emz0/BWUiNtMSfxIIvgynuB0Bf1vF4s8eWTcZitBx9l+g/FDaJk5XxqBv9buQXizXKQcXFG1w=="
},
"JsonPointer.Net": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "fm4T5w20AY6C+p5/pJr0vrXRNGgtSfHl34I1LxC9zdPwS9S3j0GiR1Mz/CVPWKDXXGDpCt1APHpCq7kn5adCfA==",
"dependencies": {
"Humanizer.Core": "2.14.1",
"Json.More.Net": "2.0.1.2"
}
},
"Microsoft.Bcl.AsyncInterfaces": {
"type": "Transitive",
"resolved": "6.0.0",
Expand Down
36 changes: 0 additions & 36 deletions src/YamlValidator.Tests/YamlValidator.Tests.csproj

This file was deleted.

101 changes: 0 additions & 101 deletions src/YamlValidator/InputProcessor.cs

This file was deleted.

Loading

0 comments on commit 1cf22bb

Please sign in to comment.