Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -239,32 +239,20 @@ protected override void ProcessRecord()

if (_jschema != null)
{
var validationResults = _jschema.Validate(parsedJson, new ValidationOptions { OutputFormat = OutputFormat.Basic });
result = validationResults.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);
}
EvaluationResults evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List });
result = evaluationResults.IsValid;
if (!result)
{
HandleValidationErrors(evaluationResults);

if (validationResults.HasNestedResults)
if (evaluationResults.HasDetails)
{
foreach (var nestedResult in evaluationResults.Details)
{
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)
Expand All @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I updated, I tested this locally with a schema & instance that had a problem at the root. The error that's output just ends with "at", and the fact that there's an empty JSON Pointer indicating the root object isn't conveyed. I think the quotes help.

<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>
Expand Down
4 changes: 4 additions & 0 deletions tools/packaging/boms/windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down