Skip to content

fix: include URL in api list --json output#409

Closed
shazron wants to merge 10 commits into
masterfrom
fix/api-list-json-url
Closed

fix: include URL in api list --json output#409
shazron wants to merge 10 commits into
masterfrom
fix/api-list-json-url

Conversation

@shazron

@shazron shazron commented Apr 27, 2026

Copy link
Copy Markdown
Member

Fixes #388

Summary

  • Fixes aio rt api list --json does not show the URL #388aio rt api list --json was not showing the API URL
  • The --json output preserves the existing apidoc JSON structure unchanged
  • The x-openwhisk.url field (previously always "not-used") is now populated with the actual gateway URL built from gwApiUrl + path

Test plan

  • Run npm test -- --testPathPattern="api/list" — all tests pass
  • Verify aio rt api list --json output retains the apidoc structure with x-openwhisk.url now set to the real URL

🤖 Generated with Claude Code

shazron and others added 9 commits April 13, 2026 17:11
Fixes #388 - the --json flag was outputting only `apidoc` (missing the
gateway URL). Now outputs the same processed array as the table view,
which includes the URL built from `gwApiUrl`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes #388 - keeps the apidoc JSON structure unchanged but updates the
x-openwhisk.url field (previously always "not-used") to the actual
gateway URL built from gwApiUrl + path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The diff adds null-safety for the API result and enriches the apidoc output with gateway URLs before JSON serialization. The logic is clear and well-tested. One minor concern: apidoc.paths is accessed without guarding against a potentially missing or null paths property, which could throw if the API doc is malformed.

📝 1 suggestion(s) - Please review inline comments below.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

Comment thread src/commands/runtime/api/list.js Outdated
@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions Bot dismissed their stale review April 27, 2026 08:14

Superseded by new review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The diff introduces a critical syntax error in list.js: the early-return block is not properly closed, and a stray Object.keys(apidoc.paths || {}).forEach(path => { line from a previous suggestion appears in the middle of the if-block before apidoc is even declared. This would cause a runtime SyntaxError/ReferenceError. The test additions are well-structured and cover the new edge cases properly.

🔄 1 re-raised suggestion(s) from previous review


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

⚠️ Inline comments could not be attached (lines not in diff). See summary above.

@shazron

shazron commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

/review

@github-actions github-actions Bot dismissed their stale review April 27, 2026 08:15

Superseded by new review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The production code in list.js has a critical logical error: the early return after logging an empty object is missing, and there's a stray/misplaced Object.keys(apidoc.paths || {}).forEach block before apidoc is even defined, which will cause a ReferenceError at runtime. The test additions are well-structured and cover the new cases properly.

📝 1 suggestion(s) - Please review inline comments below.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

Comment on lines 59 to 79
if (shouldOutputJson) {
this.logJSON('', result.apis[0].value.apidoc)
const api = result.apis && result.apis[0]
if (!api || !api.value) {
this.logJSON('', {})
Object.keys(apidoc.paths || {}).forEach(path => {
}
const apidoc = api.value.apidoc
const gwApiUrl = api.value.gwApiUrl
Object.keys(apidoc.paths).forEach(path => {
if (!path.startsWith('/')) return
Object.keys(apidoc.paths[path]).forEach(verb => {
const operation = apidoc.paths[path][verb]
if (operation['x-openwhisk']) {
operation['x-openwhisk'].url = `${gwApiUrl}${path}`
}
})
})
this.logJSON('', apidoc)
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The code has multiple critical bugs: (1) The early return return is placed inside the if (!api || !api.value) block but the closing brace is wrong — the return is actually outside the if, so execution falls through and tries to access api.value.apidoc when api is falsy. (2) There is a stray Object.keys(apidoc.paths || {}).forEach block that references apidoc before it is declared, causing a ReferenceError. (3) The closing return after this.logJSON('', {}) is missing, so on empty apis the code will crash. The entire block needs to be rewritten correctly.

Suggested change
if (shouldOutputJson) {
this.logJSON('', result.apis[0].value.apidoc)
const api = result.apis && result.apis[0]
if (!api || !api.value) {
this.logJSON('', {})
Object.keys(apidoc.paths || {}).forEach(path => {
}
const apidoc = api.value.apidoc
const gwApiUrl = api.value.gwApiUrl
Object.keys(apidoc.paths).forEach(path => {
if (!path.startsWith('/')) return
Object.keys(apidoc.paths[path]).forEach(verb => {
const operation = apidoc.paths[path][verb]
if (operation['x-openwhisk']) {
operation['x-openwhisk'].url = `${gwApiUrl}${path}`
}
})
})
this.logJSON('', apidoc)
return
}
const api = result.apis && result.apis[0]
if (!api || !api.value) {
this.logJSON('', {})
return
}
const apidoc = api.value.apidoc
const gwApiUrl = api.value.gwApiUrl
Object.keys(apidoc.paths || {}).forEach(path => {
if (!path.startsWith('/')) return
Object.keys(apidoc.paths[path]).forEach(verb => {
const operation = apidoc.paths[path][verb]
if (operation['x-openwhisk']) {
operation['x-openwhisk'].url = `${gwApiUrl}${path}`
}
})
})
this.logJSON('', apidoc)
return

@shazron

shazron commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

closing (again)

@shazron shazron closed this Apr 27, 2026
@shazron

shazron commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

see #410

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.

aio rt api list --json does not show the URL

2 participants