fix: include URL in api list --json output#409
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>
There was a problem hiding this comment.
🤖 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
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>
There was a problem hiding this comment.
🤖 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.
|
/review |
There was a problem hiding this comment.
🤖 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
| 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 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.
| 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 (again) |
|
see #410 |
Fixes #388
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