Skip to content

Conversation

@ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Jan 27, 2023

PR Summary

Fixes #15544
Fixes #12882

Added -Path and -LiteralPath parameter to Test-Json cmdlet.

PR Context

Currently you can only pass a JSON string to Test-Json like so:

PS C:\> Test-Json -Json (Get-Content -Path data.json -Raw)

With this change you can now also pass a path:

PS C:\> Test-Json -Path data.json

Or with literal path:

PS C:\> Test-Json -LiteralPath '[data].json'

Which makes validating JSON from file paths much easier.

Current Syntax

Test-Json [-Json] <string> [<CommonParameters>]

Test-Json [-Json] <string> [[-Schema] <string>] [<CommonParameters>]

Test-Json [-Json] <string> [[-SchemaFile] <string>] [<CommonParameters>]

New Syntax

Test-Json [-Json] <string> [<CommonParameters>]

Test-Json [-Json] <string> [-Schema] <string> [<CommonParameters>]

Test-Json [-Json] <string> [-SchemaFile] <string> [<CommonParameters>]

Test-Json [-Path] <string> [<CommonParameters>]

Test-Json [-Path] <string> [-Schema] <string> [<CommonParameters>]

Test-Json [-Path] <string> [-SchemaFile] <string> [<CommonParameters>]

Test-Json [-LiteralPath] <string> [<CommonParameters>]

Test-Json [-LiteralPath] <string> [-Schema] <string> [<CommonParameters>]

Test-Json [-LiteralPath] <string> [-SchemaFile] <string> [<CommonParameters>]

Which does introduce a Bucket 4 breaking change: https://github.com/PowerShell/PowerShell/blob/master/docs/dev-process/breaking-change-contract.md#bucket-4-clearly-non-public

But given changing parameter sets are not technically public API then it seemed fine to reorganize them to allow the new -Path parameter. If there is an easier way to do the parameter sets please let me know 😄.

PR Checklist

@ghost ghost assigned daxian-dbw Jan 27, 2023
@ArmaanMcleod ArmaanMcleod marked this pull request as ready for review January 27, 2023 13:46
@ArmaanMcleod ArmaanMcleod force-pushed the test-json-file-parameter branch from 69168a5 to ce486a4 Compare January 28, 2023 02:02
@ArmaanMcleod ArmaanMcleod changed the title Add Path parameter to Test-Json Add -Path parameter to Test-Json cmdlet Jan 28, 2023
@ArmaanMcleod ArmaanMcleod changed the title Add -Path parameter to Test-Json cmdlet Add -Path and -LiteralPath parameters to Test-Json cmdlet Feb 2, 2023
@ArmaanMcleod ArmaanMcleod force-pushed the test-json-file-parameter branch from 17bd510 to 992b89f Compare February 2, 2023 13:50
@ArmaanMcleod ArmaanMcleod marked this pull request as ready for review February 2, 2023 14:02
@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Feb 2, 2023

@iSazonov Thanks for the feedback. I've included a -LiteralPath parameter and made both path parameters use ValueFromPipelineByPropertyName. Also cleaned up the extra whitspace and generate the test json files on the fly using TestDrive:/.

Let me know what you think, I think it looks much better already 😄.

@iSazonov iSazonov requested a review from vexx32 February 2, 2023 17:26
@ArmaanMcleod ArmaanMcleod force-pushed the test-json-file-parameter branch from 8a95fb8 to 9a7582b Compare February 3, 2023 22:39
@ArmaanMcleod
Copy link
Contributor Author

One strange thing I've noticed is if you do Get-ChildItem -Path '.markdownlint.json' -File | Test-Json, it will still set the path as a literal path from pipeline parameter binding.

@iSazonov
Copy link
Collaborator

iSazonov commented Feb 4, 2023

One strange thing I've noticed is if you do Get-ChildItem -Path '.markdownlint.json' -File | Test-Json, it will still set the path as a literal path from pipeline parameter binding.

ValueFromPipelineByPropertyName and PSPath alias for LiteralPath work. It is expected behavior.

@iSazonov iSazonov added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module labels Feb 4, 2023
@ArmaanMcleod ArmaanMcleod reopened this Feb 7, 2023
@ArmaanMcleod
Copy link
Contributor Author

Closed and Reopened to restart CI

@iSazonov iSazonov requested a review from SteveL-MSFT February 7, 2023 11:59
@ArmaanMcleod ArmaanMcleod force-pushed the test-json-file-parameter branch 2 times, most recently from d2fbe31 to 707c135 Compare February 8, 2023 12:53
@pull-request-quantifier-deprecated

This PR has 155 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +144 -11
Percentile : 51%

Total files changed: 2

Change summary by file extension:
.cs : +59 -8
.ps1 : +85 -3

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@daxian-dbw daxian-dbw merged commit 0be3eea into PowerShell:master Feb 21, 2023
@ArmaanMcleod ArmaanMcleod deleted the test-json-file-parameter branch February 21, 2023 19:55
@iSazonov
Copy link
Collaborator

@ArmaanMcleod Thanks for your contribution!

@ghost
Copy link

ghost commented Mar 14, 2023

🎉v7.4.0-preview.2 has been released which incorporates this pull request.:tada:

Handy links:

Comment on lines +28 to +30
private const string JsonPathParameterSet = "JsonPath";
private const string JsonPathWithSchemaStringParameterSet = "JsonPathWithSchemaString";
private const string JsonPathWithSchemaFileParameterSet = "JsonPathWithSchemaFile";
Copy link
Contributor

Choose a reason for hiding this comment

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

"JsonPath" is really unfortunate naming as it suggests JSON Path, the query syntax.

Copy link
Contributor Author

@ArmaanMcleod ArmaanMcleod May 2, 2023

Choose a reason for hiding this comment

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

@gregsdennis Agree, we could change parameter set names to something more suitable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please wait until my #18141 merges, or I can do it afterward. That change almost erased these due to a bad rebase.

gregsdennis added a commit to gregsdennis/PowerShell that referenced this pull request May 2, 2023
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 Medium WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test-Json : Add parameter for JSON data file Test-Json should have a -JsonFile parameter

4 participants