From 1fca2fa08a7f39037611c663ce2d3a98e9e1d866 Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Thu, 4 May 2023 16:26:01 +1200 Subject: [PATCH 1/7] Updated JsonSchema.Net to latest (major bump) --- ...crosoft.PowerShell.Commands.Utility.csproj | 2 +- .../commands/utility/TestJsonCommand.cs | 39 ++++++------ .../resources/TestJsonCmdletStrings.resx | 62 +++++++++---------- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj index ea5e0bd22a1..e465aa03f33 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj +++ b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj @@ -35,7 +35,7 @@ - + diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs index 4a6e11a9633..8595471548d 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs @@ -239,29 +239,17 @@ protected override void ProcessRecord() if (_jschema != null) { - var validationResults = _jschema.Validate(parsedJson, new ValidationOptions { OutputFormat = OutputFormat.Basic }); - result = validationResults.IsValid; + var evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List }); + result = evaluationResults.IsValid; if (!result) { - if (validationResults.Message != null) - { - Exception exception = new(string.Format(TestJsonCmdletStrings.InvalidJsonAgainstSchemaDetailed, validationResults.Message, validationResults.InstanceLocation)); - ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchemaDetailed", ErrorCategory.InvalidData, null); - WriteError(errorRecord); - } + HandleValidationErrors(evaluationResults); - if (validationResults.HasNestedResults) + if (evaluationResults.HasDetails) { - foreach (var nestedResult in validationResults.NestedResults) + foreach (var nestedResult in evaluationResults.Details) { - if (nestedResult.Message == null) - { - continue; - } - - Exception exception = new(string.Format(TestJsonCmdletStrings.InvalidJsonAgainstSchemaDetailed, nestedResult.Message, nestedResult.InstanceLocation)); - ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchemaDetailed", ErrorCategory.InvalidData, null); - WriteError(errorRecord); + HandleValidationErrors(nestedResult); } } } @@ -284,5 +272,20 @@ protected override void ProcessRecord() WriteObject(result); } + + private void HandleValidationErrors(EvaluationResults evaluationResult) + { + if (!evaluationResult.HasErrors) + { + return; + } + + foreach (var error in evaluationResult.Errors!) + { + Exception exception = new(string.Format(TestJsonCmdletStrings.InvalidJsonAgainstSchemaDetailed, error.Value, evaluationResult.InstanceLocation)); + ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchemaDetailed", ErrorCategory.InvalidData, null); + WriteError(errorRecord); + } + } } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx index eed85d28b3d..94d81e854fd 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx +++ b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx @@ -1,17 +1,17 @@ - - - + + @@ -124,7 +124,7 @@ Cannot parse the JSON. - The JSON is not valid with the schema: {0} at {1} + The JSON is not valid with the schema: {0} at '{1}' Can not open JSON schema file: {0} @@ -132,4 +132,4 @@ URI scheme '{0}' is not supported. Only HTTP(S) and local file system URIs are allowed. - + \ No newline at end of file From 0fe1c38f2bb9b10e0d9e513d26e1b744c066fc58 Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Thu, 4 May 2023 16:33:07 +1200 Subject: [PATCH 2/7] reset unnecessary resx changes --- .../resources/TestJsonCmdletStrings.resx | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx index 94d81e854fd..d503154db71 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx +++ b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx @@ -1,17 +1,17 @@ - - - + + @@ -132,4 +132,4 @@ URI scheme '{0}' is not supported. Only HTTP(S) and local file system URIs are allowed. - \ No newline at end of file + From 44fdb3a1b58ccc41a56ea1d8c87e30121bdafcfd Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Thu, 4 May 2023 16:33:54 +1200 Subject: [PATCH 3/7] reset more unnecessary resx changes --- .../resources/TestJsonCmdletStrings.resx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx index d503154db71..cc607eda418 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx +++ b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx @@ -27,35 +27,35 @@ This is a comment - There are any number of "resheader" rows that contain simple + There are any number of "resheader" rows that contain simple name/value pairs. - Each data row contains a name, and value. The row also contains a - type or mimetype. Type corresponds to a .NET class that support - text/value conversion through the TypeConverter architecture. - Classes that don't support this are serialized and stored with the + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the mimetype set. - The mimetype is used for serialized objects, and tells the - ResXResourceReader how to depersist the object. This is currently not + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not extensible. For a given mimetype the value must be set accordingly: - Note - application/x-microsoft.net.object.binary.base64 is the format - that the ResXResourceWriter will generate, however the reader can + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can read any of the formats listed below. mimetype: application/x-microsoft.net.object.binary.base64 - value : The object must be serialized with + value : The object must be serialized with : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 - value : The object must be serialized with + value : The object must be serialized with : System.Runtime.Serialization.Formatters.Soap.SoapFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.bytearray.base64 - value : The object must be serialized into a byte array + value : The object must be serialized into a byte array : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> From df20cd439bfcad1120f9c7217195e85573afd7ec Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Thu, 4 May 2023 16:54:19 +1200 Subject: [PATCH 4/7] specify type in var declaration where type is not obvious --- .../commands/utility/TestJsonCommand.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs index 8595471548d..4069caf9ef7 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Management.Automation; @@ -239,7 +240,7 @@ protected override void ProcessRecord() if (_jschema != null) { - var evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List }); + EvaluationResults evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List }); result = evaluationResults.IsValid; if (!result) { From 695d0b7f60cc0bb690323d3372c5e223747f4f3b Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Fri, 5 May 2023 09:46:19 +1200 Subject: [PATCH 5/7] remove unused using and fix indention --- .../commands/utility/TestJsonCommand.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs index 4069caf9ef7..edb83a08413 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; using System.Globalization; using System.IO; using System.Management.Automation; @@ -240,20 +239,20 @@ protected override void ProcessRecord() if (_jschema != null) { - EvaluationResults evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List }); - result = evaluationResults.IsValid; - if (!result) - { - HandleValidationErrors(evaluationResults); + EvaluationResults evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List }); + result = evaluationResults.IsValid; + if (!result) + { + HandleValidationErrors(evaluationResults); - if (evaluationResults.HasDetails) + if (evaluationResults.HasDetails) + { + foreach (var nestedResult in evaluationResults.Details) { - foreach (var nestedResult in evaluationResults.Details) - { - HandleValidationErrors(nestedResult); - } + HandleValidationErrors(nestedResult); } } + } } } catch (JsonSchemaReferenceResolutionException jsonExc) From 05962bf178c480fbf6d8283fa905aff156c1a73a Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Sat, 6 May 2023 09:08:09 +1200 Subject: [PATCH 6/7] update JsonSchema.Net to v4.1.1 --- .../Microsoft.PowerShell.Commands.Utility.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj index e465aa03f33..2972c210a60 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj +++ b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj @@ -35,7 +35,7 @@ - + From 8ad897b6e0d040e7277600b69302ac3da41c28ed Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Sat, 6 May 2023 11:25:10 +1200 Subject: [PATCH 7/7] update windows packaging bom --- tools/packaging/boms/windows.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/packaging/boms/windows.json b/tools/packaging/boms/windows.json index 747fa838b5d..75b6ddf3266 100644 --- a/tools/packaging/boms/windows.json +++ b/tools/packaging/boms/windows.json @@ -287,6 +287,10 @@ "Pattern": "es/WindowsFormsIntegration.resources.dll", "FileType": "NonProduct" }, + { + "Pattern": "es\\JsonSchema.Net.resources.dll", + "FileType": "NonProduct" + }, { "Pattern": "fr/Microsoft.CodeAnalysis.CSharp.resources.dll", "FileType": "NonProduct"