Skip to content

Require -FetchExternalReference to resolve external Test-Json schema references - #28205

Open
Justin Chung (jshigetomi) wants to merge 2 commits into
masterfrom
128628
Open

Justin Chung (jshigetomi) wants to merge 2 commits into
masterfrom
128628

Conversation

@jshigetomi

Copy link
Copy Markdown
Collaborator

PR Summary

This pull request enhances the Test-Json cmdlet by adding support for resolving external references in JSON schemas, controlled by a new -FetchExternalReference parameter. It also improves error handling and test coverage for various schema reference scenarios.

PR Context

PR Checklist

@jshigetomi Justin Chung (jshigetomi) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 14, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@jshigetomi Justin Chung (jshigetomi) changed the title Disable fetch delegate on $ref feature so external references are not allowed in Test-Json schema Require -FetchExternalReference to resolve external Test-Json schema references Oct 14, 2026
@jshigetomi
Justin Chung (jshigetomi) marked this pull request as ready for review October 14, 2026 21:42
@jshigetomi
Justin Chung (jshigetomi) requested a review from a team as a code owner October 14, 2026 21:42
Copilot AI balanced review requested due to automatic review settings October 14, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new CI test depends on uncontrolled public HTTP traffic and can stall on restricted agents.

1 open finding
What changed in this PR

Makes external schema fetching opt-in for Test-Json through -FetchExternalReference.

Changes:

  • Uses per-invocation schema evaluation options.
  • Adds unresolved-reference diagnostics.
  • Expands tests for internal, external, and invalid schema references.
File Description
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​Test-Json.Tests.ps1 Tests opt-in fetching and invocation isolation.
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​assets/​valid_schema.json Adds a standalone valid schema.
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​assets/​valid_schema_uri_references_external.json Adds an external HTTP reference.
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​assets/​valid_schema_references_internal.json Adds internal reference coverage.
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​assets/​valid_schema_references_external.json Adds external file references.
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​assets/​valid_schema_definitions_external.json Supplies externally referenced definitions.
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​assets/​invalid_schema.json Provides an independently invalid schema.
src/​Microsoft.PowerShell.Commands.Utility/​resources/​TestJsonCmdletStrings.resx Adds unresolved-reference guidance.
src/​Microsoft.PowerShell.Commands.Utility/​commands/​utility/​TestJsonCommand.cs Gates fetching and handles unresolved references.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

}

It "Json is valid but unresolvable, with FetchExternalReference parameter, against a schema with external URI reference" {
Test-Json -Json $validJson -SchemaFile $validSchemaWithExternalUriRefJsonPath -FetchExternalReference -ErrorVariable ErrorVar -ErrorAction SilentlyContinue | Should -BeFalse
@daxian-dbw

Copy link
Copy Markdown
Member

Anam Navied (@anamnavi) Please take a look at #28218 when reviewing this PR.

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.

3 participants