Skip to content

feat: environment-aware API Try Out console (OpenAPI & GraphQL)#670

Merged
NomadXD merged 22 commits into
mainfrom
feat/api-tryout-console
Jul 9, 2026
Merged

feat: environment-aware API Try Out console (OpenAPI & GraphQL)#670
NomadXD merged 22 commits into
mainfrom
feat/api-tryout-console

Conversation

@NomadXD

@NomadXD NomadXD commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Reworks the catalog API entity page into three tabs and adds an environment-aware Try Out experience so users can invoke their deployed APIs directly from the portal.

  • Overview — unchanged.
  • Definition — renders the raw schema in the shared read-only YamlEditor (with a copy button), consistent with the Component/Resource definition tab.
  • Try Out — an interactive, environment-aware console.

Related to openchoreo/openchoreo#4118

Try Out

A Connection card (styled like the deploy page's environment card) sits at the top of the console:

  • Environment selector — lists the component's environments (pipeline order); environments with no deployment are disabled.
  • Endpoint — the selected environment's public API-gateway invoke URL (resolved via the existing useEnvironmentData / derivePrimaryUrl plumbing), shown as a copyable link.
  • Authentication — configure how test requests are authenticated (see below).

OpenAPI console

Screen.Recording.2026-07-07.at.15.55.13.mov

GraphQL console

Screen.Recording.2026-07-09.at.08.47.14.mov

Unsupported endpoints

Screen.Recording.2026-07-07.at.16.00.29.mov

No deployments available

Screen.Recording.2026-07-09.at.08.49.57.mov

Internal endpoints not supported

Screen.Recording.2026-07-09.at.12.29.28.mov

Per API type:

  • OpenAPI → SwaggerUI console. The spec's server is rewritten to the selected environment's gateway URL (so "Try it out" hits the deployed gateway), and SwaggerUI's native "Servers" block is suppressed in favour of the Connection card.
  • GraphQL → GraphiQL console (lazy-loaded), with an environment-aware fetcher and its theme matched to the active OpenChoreo/Backstage theme. Docs/autocomplete are populated from the SDL.
  • gRPC / WebSocket / other → an informational notice ("Interactive testing isn't available for this API type yet"); the raw schema remains on the Definition tab.

Authentication (client-side)

Configured in the Connection card and applied to every test request in both consoles (SwaggerUI requestInterceptor / GraphiQL custom fetch, via a shared headers ref so editing the form never re-initializes the console):

  • API Key — header name + value.
  • Bearer token — sent as Authorization: Bearer ….
  • OAuth2 (Client Credentials) — token endpoint + client id/secret; a Get token button performs the client_credentials grant directly from the browser and the returned access token is sent as a Bearer token.

Dependencies

Adds to @openchoreo/backstage-plugin: graphiql, @graphiql/toolkit, graphql, graphql-ws.

Notes / caveats

  • Being client-side, live requests are subject to the API gateway's (and the OAuth2 token endpoint's) CORS policy for the Backstage origin.
  • The OAuth2 client secret is entered/handled in the browser and kept only in component state (not persisted).

Testing

  • yarn tsc and yarn backstage-cli repo lint pass.
  • Verified in a local k3d cluster: OpenAPI (reading-list) and GraphQL sample APIs render their consoles, environment selection re-targets the endpoint, and auth headers are attached to outgoing requests.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added a new “Try Out” tab for API entity pages with OpenAPI (Swagger UI) and GraphQL (GraphiQL) consoles.
    • Added a raw API definition card with read-only viewing and copy-to-clipboard.
  • Bug Fixes
    • Improved behavior when definitions or deployed environments are missing, including clearer empty states.
    • Ensured auth/header updates apply to active console requests; added safer endpoint rewriting fallbacks.
  • Tests
    • Expanded coverage for environment selection, console rendering, auth flows, and header/copy interactions.

NomadXD added 11 commits July 6, 2026 10:48
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Changeset detected — the following file(s) will be released with this PR:

.changeset/api-tryout-console.md

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a raw API definition viewer and an environment-aware Try Out console for OpenAPI and GraphQL entities, with auth inputs, token exchange, route wiring, exports, and tests.

Changes

API definition viewing and Try Out console

Layer / File(s) Summary
Raw definition viewer card
packages/app/src/components/catalog/ApiDefinitionTabs.tsx, packages/app/src/components/catalog/EntityPage.tsx
Adds ApiRawDefinitionCard to render the entity definition in a read-only YamlEditor with copy-to-clipboard behavior, and routes /definition to the new card.
Dependencies and exports
plugins/openchoreo/package.json, plugins/openchoreo/src/components/ApiTryOut/index.ts, plugins/openchoreo/src/index.ts, .changeset/api-tryout-console.md
Adds GraphQL/GraphiQL dependencies, re-exports ApiTryOut, exposes it from the plugin entrypoint, and records the minor release changeset.
Auth state and token flow
plugins/openchoreo/src/components/ApiTryOut/useTryOutAuth.ts, plugins/openchoreo/src/components/ApiTryOut/useTryOutAuth.test.ts
Adds auth config state, header derivation, OAuth2 token exchange, live header refs, and hook tests for header building and token handling.
Auth form UI
plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.tsx, plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.test.tsx
Adds the scheme selector and conditional API key, bearer, and OAuth2 inputs, plus tests for scheme switching, secret toggling, and token controls.
GraphQL console
plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.tsx, plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.test.tsx
Adds the GraphiQL-based console that compiles SDL into a schema, creates a URL-aware fetcher, and merges live auth headers; tests cover schema handling and fetcher behavior.
Try Out orchestration
plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.tsx, plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.test.tsx
Adds environment selection, server URL rewriting, the SwaggerUI connection panel/plugin, request interception, and branching for OpenAPI, GraphQL, and unsupported entities, with tests covering the main UI and data-flow paths.

Estimated code review effort: 4 (Complex) | ~60 minutes

Suggested reviewers: sameerajayasoma, stefinie123, Mirage20, kaviththiranga

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the feature well, but it misses most required template sections like Purpose, Goals, Approach, Documentation, and Security checks. Add the missing template sections with issue links, goals, approach, docs, tests, security checks, and the other required metadata.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: an environment-aware API Try Out console for OpenAPI and GraphQL.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/api-tryout-console

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.tsx (1)

281-309: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Pin the Swagger UI override to the exact component contract. wrapComponents.info and the Servers/ServersContainer overrides rely on Swagger UI component names that can shift across upgrades; pin the resolved swagger-ui-react version and keep a regression check for the .scheme-container fallback.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.tsx` around lines 281 -
309, The Swagger UI overrides in ApiTryOut rely on component names that may
change across upgrades, so pin the resolved swagger-ui-react version used by
connectionPlugin and keep a regression check for the useConsoleStyles
.scheme-container fallback. Review the wrapComponents.info, Servers, and
ServersContainer overrides in ApiTryOut.tsx and make sure they are treated as
version-coupled behavior, with any upgrade changes validated against those exact
contracts.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/app/src/components/catalog/ApiDefinitionTabs.tsx`:
- Around line 57-61: The copy handler in ApiDefinitionTabs’s handleCopy
currently marks success even when navigator.clipboard.writeText fails or is
unavailable. Make handleCopy async, await the writeText call, and only call
setCopied(true) after a successful write; on failure, skip the success state and
optionally handle the error so the UI does not show false copy feedback.

In `@plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.tsx`:
- Around line 354-361: The `ApiTryOut` selection logic is not revalidating
`selected` when `environments` changes, so stale environment objects can keep
driving `activeUrl` and `effectiveDefinition` after a refetch. Update the
`useEffect` in `ApiTryOut.tsx` to detect when the current `selected` no longer
exists in the refreshed `environments` list and reset or replace it with a valid
environment (for example the first deployed one), and make sure the downstream
selection-dependent logic around `activeUrl`/`effectiveDefinition` uses the
validated environment state rather than the stale object.

In `@plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.tsx`:
- Around line 44-50: The GraphQL schema build in GraphQlConsole is swallowing
parse/validation failures, so users get no indication when the SDL is invalid.
Update the useMemo around buildSchema(definition) to capture the thrown error
and surface it through the console UI state used by GraphQlConsole, rather than
returning undefined silently. Use the existing schema-building flow and related
docs/autocomplete rendering logic to show a clear error or fallback message when
schema compilation fails.

In `@plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.tsx`:
- Around line 119-133: The secret visibility toggle in TryOutAuthFields is
removed from the keyboard tab order by tabIndex={-1}, making it inaccessible to
keyboard-only users. Update the toggle button in TryOutAuthFields so it can
receive focus via keyboard, while keeping the existing show/hide behavior tied
to setShow, show, and the aria-label state.

In `@plugins/openchoreo/src/components/ApiTryOut/useTryOutAuth.ts`:
- Around line 17-22: Expired OAuth2 tokens are still being reused because
`OAuthState.expiresAt` is never checked before building auth headers. Update
`buildAuthHeaders` in `useTryOutAuth` to accept `expiresAt` (or the full `oauth`
state) and treat `token` as unavailable once `Date.now() >= expiresAt`, so
expired tokens are not sent. Then make sure the auth flow that calls
`buildAuthHeaders` uses this new expiry-aware behavior and returns the
unauthenticated/refresh-needed state instead of attaching a stale bearer token.

---

Nitpick comments:
In `@plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.tsx`:
- Around line 281-309: The Swagger UI overrides in ApiTryOut rely on component
names that may change across upgrades, so pin the resolved swagger-ui-react
version used by connectionPlugin and keep a regression check for the
useConsoleStyles .scheme-container fallback. Review the wrapComponents.info,
Servers, and ServersContainer overrides in ApiTryOut.tsx and make sure they are
treated as version-coupled behavior, with any upgrade changes validated against
those exact contracts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c2627a0f-6089-4e56-8b5f-1107b3d81705

📥 Commits

Reviewing files that changed from the base of the PR and between 6b8a9bd and c731e9a.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • packages/app/src/components/catalog/ApiDefinitionTabs.tsx
  • packages/app/src/components/catalog/EntityPage.tsx
  • plugins/openchoreo/package.json
  • plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.tsx
  • plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.tsx
  • plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.tsx
  • plugins/openchoreo/src/components/ApiTryOut/index.ts
  • plugins/openchoreo/src/components/ApiTryOut/useTryOutAuth.ts
  • plugins/openchoreo/src/index.ts

Comment thread packages/app/src/components/catalog/ApiDefinitionTabs.tsx
Comment thread plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.tsx
Comment thread plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.tsx
Comment thread plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.tsx
Comment thread plugins/openchoreo/src/components/ApiTryOut/useTryOutAuth.ts
NomadXD added 2 commits July 7, 2026 17:29
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>

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

🧹 Nitpick comments (1)
plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.test.tsx (1)

57-81: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Restore global.fetch mock via afterEach, not just end-of-test.

If an assertion in this test throws before Line 80, fetchSpy.mockRestore() never runs, leaking the spy into later tests.

♻️ Suggested fix
+afterEach(() => {
+  jest.restoreAllMocks();
+});
+
 describe('GraphQlConsole', () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.test.tsx` around
lines 57 - 81, The `GraphQlConsole` fetch spy is only restored at the end of the
test, so a failing assertion can leak the mocked `global.fetch` into later
tests. Move the cleanup for `fetchSpy` into a shared `afterEach` in
`GraphQlConsole.test.tsx` so the mock is always restored, and keep the test body
focused on verifying `createGraphiQLFetcher` and the injected auth headers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.test.tsx`:
- Around line 57-81: The `GraphQlConsole` fetch spy is only restored at the end
of the test, so a failing assertion can leak the mocked `global.fetch` into
later tests. Move the cleanup for `fetchSpy` into a shared `afterEach` in
`GraphQlConsole.test.tsx` so the mock is always restored, and keep the test body
focused on verifying `createGraphiQLFetcher` and the injected auth headers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2f95426b-2b1e-46c2-bb2e-18d9ae1ecaea

📥 Commits

Reviewing files that changed from the base of the PR and between c731e9a and c1b8b95.

📒 Files selected for processing (6)
  • .changeset/api-tryout-console.md
  • plugins/openchoreo/src/components/ApiTryOut/ApiTryOut.test.tsx
  • plugins/openchoreo/src/components/ApiTryOut/GraphQlConsole.test.tsx
  • plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.test.tsx
  • plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.tsx
  • plugins/openchoreo/src/components/ApiTryOut/useTryOutAuth.test.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/api-tryout-console.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/openchoreo/src/components/ApiTryOut/TryOutAuthFields.tsx

NomadXD added 5 commits July 7, 2026 20:32
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
NomadXD added 2 commits July 8, 2026 17:47
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
stefinie123
stefinie123 previously approved these changes Jul 9, 2026

@stefinie123 stefinie123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be better to give a link to the deploy page in the message when the API is not deployed to any environment.

We can add that as an improvement in another PR

LakshanSS
LakshanSS previously approved these changes Jul 9, 2026

@LakshanSS LakshanSS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@stefinie123

stefinie123 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@NomadXD What will be the user experience if a given endpoint visibility is set to internal ? In that case does Try out make any sense ?
Additionally can you check whether we showed an interactive UI for Async APIs before these changes and with these changes we have removed it. If so, lets add it back

Signed-off-by: Lahiru De Silva <lahirude@wso2.com>
@NomadXD NomadXD dismissed stale reviews from LakshanSS and stefinie123 via 9781247 July 9, 2026 06:59
@NomadXD NomadXD merged commit 5222138 into main Jul 9, 2026
9 checks passed
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.

3 participants