Skip to content

Conversation

@trheyi
Copy link
Contributor

@trheyi trheyi commented Jan 4, 2026

https://github.com/yaoapp/yao/blob/main/openapi/docs/migration-guide.md

Summary

This PR integrates OpenAPI functionality into the Yao service layer, enabling seamless switching between traditional JWT mode and OpenAPI OAuth mode. Key features include dynamic API routing, hot-reload support, and unified guard mechanism.

Breaking Changes

  • When OpenAPI is enabled, all API routes move from /api to /{baseURL} (e.g., /v1)
  • Developer APIs are now under /{baseURL}/api/*
  • Built-in widget APIs are under /{baseURL}/__yao/*

Key Changes

GOU Layer

  • Dynamic routing: Added RouteTable, FindHandler(), BuildRouteTable() for runtime route lookup
  • API hot-reload: Added ReloadAPIs() to reload API definitions without restart
  • Handler extraction: Extracted BuildHandler() for dynamic handler building
  • Auth propagation: getAuthorizedInfo() now supports both __authorized map and individual context fields (__subject, __scope, etc.)

YAO Layer

  • Guard switching: OpenAPIGuards() returns OAuth guards when OpenAPI is enabled, directly using oauth.OAuth.Guard
  • Dynamic proxy: DynamicAPIHandler proxies developer API requests with hot-reload support
  • Watch integration: File watcher calls ReloadAPIs() instead of Restart() in OpenAPI mode
  • SUI auth fix: SUI Run now passes authorized info to V8 context
  • Well-known endpoint: Added /.well-known/yao for client-side configuration discovery

ACL Layer

  • Wildcard merge: Wildcard path endpoints now merge RequiredScopes correctly
  • Recursive alias: expandUserScopes() now recursively expands nested aliases
  • Scope structure: Reorganized scopes into __yao/* (built-in) and api/* (developer)

Frontend (CUI)

  • Dynamic API base: All services use getApiBase() from wellknown.ts
  • Sync metadata fetch: /.well-known/yao fetched synchronously at startup
  • Path fixes: Removed hardcoded /api/ paths throughout

Migration Guide (v0 → v1)

1. Enable OpenAPI

Add openapi.yao configuration to your app root.

2. Update API Paths

Before After (OpenAPI enabled)
/api/your-endpoint /v1/api/your-endpoint
/api/__yao/app/setting /v1/__yao/app/setting

3. Guard Compatibility

No changes needed. Existing guards (bearer-jwt, cookie-jwt, etc.) automatically map to OAuth when OpenAPI is enabled.

4. Scope Configuration

Add scope files for your custom APIs:

openapi/scopes/__yao/yao.yml

__yao:yao:execute:all:
endpoints:
- GET /__yao/*
- POST /__yao/*

openapi/scopes/api/api.yml

api:api:execute:all:
endpoints:
- GET /api/*
- POST /api/*

trheyi added 2 commits January 4, 2026 12:06
- Added new examples for backend script method calls from `.json` configurations, enhancing practical understanding for developers.
- Clarified usage of request parameters and common pitfalls, improving guidance for effective backend script implementation.
- Updated existing sections to ensure consistency and clarity in documentation, supporting better developer experience.
- Introduced support for OpenAPI mode, allowing dynamic routing and OAuth guards for API endpoints.
- Updated API root path handling to accommodate OpenAPI configurations, ensuring consistent URL structures.
- Added well-known routes for Yao metadata and OAuth discovery, improving API discoverability.
- Refactored middleware and guards to streamline OpenAPI integration, enhancing overall service functionality.
- Removed deprecated agent TypeScript file, simplifying the codebase and improving maintainability.
@trheyi trheyi merged commit fd28aa5 into YaoApp:main Jan 4, 2026
3 of 4 checks passed
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Thank you for the PR! The db: SQLite3 redis: 4 mongo: 6.0 test workflow is running, the results of the run will be commented later.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Thank you for the PR! The db: MySQL8.0 redis: 6 mongo: 6.0 test workflow is running, the results of the run will be commented later.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Thank you for the PR! The db: SQLite3 redis: 6 mongo: 6.0 test workflow is running, the results of the run will be commented later.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Thank you for the PR! The db: SQLite3 redis: 5 mongo: 6.0 test workflow is running, the results of the run will be commented later.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Thank you for the PR! The db: MySQL8.0 redis: 5 mongo: 6.0 test workflow is running, the results of the run will be commented later.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Thank you for the PR! The db: MySQL8.0 redis: 4 mongo: 6.0 test workflow is running, the results of the run will be commented later.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

🤖 AI Tests (agent, aigc) running with SQLite...

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

🤖 KB Tests (kb) running with SQLite...

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✅ KB Tests (kb) passed!

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✨DONE✨ db: SQLite3 redis: 4 mongo: 6.0 passed.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✨DONE✨ db: SQLite3 redis: 6 mongo: 6.0 passed.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✨DONE✨ db: SQLite3 redis: 5 mongo: 6.0 passed.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✨DONE✨ db: MySQL8.0 redis: 5 mongo: 6.0 passed.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✅ AI Tests (agent, aigc) passed!

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✨DONE✨ db: MySQL8.0 redis: 6 mongo: 6.0 passed.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

✨DONE✨ db: MySQL8.0 redis: 4 mongo: 6.0 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.

1 participant