mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Update JsonSchema.Net version to 4.1.0 (#19610)
This commit is contained in:
+1
-1
@@ -35,7 +35,7 @@
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0-1.final" />
|
||||
<PackageReference Include="System.Threading.AccessControl" Version="8.0.0-preview.3.23174.8" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.0-preview.2.23128.3" />
|
||||
<PackageReference Include="JsonSchema.Net" Version="3.3.2" />
|
||||
<PackageReference Include="JsonSchema.Net" Version="4.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -239,32 +239,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (_jschema != null)
|
||||
{
|
||||
var validationResults = _jschema.Validate(parsedJson, new ValidationOptions { OutputFormat = OutputFormat.Basic });
|
||||
result = validationResults.IsValid;
|
||||
if (!result)
|
||||
EvaluationResults evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List });
|
||||
result = evaluationResults.IsValid;
|
||||
if (!result)
|
||||
{
|
||||
HandleValidationErrors(evaluationResults);
|
||||
|
||||
if (evaluationResults.HasDetails)
|
||||
{
|
||||
if (validationResults.Message != null)
|
||||
foreach (var nestedResult in evaluationResults.Details)
|
||||
{
|
||||
Exception exception = new(string.Format(TestJsonCmdletStrings.InvalidJsonAgainstSchemaDetailed, validationResults.Message, validationResults.InstanceLocation));
|
||||
ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchemaDetailed", ErrorCategory.InvalidData, null);
|
||||
WriteError(errorRecord);
|
||||
}
|
||||
|
||||
if (validationResults.HasNestedResults)
|
||||
{
|
||||
foreach (var nestedResult in validationResults.NestedResults)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (JsonSchemaReferenceResolutionException jsonExc)
|
||||
@@ -284,5 +272,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@
|
||||
<value>Cannot parse the JSON.</value>
|
||||
</data>
|
||||
<data name="InvalidJsonAgainstSchemaDetailed" xml:space="preserve">
|
||||
<value>The JSON is not valid with the schema: {0} at {1}</value>
|
||||
<value>The JSON is not valid with the schema: {0} at '{1}'</value>
|
||||
</data>
|
||||
<data name="JsonSchemaFileOpenFailure" xml:space="preserve">
|
||||
<value>Can not open JSON schema file: {0}</value>
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user