Skip to content

feat: add user token OpenAPI contract#35

Merged
nobodyiam merged 2 commits into
apolloconfig:mainfrom
klboke:kl-user-token-openapi
Jun 9, 2026
Merged

feat: add user token OpenAPI contract#35
nobodyiam merged 2 commits into
apolloconfig:mainfrom
klboke:kl-user-token-openapi

Conversation

@klboke

@klboke klboke commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

What's changed

  • Add User Token Management OpenAPI tag and current-token endpoints:
    • GET /openapi/v1/user-tokens/current
    • GET /openapi/v1/user-tokens/current/capabilities
    • GET /openapi/v1/user-tokens/whoami
  • Add generated response models for current user token identity, namespace scope, and callable OpenAPI actions.
  • Add contract tests covering the new paths and schema shape.

Related Apollo change

This contract is needed by apolloconfig/apollo#5632 so Apollo Portal can implement the generated UserTokenManagementApi interface instead of hand-written OpenAPI mappings.

Tests

  • /usr/bin/python3 -m unittest discover -s tests
  • ./generate.sh --verify

Summary by CodeRabbit

Release Notes

  • New Features
    • Added User Token Management endpoints to retrieve current token identity and permission scope
    • New endpoint to list callable capabilities for the current token
    • Added whoami alias endpoint for quick token identification

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@klboke, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 22 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d2f5578-254e-424c-b80f-4f0ed595b8fd

📥 Commits

Reviewing files that changed from the base of the PR and between 81bb1f6 and a1b8387.

📒 Files selected for processing (2)
  • apollo-openapi.yaml
  • tests/test_user_token_contract.py
📝 Walkthrough

Walkthrough

This PR introduces a new User Token Management API contract to the Apollo OpenAPI specification. Three new endpoints expose the current token's identity, permission scope, callable capabilities, and a whoami alias. The contract is validated via a new unittest module that verifies endpoint presence, operationIds, schema references, and detailed property constraints.

Changes

User Token Management API

Layer / File(s) Summary
User Token Management API Contract Definition
apollo-openapi.yaml
Adds the User Token Management tag and three GET endpoints (/current, /current/capabilities, /whoami) with operationIds and 403 responses. Defines OpenUserTokenCurrentCapability schema with nested OpenUserTokenNamespaceScope and OpenUserTokenOpenApiAction structures, including fields for token identity, rate limiting, expiry, and callable OpenAPI action metadata.
Contract Validation Tests
tests/test_user_token_contract.py
New unittest module that loads apollo-openapi.yaml and validates tag presence, endpoint presence with correct operationIds and tags, response schema references, and OpenUserTokenCurrentCapability schema properties including types, formats, uniqueness constraints, and nested $ref targets.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A token to tell who you are,
Three endpoints to shine like a star!
With scope and with might,
Your permissions laid bright—
The specs validated near and far! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add user token OpenAPI contract' accurately and concisely describes the main change: introducing a new OpenAPI contract for user token management with new endpoints and schema definitions.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@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)
apollo-openapi.yaml (1)

6931-7061: ⚡ Quick win

Consider documenting which fields are required in the OpenUserTokenCurrentCapability schema.

The schema defines approximately 30 properties but lacks a required array. While this makes all fields optional by default, it's unclear whether this is intentional or an oversight. Key fields like authType, userId, tokenId appear semantically required for a token capability response.

For API contract clarity, consider adding a required array if certain fields will always be present, similar to other schemas in this spec that define required fields.

💡 Example required fields specification
 OpenUserTokenCurrentCapability:
   type: object
   description: 当前用户访问Token身份、权限范围和可调用OpenAPI能力
+  required:
+    - authType
+    - userId
+    - tokenId
   properties:
     authType:
       type: string
🤖 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 `@apollo-openapi.yaml` around lines 6931 - 7061, The
OpenUserTokenCurrentCapability schema lacks a "required" array making all ~30
properties optional; add a required array listing fields that must always be
returned (e.g. authType, userId, tokenId, tokenName, tokenPrefix, expires) or
adjust to the actual contract; update the OpenUserTokenCurrentCapability
schema's properties block to include a "required" array with those field names
and ensure any downstream validation/serialization code (token creation/response
logic) returns those fields accordingly.
🤖 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 `@apollo-openapi.yaml`:
- Around line 6931-7061: The OpenUserTokenCurrentCapability schema lacks a
"required" array making all ~30 properties optional; add a required array
listing fields that must always be returned (e.g. authType, userId, tokenId,
tokenName, tokenPrefix, expires) or adjust to the actual contract; update the
OpenUserTokenCurrentCapability schema's properties block to include a "required"
array with those field names and ensure any downstream validation/serialization
code (token creation/response logic) returns those fields accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8dd952c3-a078-42bf-8c1f-00ba1a0b5830

📥 Commits

Reviewing files that changed from the base of the PR and between a5ffbd9 and 81bb1f6.

📒 Files selected for processing (2)
  • apollo-openapi.yaml
  • tests/test_user_token_contract.py

@nobodyiam nobodyiam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed current head a1b8387. The new User Token Management paths and response model match the referenced Apollo implementation shape, generate the expected UserTokenManagementApi, and the required-fields follow-up has been addressed. I also verified the local contract tests, generation check, and generated project compile successfully.

Non-blocking follow-up: OpenUserTokenOpenApiAction currently leaves its catalog fields optional in the schema, so generated clients treat fields like id, method, path, requiredOperations, grantedOperations, operationMatch, resourceScope, and description as nullable. Since this endpoint is intended to expose a machine-readable action catalog, it would be clearer to mark those nested action fields as required in a later cleanup.

No blocking findings from my side.

@nobodyiam
nobodyiam merged commit 6085f59 into apolloconfig:main Jun 9, 2026
5 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.

2 participants