-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Test-Json: use JsonSchema.Net instead of NJsonSchema #18023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test-Json: use JsonSchema.Net instead of NJsonSchema #18023
Conversation
|
I'm not sure if this is a problem, but I notice that all of the tests are written with single quotes. Newtonsoft is happy to parse these, but System.Text.Json will not. I suspect this is the source the test failures, but I'm not sure. I could use some help getting the tests to run locally. |
|
@gregsdennis Yes, it is main breaking change in System.Text.Json. @SteveL-MSFT Do you agree to begin migration to System.Text.Json in the 7.4 milestone? |
|
There seem to be a lot more changes to files.wxs that I expected. Maybe this is normal? |
|
@gregsdennis Please finish replacing ' with " in tests since you have started the process.
Try reformat: var validationResults = _jschema.Validate(parsedJson, new ValidationOptions
{
OutputFormat = OutputFormat.Basic
});
> files.wxs
You need to build win package locally and the script will publish new files.wxs in temp folder. |
|
@gregsdennis Maybe #11397 help you a bit. |
I expect you don't mean all the tests. Even just in that file seems overkill. It seems there's a preference to have
The format of |
I still see test fails because of " |
|
The failing tests aren't (all) because of For example, JSON Schema explicitly states that implementations SHOULD NOT download references that appear to be URLs. The URIs that are used are merely identifiers, not locations. As such, downloading is disabled in my lib by default, requiring pre-loading of all required schemas, but it seems that it may have been enabled in NJsonSchema. I can make this change. I'll go through the other tests to see what the problems are. |
So we cannot reference base schema file from new schema file? |
|
If PowerShell is comfortable with automatically fetching external documents, it can be enabled, yes, but it's not generally recommended by JSON Schema. Given that this is previous functionality, I think enabling it is fine. I suggest adding this to the docs as a deviation from the spec. |
Since this has not been reported as a security issue until now we should keep current behavior if possible. Then we will ask PowerShell security group. |
|
It looks like there's some syntax issue I don't understand in the I've extracted the loop into a separate file: $types = 'string', 'number', 'boolean', 'null', 'array', 'object'
$types | Where-Object {
$schema = "{ ""type"": ""$_"" }"
Write-Output $schema
}
$type = 'string'
$schema = "{ ""type"": ""$type"" }"
Write-Output $schemaThis outputs I don't understand why the interpolation isn't working in the loop but it works outside of it. |
test/powershell/Modules/Microsoft.PowerShell.Utility/Test-Json.Tests.ps1
Outdated
Show resolved
Hide resolved
PowerShell interpolation works only in double quotes. I added commit to fix the test. |
|
What's the policy on changing error codes?
In both cases, it's an error, but the exact error is different. Edit: After the commit below, all the tests are passing except for this. |
I agree with |
…nSchemaReferenceResolutionException.cs Co-authored-by: Ilya <darpa@yandex.ru>
…tJsonCommand.cs Co-authored-by: Ilya <darpa@yandex.ru>
18443fb to
eb6d1d0
Compare
Co-authored-by: Ilya <darpa@yandex.ru>
|
I've rebased and pushed. |
|
@iSazonov since the update to .Net 7 RC1, I can't build anymore. I've installed the preview framework (Windows x64 installer). I'm getting a lot of errors saying that it can't find Microsoft.CodeAnalysis. It seems there are some rebase conflicts with how I merged the .wxs file. |
Usually we need to remove nuget cache in current user profile to fix such issues. Also you need to run once |
|
@iSazonov I've regen'd the files.wxs file (and removed the pdb's) but I'm not sure it's right. There seem to be other DLLs listed that I didn't do anything with. |
Please build msi package locally and use files.wxs from the build. |
Are there instructions for this? All I can find is the Windows build instructions. This only generates an .exe. |
|
@iSazonov I ran that except that it didn't recognize the It also added all of the |
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
@gregsdennis I added new commit to fix packaging. |
|
Thank you @iSazonov I'm going through the checklist now, and the only breaking change that I can think of is the lack of support for single-quoted JSON (which isn't really JSON anyway). Does this need to be documented somewhere? If so, where? Do I need to create a separate issue to track that? |
Common rule for PowerShell is to follow .Net behavior. I think it makes sense to explain the breaking change in docs. But now is not the time. The change has to be approved by MSFT team first. Then there are other Json cmdlets that should be migrated. And finally, there are many small differences between NewtonSoft and .Net implementations. I guess we are not able to describe them all. We can only point out this fact. I don't think this is a critical change, because the .Net implementations follow Json standard very closely. @gregsdennis The PR contains a lot of temporary comments, so I suggest to close the PR and open new one. |

PR Summary
Updates the
Test-Jsoncmdlet to use JsonSchema.Net instead of NJsonSchema in order to:Resolves
PR Context
Resolves #18009
NJsonSchema only supports up to draft 7, which at this point is several years old and two versions behind. Additionally, it relies on Newtonsoft.Json.
This change is a merely drop-in replacement of the implementation that provides validation.
The cmdlet API doesn't change, however the cmdlet will no longer support draft 4 schemas. Draft 4 is a decade old at this point and the JSON Schema team (myself included) is encouraging tooling to only support draft 6/7 (6 is a subset of 7) and later. (In the future, support for these should be dropped as newer versions are released.) I'm not sure if this is considered a breaking change for this repo.
To assist users in their migration away from draft 4, the alterschema draft migration tool has been created.
I expect the existing test coverage is adequate to cover this change.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).