Skip to content

Commit

Permalink
Minor changes to output (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochuk authored Jun 25, 2024
1 parent 1138d3b commit 0bffc34
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 71 deletions.
42 changes: 22 additions & 20 deletions src/PAModel/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,48 @@
},
"Microsoft.Extensions.DependencyInjection": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "elNeOmkeX3eDVG6pYVeV82p29hr+UKDaBhrZyWvWLw/EVZSYEkZlQdkp0V39k/Xehs2Qa0mvoCvkVj3eQxNQ1Q==",
"resolved": "8.0.0",
"contentHash": "V8S3bsm50ig6JSyrbcJJ8bW2b9QLGouz+G1miK3UTaOWmMtFwNNNzUf4AleyDWUmTrWMLNnFSLEQtxmxgNQnNQ==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0"
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "h3j/QfmFN4S0w4C2A6X7arXij/M/OVw3uQHSOFxnND4DyAzO1F9eMX7Eti7lU/OkSthEE0WzRsfT/Dmx86jzCw=="
"resolved": "8.0.0",
"contentHash": "cjWrLkJXK0rs4zofsK4bSdg+jhDLTaxrkXu4gS6Y7MAlCvRyNNgwY/lJi5RDlQOnSZweHqoyvgvbdvQsRIW+hg=="
},
"Microsoft.Extensions.Logging": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "Nw2muoNrOG5U5qa2ZekXwudUn2BJcD41e65zwmDHb1fQegTX66UokLWZkJRpqSSHXDOWZ5V0iqhbxOEky91atA==",
"resolved": "8.0.0",
"contentHash": "tvRkov9tAJ3xP51LCv3FJ2zINmv1P8Hi8lhhtcKGqM+ImiTCC84uOPEI4z8Cdq2C3o9e+Aa0Gw0rmrsJD77W+w==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "7.0.0",
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0",
"Microsoft.Extensions.Logging.Abstractions": "7.0.0",
"Microsoft.Extensions.Options": "7.0.0"
"Microsoft.Extensions.DependencyInjection": "8.0.0",
"Microsoft.Extensions.Logging.Abstractions": "8.0.0",
"Microsoft.Extensions.Options": "8.0.0"
}
},
"Microsoft.Extensions.Logging.Abstractions": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "kmn78+LPVMOWeITUjIlfxUPDsI0R6G0RkeAMBmQxAJ7vBJn4q2dTva7pWi65ceN5vPGjJ9q/Uae2WKgvfktJAw=="
"resolved": "8.0.0",
"contentHash": "arDBqTgFCyS0EvRV7O3MZturChstm50OJ0y9bDJvAcmEPJm0FFpFyjU/JLYyStNGGey081DvnQYlncNX5SJJGA==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
"Microsoft.Extensions.Options": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "lP1yBnTTU42cKpMozuafbvNtQ7QcBjr/CcK3bYOGEMH55Fjt+iecXjT6chR7vbgCMqy3PG3aNQSZgo/EuY/9qQ==",
"resolved": "8.0.0",
"contentHash": "JOVOfqpnqlVLUzINQ2fox8evY2SKLYJ3BV8QDe/Jyp21u1T7r45x/R/5QdteURMR5r01GxeJSBBUOCOyaNXA3g==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0",
"Microsoft.Extensions.Primitives": "7.0.0"
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0",
"Microsoft.Extensions.Primitives": "8.0.0"
}
},
"Microsoft.Extensions.Primitives": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "um1KU5kxcRp3CNuI8o/GrZtD4AIOXDk+RLsytjZ9QPok3ttLUelLKpilVPuaFT3TFjOhSibUAso0odbOaCDj3Q=="
"resolved": "8.0.0",
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g=="
},
"Microsoft.PowerFx.Core": {
"type": "Transitive",
Expand Down Expand Up @@ -118,7 +120,7 @@
"microsoft.powerplatform.powerapps.persistence": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.Logging": "[7.0.0, )",
"Microsoft.Extensions.Logging": "[8.0.0, )",
"Microsoft.PowerFx.Core": "[1.2.0, )",
"YamlDotNet": "[15.1.6, )"
}
Expand Down
42 changes: 22 additions & 20 deletions src/Persistence/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
"net8.0": {
"Microsoft.Extensions.Logging": {
"type": "Direct",
"requested": "[7.0.0, )",
"resolved": "7.0.0",
"contentHash": "Nw2muoNrOG5U5qa2ZekXwudUn2BJcD41e65zwmDHb1fQegTX66UokLWZkJRpqSSHXDOWZ5V0iqhbxOEky91atA==",
"requested": "[8.0.0, )",
"resolved": "8.0.0",
"contentHash": "tvRkov9tAJ3xP51LCv3FJ2zINmv1P8Hi8lhhtcKGqM+ImiTCC84uOPEI4z8Cdq2C3o9e+Aa0Gw0rmrsJD77W+w==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection": "7.0.0",
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0",
"Microsoft.Extensions.Logging.Abstractions": "7.0.0",
"Microsoft.Extensions.Options": "7.0.0"
"Microsoft.Extensions.DependencyInjection": "8.0.0",
"Microsoft.Extensions.Logging.Abstractions": "8.0.0",
"Microsoft.Extensions.Options": "8.0.0"
}
},
"Microsoft.Net.Compilers.Toolset.Framework": {
Expand Down Expand Up @@ -44,35 +43,38 @@
},
"Microsoft.Extensions.DependencyInjection": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "elNeOmkeX3eDVG6pYVeV82p29hr+UKDaBhrZyWvWLw/EVZSYEkZlQdkp0V39k/Xehs2Qa0mvoCvkVj3eQxNQ1Q==",
"resolved": "8.0.0",
"contentHash": "V8S3bsm50ig6JSyrbcJJ8bW2b9QLGouz+G1miK3UTaOWmMtFwNNNzUf4AleyDWUmTrWMLNnFSLEQtxmxgNQnNQ==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0"
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
"Microsoft.Extensions.DependencyInjection.Abstractions": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "h3j/QfmFN4S0w4C2A6X7arXij/M/OVw3uQHSOFxnND4DyAzO1F9eMX7Eti7lU/OkSthEE0WzRsfT/Dmx86jzCw=="
"resolved": "8.0.0",
"contentHash": "cjWrLkJXK0rs4zofsK4bSdg+jhDLTaxrkXu4gS6Y7MAlCvRyNNgwY/lJi5RDlQOnSZweHqoyvgvbdvQsRIW+hg=="
},
"Microsoft.Extensions.Logging.Abstractions": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "kmn78+LPVMOWeITUjIlfxUPDsI0R6G0RkeAMBmQxAJ7vBJn4q2dTva7pWi65ceN5vPGjJ9q/Uae2WKgvfktJAw=="
"resolved": "8.0.0",
"contentHash": "arDBqTgFCyS0EvRV7O3MZturChstm50OJ0y9bDJvAcmEPJm0FFpFyjU/JLYyStNGGey081DvnQYlncNX5SJJGA==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0"
}
},
"Microsoft.Extensions.Options": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "lP1yBnTTU42cKpMozuafbvNtQ7QcBjr/CcK3bYOGEMH55Fjt+iecXjT6chR7vbgCMqy3PG3aNQSZgo/EuY/9qQ==",
"resolved": "8.0.0",
"contentHash": "JOVOfqpnqlVLUzINQ2fox8evY2SKLYJ3BV8QDe/Jyp21u1T7r45x/R/5QdteURMR5r01GxeJSBBUOCOyaNXA3g==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0",
"Microsoft.Extensions.Primitives": "7.0.0"
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0",
"Microsoft.Extensions.Primitives": "8.0.0"
}
},
"Microsoft.Extensions.Primitives": {
"type": "Transitive",
"resolved": "7.0.0",
"contentHash": "um1KU5kxcRp3CNuI8o/GrZtD4AIOXDk+RLsytjZ9QPok3ttLUelLKpilVPuaFT3TFjOhSibUAso0odbOaCDj3Q=="
"resolved": "8.0.0",
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g=="
},
"Microsoft.PowerFx.Transport.Attributes": {
"type": "Transitive",
Expand Down
3 changes: 1 addition & 2 deletions src/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<CoverletCollectorVersion>6.0.0</CoverletCollectorVersion>
<FluentAssertionsVersion>6.12.0</FluentAssertionsVersion>
<MinVerVersion>4.3.0</MinVerVersion>
<MicrosoftExtensionsLoggingVersion>7.0.0</MicrosoftExtensionsLoggingVersion>

<MicrosoftExtensionsLoggingVersion>8.0.0</MicrosoftExtensionsLoggingVersion>
<!-- WARNING: Do not update Moq library past 4.20.0 due to privacy issues: https://github.com/devlooped/moq/issues/1372 -->
<MoqVersion>4.16.0</MoqVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/YamlValidator/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Licensed under the MIT License.

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;
public class Constants

public static class Constants
{
public const string FileTypeName = "file";
public const string FolderTypeName = "folder";
public const string YamlFileExtension = ".yaml";
public const string YmlFileExtension = ".yml";
public const string YamlFileExtension = ".pa.yaml";
public const string JsonFileExtension = ".json";

public const string Verbose = "verbose";
Expand Down
23 changes: 11 additions & 12 deletions src/YamlValidator/InputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.CommandLine;

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public class InputProcessor
{

private static void ProcessFiles(string path, string schema, string pathType)
{
// read only records
Expand All @@ -19,6 +19,7 @@ private static void ProcessFiles(string path, string schema, string pathType)
var orchestrator = new Orchestrator(fileLoader, schemaLoader, validator);
orchestrator.RunValidation(filePathInfo);
}

public static RootCommand GetRootCommand()
{

Expand All @@ -33,33 +34,32 @@ public static RootCommand GetRootCommand()
var inputFilePath = result.GetValueForOption(pathOption);

// either file or folder must be passed
var pathType = string.Empty;
if (string.IsNullOrEmpty(inputFilePath))
if (string.IsNullOrWhiteSpace(inputFilePath))
{
result.ErrorMessage = "The input is invalid, input must be a filepath to a yaml file \\" +
"or a folder path to a folder of yaml files";
}
else if (!Directory.Exists(inputFilePath) && !File.Exists(inputFilePath))
{
result.ErrorMessage = "The input path does not exist";
result.ErrorMessage = $"The path '{inputFilePath}' does not exist";
}
else if (Directory.Exists(inputFilePath))
{
if (Directory.GetFiles(inputFilePath, $"*{Constants.YamlFileExtension}").Length == 0)
{
result.ErrorMessage = "The input folder does not contain any yaml files";
result.ErrorMessage = $"The folder '{inputFilePath}' does not contain any yaml files";
}
}
else if (File.Exists(inputFilePath))
{
if (Path.GetExtension(inputFilePath) != Constants.YamlFileExtension)
if (!inputFilePath.EndsWith(Constants.YamlFileExtension, StringComparison.OrdinalIgnoreCase))
{
result.ErrorMessage = "The input file must be a yaml file";
result.ErrorMessage = $"The file '{inputFilePath}' must be a '{Constants.YamlFileExtension}' file";
}
}
});

// assume local schema file exists in nuget package, use relative filepath for now
// assume local schema file exists in NuGet package, use relative filepath for now
var schemaOption = new Option<string>(
name: "--schema",
description: "The path to the schema json file",
Expand All @@ -79,15 +79,15 @@ public static RootCommand GetRootCommand()
}
else if (!File.Exists(schemaPath))
{
result.ErrorMessage = "The schema file does not exist";
result.ErrorMessage = $"The schema file '{schemaPath}' does not exist";
}
});

// define root
var rootCommand = new RootCommand("YAML validator cli-tool");
var rootCommand = new RootCommand("Power Apps YAML validator command line tool");

// validate command
var validateCommand = new Command("validate", "Validate the input yaml file")
var validateCommand = new Command("validate", "Validate the input Power Apps YAML file")
{
pathOption,
schemaOption
Expand All @@ -104,6 +104,5 @@ public static RootCommand GetRootCommand()
rootCommand.AddCommand(validateCommand);

return rootCommand;

}
}
9 changes: 4 additions & 5 deletions src/YamlValidator/Orchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public class Orchestrator
{
private readonly YamlLoader _fileLoader;
Expand All @@ -26,17 +27,15 @@ public void RunValidation(ValidationRequest inputData)

foreach (var yamlFileData in yamlData)
{
Console.WriteLine($"Validation for {yamlFileData.Key}");
Console.WriteLine($"Validating '{yamlFileData.Key}'");
var result = _validator.Validate(serializedSchema, yamlFileData.Value);
Console.WriteLine($"Validation Result: {result.SchemaValid}");
Console.WriteLine($"Validation {(result.SchemaValid ? "Passed" : "Failed")}");

foreach (var error in result.TraversalResults)
{
Console.WriteLine($"{error}");
}
Console.WriteLine();
}
}



}
2 changes: 1 addition & 1 deletion src/YamlValidator/SchemaLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Json.Schema;

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public class SchemaLoader
{
private const string _schemaFolderPath = "subschemas";
Expand All @@ -23,6 +24,5 @@ public JsonSchema Load(string schemaPath)

return node;
}

}

1 change: 1 addition & 0 deletions src/YamlValidator/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using YamlDotNet.RepresentationModel;

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public class Utility
{
public static string ReadFileData(string filePath)
Expand Down
1 change: 1 addition & 0 deletions src/YamlValidator/ValidationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// Licensed under the MIT License.

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;

public readonly record struct ValidationRequest(string FilePath, string SchemaPath, string FilePathType);
6 changes: 2 additions & 4 deletions src/YamlValidator/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ public class Validator
private readonly EvaluationOptions _verbosityOptions;
private readonly JsonSerializerOptions _serializerOptions;


public Validator(EvaluationOptions options, JsonSerializerOptions resultSerializeOptions)
{
// to do: add verbosity flag and allow users to choose verbosity of evaluation
_verbosityOptions = options;
_serializerOptions = resultSerializeOptions;

}

public ValidatorResults Validate(JsonSchema schema, string yamlFileData)
Expand All @@ -34,7 +32,7 @@ public ValidatorResults Validate(JsonSchema schema, string yamlFileData)
var results = schema.Evaluate(jsonData, _verbosityOptions);

// not used but may help if we ever need to serialize the evaluation results into json format to feed into
// a vscode extension or other tool
// a VSCode extension or other tool
var output = JsonSerializer.Serialize(results, _serializerOptions);

var schemaValidity = results.IsValid;
Expand All @@ -51,9 +49,9 @@ public ValidatorResults Validate(JsonSchema schema, string yamlFileData)
yamlValidatorErrors.Add(new ValidatorError(trace));
}
}

IReadOnlyList<ValidatorError> fileErrors = yamlValidatorErrors;
var finalResults = new ValidatorResults(results.IsValid, fileErrors);
return finalResults;

}
}
1 change: 1 addition & 0 deletions src/YamlValidator/ValidatorError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public ValidatorError(EvaluationResults results)
SchemaPath = results.EvaluationPath.ToString();
Errors = results.Errors;
}

public ValidatorError(string error)
{
InstanceLocation = "";
Expand Down
1 change: 0 additions & 1 deletion src/YamlValidator/ValidatorResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ public ValidatorResults(bool schemaValid, IReadOnlyList<ValidatorError> traversa
{
SchemaValid = schemaValid;
TraversalResults = traversalResults;

}
}
2 changes: 0 additions & 2 deletions src/YamlValidator/YamlLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;
public class YamlLoader
{

public IReadOnlyDictionary<string, string> Load(string filePath, string pathType)
{
var deserializedYaml = new Dictionary<string, string>();
Expand All @@ -29,5 +28,4 @@ public IReadOnlyDictionary<string, string> Load(string filePath, string pathType

return new ReadOnlyDictionary<string, string>(deserializedYaml);
}

}
2 changes: 1 addition & 1 deletion src/YamlValidator/YamlValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JsonSchema.Net" Version="7.0.3" />
<PackageReference Include="JsonSchema.Net" Version="7.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Yaml2JsonNode" Version="2.1.0" />
Expand Down

0 comments on commit 0bffc34

Please sign in to comment.