Improve Function for a True Json-LD API and Debugging.#26
Improve Function for a True Json-LD API and Debugging.#26AniTexs wants to merge 5 commits intoPoshWeb:mainfrom
Conversation
* Added `-SkipCertificateCheck` passthrough to `Invoke-RestMethod` * Added `-Authentication` passthrough to `Invoke-RestMethod` * Added `-UserAgent` passthrough to `Invoke-RestMethod` * Added `-Headers` passthrough to `Invoke-RestMethod` * Added `-IgnoreCache` switch to bypass cached responses and force a fresh request * Added `Write-Verbose`, `Write-Debug`, and `Write-Warning` output throughout for improved diagnostics * Added error handling with `try/catch` around web requests and JSON parsing * Fixed output formatting for direct JSON-LD API responses (true `application/ld+json` endpoints) * `@graph` document responses now emit individual graph entities rather than the wrapper object * Direct JSON-LD object and JSON-text responses are detected and processed without requiring HTML script-tag extraction
There was a problem hiding this comment.
Pull request overview
This PR updates Get-JsonLD to better support “true” JSON-LD API endpoints (e.g., application/ld+json responses), adds passthrough options for Invoke-RestMethod, and improves diagnostics and error handling.
Changes:
- Added new web-request passthrough parameters (
-SkipCertificateCheck,-Authentication,-UserAgent,-Headers) and-IgnoreCache. - Added verbose/debug/warning logging plus
try/catcharound web requests and JSON parsing. - Improved handling of direct JSON-LD API responses (including emitting
@graphentries rather than the wrapper document).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| Commands/Get-JsonLD.ps1 | Adds request passthroughs, caching controls, more diagnostics, improved error handling, and direct JSON-LD response support/formatting. |
| CHANGELOG.md | Documents the new parameters, caching behavior, diagnostics, and direct JSON-LD handling changes. |
Comments suppressed due to low confidence (1)
Commands/Get-JsonLD.ps1:118
- In the
outputfilter,$contextis only set when@contextis a string, but it’s never cleared per object. When processing multiple JSON-LD objects, an object without@contextcan inherit the previous object’s$context, producing incorrectpstypenamevalues. Reset$context(e.g.,$context = $null) at the start of the filter or computetypeNamewithout relying on a cross-object variable.
$in = $_
$shouldOutput = $true
if ($in.'@context' -is [string]) {
$context = $in.'@context'
}
if ($in.'@graph') {
if ($in.pstypenames -ne 'application/ld+json') {
$in.pstypenames.insert(0,'application/ld+json')
}
foreach ($graphObject in $in.'@graph') {
$graphObject | output
}
# Emit graph entries instead of the wrapper document.
$shouldOutput = $false
}
elseif ($in.'@type') {
$typeName = if ($context) {
$context, $in.'@type' -join '/'
} else {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Commands/Get-JsonLD.ps1
Outdated
| ($propertyNames -contains '@context') -or | ||
| ($propertyNames -contains '@type') -or | ||
| ($propertyNames -contains '@graph') |
Commands/Get-JsonLD.ps1
Outdated
| $jsonLdObjects = if ($restResponse -is [System.Collections.IEnumerable] -and -not ($restResponse -is [string])) { | ||
| @($restResponse) | ||
| } else { | ||
| @($restResponse) | ||
| } |
|
|
||
| --- | ||
|
|
||
| ## JSON-LD 0.1.1.1 - Pull Request |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances the Get-JsonLD PowerShell cmdlet to better support “true” JSON-LD API endpoints (e.g., application/ld+json responses), adds additional Invoke-RestMethod passthrough options, and improves diagnostics with verbose/debug/warning output and additional try/catch handling.
Changes:
- Added
Invoke-RestMethodpassthrough parameters (-SkipCertificateCheck,-Authentication,-UserAgent,-Headers) and cache-bypass behavior (-IgnoreCache). - Improved handling of direct JSON-LD API responses (object and JSON text), including emitting
@graphentries instead of wrapper documents. - Added more diagnostic output and additional error handling around web requests and JSON parsing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| Commands/Get-JsonLD.ps1 | Adds web request options, cache controls, diagnostics, and direct JSON-LD response handling logic. |
| CHANGELOG.md | Documents the above behavior changes in a new changelog entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* Remove Parameter `-RawHtml` since it was never used * Added ValidateSet to the `-Authentication` parameter * More error handling and stability. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@StartAutomating would you be so kind to review this PR and make a new version? |
|
@AniTexs Taking a look. It appears copilot did a lot more than initially requested, and these changes would break other functionality (like, for example, converting a graph to a json schema or lexicon). I'm ok with part of this, but not ok with how copilot has approached other parts of it. It appears that the .jsonld direct file is a "good catch". The Uri alias is also fine. I'm less inclined to support all of the parameters from Invoke-RestMethod/Invoke-WebRequest, as this sort of data should not be behind authentication (and, taken to it's logical conclusion, this would vastly expand the parameter count on a purposefully simple function) Will make the changes for #12, and opened #27 to track this concern. |
|
Yea, copilot did go a bit overboard but it also catched some stuff I forgot (: |
Get-JsonLDweb request options-SkipCertificateCheckpassthrough toInvoke-RestMethod-Authenticationpassthrough toInvoke-RestMethod-UserAgentpassthrough toInvoke-RestMethod-Headerspassthrough toInvoke-RestMethod-IgnoreCacheswitch to bypass cached responses and force a fresh requestWrite-Verbose,Write-Debug, andWrite-Warningoutput throughout for improved diagnosticstry/catcharound web requests and JSON parsingapplication/ld+jsonendpoints)@graphdocument responses now emit individual graph entities rather than the wrapper objectReason for this was because of the https://unlocode.unece.org/docs/web-vocabulary API