mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Emulator Test / docker (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Test / docker (push) Has been cancelled
Runs E2E API Tests / build (22.x) (push) Has been cancelled
Runs E2E API Tests with external source of truth / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Mirror main branch to main-mirror-for-wdb / lint_and_build (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
<!--
Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md
-->
<!-- ELLIPSIS_HIDDEN -->
----
> [!IMPORTANT]
> Fixes circular dependencies by restructuring OpenAPI type definitions
and updating API paths, with enhancements to the API Explorer.
>
> - **Breaking Changes**:
> - MCP API endpoints are now prefixed with `/api/internal` instead of
`/api`.
> - **New Features**:
> - API Explorer now supports building JSON request bodies from
individual fields.
> - Generated curl/JavaScript/Python snippets reflect the new body
builder.
> - **Bug Fixes**:
> - Improved URL handling in the API Explorer to prevent errors when
server URLs are missing.
> - **Refactor**:
> - Centralized OpenAPI type definitions into `openapi-types.ts` for
consistency and reuse.
> - Updated imports in `enhanced-api-page.tsx` and `openapi-utils.ts` to
use the new `openapi-types.ts`.
>
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for bb27147b03. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>
----
<!-- ELLIPSIS_HIDDEN -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Centralized OpenAPI type definitions into a shared module for
consistency.
* Updated internal tool API routing under an internal namespace; no
user-facing behavior changes.
* Improved URL handling with safer fallbacks.
* Switched request builder to field-based JSON bodies for clearer, more
reliable payload construction.
* **Documentation**
* Regenerated code examples (cURL/JS/Python) to reflect safer URL
handling and structured JSON bodies.
* Aligned docs components with shared types for improved
maintainability.
* **Chores**
* Adjusted internal imports and paths to match new module locations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import type { OpenAPISchema, OpenAPISpec } from './openapi-types';
|
|
|
|
/**
|
|
* Resolves $ref references in OpenAPI schemas recursively
|
|
* @param schema - The schema to resolve
|
|
* @param spec - The OpenAPI specification containing the schema definitions
|
|
* @param visited - Set of visited $ref paths to prevent infinite recursion
|
|
* @returns The resolved schema
|
|
*/
|
|
export const resolveSchema = (schema: OpenAPISchema, spec: OpenAPISpec, visited = new Set<string>()): OpenAPISchema => {
|
|
if (schema.$ref) {
|
|
// Prevent infinite recursion
|
|
if (visited.has(schema.$ref)) {
|
|
console.warn(`Circular $ref reference detected: ${schema.$ref}`);
|
|
return schema;
|
|
}
|
|
|
|
visited.add(schema.$ref);
|
|
const refPath = schema.$ref.replace('#/', '').split('/');
|
|
let refSchema: Record<string, unknown> = spec as Record<string, unknown>;
|
|
for (const part of refPath) {
|
|
const nextSchema = refSchema[part];
|
|
if (!nextSchema || typeof nextSchema !== 'object') {
|
|
console.error(`Failed to resolve $ref: ${schema.$ref}`);
|
|
return schema;
|
|
}
|
|
refSchema = nextSchema as Record<string, unknown>;
|
|
}
|
|
|
|
// Recursively resolve the resolved schema in case it contains more $refs
|
|
const resolvedSchema = resolveSchema(refSchema as OpenAPISchema, spec, visited);
|
|
visited.delete(schema.$ref);
|
|
return resolvedSchema;
|
|
}
|
|
return schema;
|
|
};
|