fix: include URL in api list --json output#410
Conversation
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>
Agent-Logs-Url: https://github.com/adobe/aio-cli-plugin-runtime/sessions/4e07e478-6839-4941-897b-fe9cf27235e3 Co-authored-by: shazron <36107+shazron@users.noreply.github.com>
Agent-Logs-Url: https://github.com/adobe/aio-cli-plugin-runtime/sessions/4e07e478-6839-4941-897b-fe9cf27235e3 Co-authored-by: shazron <36107+shazron@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
🤖 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
| 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 | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
| 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 |
|
closing (it had a commit I didn't want from the bot) |
Summary
aio rt api list --jsonwas not showing the API URL--jsonoutput preserves the existingapidocJSON structure unchangedx-openwhisk.urlfield (previously always"not-used") is now populated with the actual gateway URL built fromgwApiUrl + pathTest plan
npm test -- --testPathPattern="api/list"— all tests passaio rt api list --jsonoutput retains theapidocstructure withx-openwhisk.urlnow set to the real URL🤖 Generated with Claude Code