Skip to content

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

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

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

Conversation

@shazron

@shazron shazron commented Apr 13, 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

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

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

shazron and others added 3 commits April 13, 2026 18:15
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>

@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 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

Comment thread src/commands/runtime/api/list.js Outdated
Comment thread src/commands/runtime/api/list.js Outdated
Comment on lines +61 to +67
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']) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No null check on apidoc or apidoc.paths before calling Object.keys. If apidoc or apidoc.paths is undefined, this will throw a TypeError.

Suggested change
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}`
}
})
})
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot fix this according to #404 (comment)

Copilot AI 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.

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'].url with ${gwApiUrl}${path} for each operation in apidoc.paths when --json is used.
  • Update/extend Jest coverage to assert the URL is now present and to verify operations without x-openwhisk remain 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.

Comment thread src/commands/runtime/api/list.js
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@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 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

Comment thread src/commands/runtime/api/list.js
Comment thread src/commands/runtime/api/list.js Outdated
Comment on lines +64 to +65

const api = result.apis[0]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Re-raised] No null check on apidoc or apidoc.paths before calling Object.keys. If either is undefined this will throw a TypeError.

Suggested change
const api = result.apis[0]
const apidoc = api.value.apidoc
const gwApiUrl = api.value.gwApiUrl
if (!apidoc || !apidoc.paths) {
this.logJSON('', apidoc || {})
return
}

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

Superseded by new review

shazron and others added 2 commits April 27, 2026 16:04
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 dismissed their stale review April 27, 2026 08:04

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 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.

@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 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.

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

Superseded by new review

@shazron

shazron commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

Closing because I can't make heads or tails on the 2 bots changing things 🙃

@shazron shazron closed this Apr 27, 2026
@shazron

shazron commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

see #409

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

3 participants