Skip to content

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

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

fix: include URL in api list --json output#410
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

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 10 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>
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 implementation in list.js has a critical structural bug: there is a misplaced/orphaned code block (Object.keys(apidoc.paths || {}).forEach(...)) inside the early-return branch for missing APIs, and the return statement is missing after this.logJSON('', {}), meaning execution will fall through and crash on api.value.apidoc when api/api.value is falsy. The early-exit block is syntactically malformed and will cause a runtime error. Tests are well-structured and cover the new behavior appropriately.

📝 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 early-return guard block is malformed: it is missing a return after this.logJSON('', {}), and there is a dangling/orphaned Object.keys(apidoc.paths || {}).forEach(path => { } block inside the guard that references apidoc before it is defined. This will cause a ReferenceError or fall-through crash. The guard block needs a return and the orphaned forEach must be removed.

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 (it had a commit I didn't want from the bot)

@shazron shazron closed this Apr 27, 2026
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