Skip to content

add PSscript to convert APIView json token files to md#14344

Open
swathipil wants to merge 1 commit intoAzure:mainfrom
swathipil:swathipil/add-apiview-convert-json-to-md
Open

add PSscript to convert APIView json token files to md#14344
swathipil wants to merge 1 commit intoAzure:mainfrom
swathipil:swathipil/add-apiview-convert-json-to-md

Conversation

@swathipil
Copy link
Member

Following up on review in #13259.

Addressing: #12851

@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

@swathipil swathipil requested a review from benbp March 4, 2026 22:16
@swathipil swathipil marked this pull request as ready for review March 4, 2026 22:16
@swathipil swathipil requested a review from a team as a code owner March 4, 2026 22:16
Copilot AI review requested due to automatic review settings March 4, 2026 22:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a PowerShell utility and Pester coverage to convert APIView token JSON (tree format) into markdown with fenced code blocks for easier API review workflows.

Changes:

  • Introduces Export-APIViewMarkdown.ps1 to render ReviewLines (and nested Children) into markdown.
  • Adds Pester tests plus sample/golden APIView fixtures to validate formatting, spacing, language tags, and error handling.

Reviewed changes

Copilot reviewed 5 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
eng/common/scripts/Export-APIViewMarkdown.ps1 New script that converts APIView token JSON to fenced markdown output.
eng/common-tests/apiview-markdown/tests/Export-APIViewMarkdown.Tests.ps1 New Pester suite validating rendering, indentation, spacing flags, language tags, and errors.
eng/common-tests/apiview-markdown/testfiles/Export-APIViewMarkdown/simple_tokens.json Minimal fixture JSON with nested children and whitespace metadata.
eng/common-tests/apiview-markdown/testfiles/Export-APIViewMarkdown/azure-core_python.md Golden markdown output fixture for Python.
eng/common-tests/apiview-markdown/testfiles/Export-APIViewMarkdown/azure-core_js.md Golden markdown output fixture for JavaScript.

Comment on lines +136 to +137
$fenceOpen = "``````$language"
$fenceClose = "``````"
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The script generates fences using six backticks, but the added golden markdown fixtures (e.g., azure-core_python.md, azure-core_js.md) use standard triple-backtick fences (lang ... ). This mismatch will prevent the script output from matching the golden files and is also non-standard markdown. Switch to triple backticks for both open/close (and keep the language tag on the opening fence).

Suggested change
$fenceOpen = "``````$language"
$fenceClose = "``````"
$fenceOpen = "```$language"
$fenceClose = "```"

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +23
$content | Should -Match "^``````py"
$content | Should -Match "``````$"
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The tests assert six-backtick fences here, but later tests assert triple-backtick fences (e.g., expecting ```py for alias mapping) and the golden files also start with triple backticks. This inconsistency will make the test suite fail once the fence format is corrected; update these assertions to match the chosen (and golden) fence style.

Suggested change
$content | Should -Match "^``````py"
$content | Should -Match "``````$"
$content | Should -Match '^```py'
$content | Should -Match '```$'

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +105
Write-Error "Token JSON file not found: $TokenJsonPath"
exit 1
}

$tokenJson = Get-Content -Path $TokenJsonPath -Raw | ConvertFrom-Json

if (-not $tokenJson.ReviewLines) {
Write-Error "The token JSON file does not contain a 'ReviewLines' property."
exit 1
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

Write-Error combined with exit is risky for a script that may be dot-sourced or invoked from a larger PowerShell session (including CI), because exit can terminate the entire host if the error is caught upstream. Prefer throw (or Write-Error -ErrorAction Stop without exit) and remove exit 1 so failures remain catchable without killing the process.

Suggested change
Write-Error "Token JSON file not found: $TokenJsonPath"
exit 1
}
$tokenJson = Get-Content -Path $TokenJsonPath -Raw | ConvertFrom-Json
if (-not $tokenJson.ReviewLines) {
Write-Error "The token JSON file does not contain a 'ReviewLines' property."
exit 1
throw "Token JSON file not found: $TokenJsonPath"
}
$tokenJson = Get-Content -Path $TokenJsonPath -Raw | ConvertFrom-Json
if (-not $tokenJson.ReviewLines) {
throw "The token JSON file does not contain a 'ReviewLines' property."

Copilot uses AI. Check for mistakes.
Comment on lines +149 to +154
It "Closes the fence with a plain triple-backtick" {
$outFile = Join-Path $TestDrive "close.md"
& $scriptPath -TokenJsonPath $simpleTokensJson -OutputPath $outFile

$lines = Get-Content $outFile
$lines[-1] | Should -Be "``````"
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The test name says "triple-backtick" but asserts a six-backtick fence. After aligning fences to standard markdown, update both the test title and assertion to consistently refer to (and validate) the same fence format.

Copilot uses AI. Check for mistakes.
@azure-sdk
Copy link
Collaborator

The following pipelines have been queued for testing:
java - template
java - template - tests
js - template
net - template
net - template - tests
python - template
python - template - tests
You can sign off on the approval gate to test the release stage of each pipeline.
See eng/common workflow

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants