Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add parameter SchemaFile to Test-Json cmdlet#11934

Merged
adityapatwardhan merged 28 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
beatcracker:test-json_schema-from-fileCopy head branch name to clipboard
Jun 2, 2020
Merged

Add parameter SchemaFile to Test-Json cmdlet#11934
adityapatwardhan merged 28 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
beatcracker:test-json_schema-from-fileCopy head branch name to clipboard

Conversation

@beatcracker

@beatcracker beatcracker commented Feb 23, 2020

Copy link
Copy Markdown
Contributor

PR Summary

Add parameter SchemaFile to the Test-Json cmdlet.

PR Context

Current implementation allows JSON schema to be only passed as string. This makes it impossible to validate JSON files against the schema that includes definitions from separate files: https://json-schema.org/understanding-json-schema/structuring.html#reuse

{ "$ref": "definitions.json#/address" }

The new parameter accepts literal path to the JSON schema file and allows JSON files to be validated against such schemas.

Notes

  1. I don't have much experience with C#, so please, bear with me.
  2. This PR currently lacks tests. I think that I need to extend Test-Json.Tests.ps1, but I'm not sure where to put JSON schema files with includes. Would assets folder be ok?
  3. @iSazonov is the author of the original Test-Json implementation and there is Migrate Test-Json to System.Text.Json API #11397 that should be taken into account.

PR Checklist

@msftclas

msftclas commented Feb 23, 2020

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@beatcracker

Copy link
Copy Markdown
Contributor Author

Signed CLA, added tests.

@beatcracker beatcracker requested a review from iSazonov February 24, 2020 16:39
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs Outdated
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs Outdated
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs Outdated
beatcracker and others added 3 commits February 25, 2020 00:19
Co-Authored-By: Ilya <darpa@yandex.ru>
Seems that "ResolveFilePath" doesn't throw in any conditions I could test.
NJsonSchema will throw "System.IO.IOException" so we catch that.
/// This class implements Test-Json command.
/// </summary>
[Cmdlet(VerbsDiagnostic.Test, "Json", HelpUri = "")]
[Cmdlet(VerbsDiagnostic.Test, "Json", DefaultParameterSetName = ParameterAttribute.AllParameterSets, HelpUri = "")]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@sdwheeler @SteveL-MSFT I wonder that we haven't HelpUri for the cmdlet.

Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs Outdated
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs Outdated
@beatcracker beatcracker changed the title [ WIP ] Test-Json: add parameter 'SchemaPath' [ WIP ] Test-Json: add parameter 'SchemaFile' Mar 2, 2020
@vexx32

vexx32 commented Mar 4, 2020

Copy link
Copy Markdown
Collaborator

We may also want to consider #11999 in tandem with this PR and the overall behaviour when a JSON input fails validation / schema.

@iSazonov

iSazonov commented Mar 4, 2020

Copy link
Copy Markdown
Collaborator

My initial thoughts was and I still believe that users want to see errors of the JSON validation.

@vexx32

vexx32 commented Mar 5, 2020

Copy link
Copy Markdown
Collaborator

@iSazonov I would agree that there is potential value in being able to see that, but I think that having that as an explicit opt-in would be more useful. There's a lot of cases where you just want to test whether some input JSON is valid or not, and not do much else.

For the cases where the full feedback is asked for, I would expect we output a rich object indicating success status and a proper list of structured data indicating any validation failures that were encountered, all on the one output object. The current state of having two separate and simultaneous modes of outputting data across two separate streams is, I think, much more difficult for folks to work with.

@iSazonov

iSazonov commented Mar 5, 2020

Copy link
Copy Markdown
Collaborator

I think that having that as an explicit opt-in would be more useful. There's a lot of cases where you just want to test whether some input JSON is valid or not, and not do much else.

I don't know what is a primary scenario. In interactive scenario users could get verbose output without extra switches and in script scenario we could do Test-Json -Quite like we do in Test-Connection cmdlet - it would be non-breaking change.

@vexx32

vexx32 commented Mar 5, 2020

Copy link
Copy Markdown
Collaborator

@iSazonov I don't think that changing behaviours between interactive use and script is ever a good idea. It should always be an option for the user to specify. Any kind of black magic like that will simply confuse users and make it more difficult to appropriately diagnose issues.

Cmdlet behaviours should be consistent.

@TravisEz13 TravisEz13 added this to the 7.1.0-preview.4 milestone May 14, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label May 27, 2020
@ghost

ghost commented May 27, 2020

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@adityapatwardhan

Copy link
Copy Markdown
Member

@beatcracker If the PR is ready for review, please remove the WIP from the title. That helps me prioritize things.

@beatcracker beatcracker changed the title [ WIP ] Test-Json: add parameter 'SchemaFile' Test-Json: add parameter 'SchemaFile' May 28, 2020
@beatcracker

Copy link
Copy Markdown
Contributor Author

@adityapatwardhan I think it is. I've removed [ WIP ], thanks.

Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs Outdated
@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label May 28, 2020
@ghost ghost removed this from the 7.1.0-preview.4 milestone May 28, 2020
@ghost ghost removed the Review - Needed The PR is being reviewed label May 28, 2020
@adityapatwardhan

Copy link
Copy Markdown
Member

@beatcracker Can you also respond to comment about not rethrowing and writing error instead.

Co-authored-by: Aditya Patwardhan <adityap@microsoft.com>
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label May 28, 2020
@beatcracker

Copy link
Copy Markdown
Contributor Author

@adityapatwardhan, Sure, I just did that. As far as I understand, in that case we're supposed to throw. because this is invalid input.

@adityapatwardhan

Copy link
Copy Markdown
Member

@PoshChan Please remind me in 1 hour

@adityapatwardhan adityapatwardhan changed the title Test-Json: add parameter 'SchemaFile' Add parameter SchemaFile to Test-Json cmdlet May 29, 2020
@PoshChan

Copy link
Copy Markdown
Collaborator

@adityapatwardhan, this is the reminder you requested 1 hour ago

@adityapatwardhan

Copy link
Copy Markdown
Member

@PoshChan please rebuild windows

@PoshChan

PoshChan commented Jun 1, 2020

Copy link
Copy Markdown
Collaborator

@adityapatwardhan, successfully started rebuild of PowerShell-CI-Windows

@adityapatwardhan adityapatwardhan merged commit c22ccbe into PowerShell:master Jun 2, 2020
@adityapatwardhan

Copy link
Copy Markdown
Member

@beatcracker Thank you for your contribution!

@adityapatwardhan adityapatwardhan added this to the 7.1.0-preview.4 milestone Jun 2, 2020
@vexx32

vexx32 commented Jun 6, 2020

Copy link
Copy Markdown
Collaborator

@adityapatwardhan @beatcracker did we get an issue filed in the docs repo to ensure this is documented in time for 7.1.0?

@beatcracker

Copy link
Copy Markdown
Contributor Author

@vexx32 I don't think so. If you point me in the right direction, I could do that. Are we talking about PR to update Test-Json.md?

@vexx32

vexx32 commented Jun 6, 2020

Copy link
Copy Markdown
Collaborator

@beatcracker yep! You can either submit a PR to add the information directly or file an issue so the docs team are aware and can sort it out as they're able. 🙂

sdwheeler added a commit to MicrosoftDocs/PowerShell-Docs that referenced this pull request Jun 19, 2020
* Test-Json: document SchemaFile parameter

See PowerShell/PowerShell#11934 for details

* Update reference/7.1/Microsoft.PowerShell.Utility/Test-Json.md

Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>

* Add SchemaFile example

* Reformatted to fix build error

Fixed formatting to fit PlatyPS schema requirements

* Fix duplicate JSON in SchemaFile example

Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
@ghost

ghost commented Jun 25, 2020

Copy link
Copy Markdown

🎉v7.1.0-preview.4 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.