fix: include URL in api list --json output#404
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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>
There was a problem hiding this comment.
🤖 PR Reviewer
The changes add gateway URL injection into the apidoc paths before JSON output. The logic is straightforward and the tests cover both the happy path and the edge case of missing x-openwhisk. However, there are missing null/undefined guards that could cause runtime errors if the API response structure is incomplete.
📝 2 suggestion(s) - Please review inline comments below.
💡 How to re-trigger
Comment /review or /pr-reviewer on this PR
| 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']) { |
There was a problem hiding this comment.
No null check on apidoc or apidoc.paths before calling Object.keys. If apidoc or apidoc.paths is undefined, this will throw a TypeError.
| 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']) { | |
| if (apidoc && apidoc.paths) { | |
| 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 && operation['x-openwhisk']) { | |
| operation['x-openwhisk'].url = `${gwApiUrl}${path}` | |
| } | |
| }) | |
| }) | |
| } |
There was a problem hiding this comment.
@copilot fix this according to #404 (comment)
There was a problem hiding this comment.
Pull request overview
Fixes the aio rt api list --json output so it includes the actual API gateway URL in the Swagger apidoc output (specifically x-openwhisk.url), aligning JSON output with the plain-text listing behavior.
Changes:
- Populate
operation['x-openwhisk'].urlwith${gwApiUrl}${path}for each operation inapidoc.pathswhen--jsonis used. - Update/extend Jest coverage to assert the URL is now present and to verify operations without
x-openwhiskremain unchanged.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/commands/runtime/api/list.js |
Updates --json output to inject the computed gateway URL into x-openwhisk.url before logging the apidoc. |
test/commands/runtime/api/list.test.js |
Strengthens --json assertions to validate x-openwhisk.url is populated and adds a no-x-openwhisk regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🤖 PR Reviewer
The diff addresses the empty result.apis case but still does not guard against api.value being null/undefined or apidoc.paths being null/undefined, which were flagged in the previous review. The two originally raised issues remain unresolved.
🔄 2 re-raised suggestion(s) from previous review
💡 How to re-trigger
Comment /review or /pr-reviewer on this PR
|
|
||
| const api = result.apis[0] |
There was a problem hiding this comment.
[Re-raised] No null check on apidoc or apidoc.paths before calling Object.keys. If either is undefined this will throw a TypeError.
| const api = result.apis[0] | |
| const apidoc = api.value.apidoc | |
| const gwApiUrl = api.value.gwApiUrl | |
| if (!apidoc || !apidoc.paths) { | |
| this.logJSON('', apidoc || {}) | |
| return | |
| } |
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>
There was a problem hiding this comment.
🤖 PR Reviewer
The diff contains a critical syntax error in the source file: the early-return branch for empty apis is never closed before re-declaring variables (duplicate const api, const apidoc, const gwApiUrl declarations), and the closing brace for the empty-array check is missing. This code would fail to parse/compile entirely. The re-raised null-safety issues are still present since the null guard for apidoc and apidoc.paths is still absent before Object.keys(apidoc.paths).
🔄 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.
There was a problem hiding this comment.
🤖 PR Reviewer
The diff contains critical syntax errors in the source file: duplicate variable declarations (const api, const apidoc, const gwApiUrl), a missing closing brace for the early-return if block, and unreachable code after return. The logic as written will not compile/run correctly. The test file changes look reasonable but cannot validate the broken source code.
📝 1 suggestion(s) - Please review inline comments below.
💡 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.
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>
|
Closing because I can't make heads or tails on the 2 bots changing things 🙃 |
|
see #409 |
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