@devries-cameron20 / composio Mirror · read-only / commits / 947bfb459
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 13:30 UTC

fix(docs): filter deprecated fields only in playground

Brendan O'Leary committed Sep 10, 2026 at 09:50 UTC 947bfb4590f2221a96b260368df8210a797f6bf7
4 files changed +80 -11
docs/components/api-page.tsx
+67 -3
@@ -1,13 +1,22 @@
1 'use client';
2
3 -import { createElement, type FC, type ReactNode } from 'react';
4 -import { createOpenAPIPage } from 'fumadocs-openapi/ui';
3 +import {
4 + createContext, createElement, use, useEffect, useEffectEvent, useMemo,
5 + type FC, type ReactNode,
6 +} from 'react';
7 +import {
8 + createOpenAPIPage, useOperationContext, useServerContext, type APIPlaygroundProps,
9 +} from 'fumadocs-openapi/ui';
10 +import { hideDeprecatedFields } from '@/lib/openapi-deprecated';
11 import { generateSchemaData } from './schema-generator';
12 import { CustomSchemaUI } from './custom-schema-ui';
13
14 export const APIPage = createOpenAPIPage({
15 generateTypeScriptDefinitions: false,
10 - playground: { enabled: true },
16 + playground: {
17 + enabled: true,
18 + render: (props) => <DeprecatedFieldsPlayground {...props} />,
19 + },
20 schemaUI: {
21 render: (options, ctx) => {
22 const client = (
@@ -54,6 +63,61 @@ export const APIPage = createOpenAPIPage({
63 },
64 });
65
66 +// A separate page context keeps filtered schemas and initial request examples
67 +// inside the playground. The surrounding reference uses the complete contract.
68 +const PlaygroundSyncContext = createContext<{
69 + operation: ReturnType<typeof useOperationContext>;
70 + server: ReturnType<typeof useServerContext>;
71 +} | null>(null);
72 +
73 +function PlaygroundSync({ children }: { children: ReactNode }) {
74 + const parent = use(PlaygroundSyncContext)!;
75 + const { example, setExample, addListener, removeListener } = useOperationContext();
76 + const { server } = useServerContext();
77 + useEffect(() => {
78 + if (parent.operation.example && parent.operation.example !== example)
79 + setExample(parent.operation.example);
80 + }, [parent.operation.example, example, setExample]);
81 + useEffect(() => {
82 + const listener = parent.operation.setExampleData;
83 + addListener(listener);
84 + return () => removeListener(listener);
85 + }, [addListener, removeListener, parent.operation.setExampleData]);
86 + const syncServer = useEffectEvent(() => {
87 + if (!server) return;
88 + parent.server.setServer(server.url);
89 + parent.server.setServerVariables(server.variables);
90 + });
91 + useEffect(() => {
92 + syncServer();
93 + }, [server]);
94 + return children;
95 +}
96 +
97 +const PlaygroundPage = createOpenAPIPage({
98 + generateTypeScriptDefinitions: false,
99 + content: {
100 + renderOperationLayout: ({ apiPlayground }) => <PlaygroundSync>{apiPlayground}</PlaygroundSync>,
101 + },
102 +});
103 +
104 +function DeprecatedFieldsPlayground({ path, method, ctx }: APIPlaygroundProps) {
105 + const operation = useOperationContext();
106 + const server = useServerContext();
107 + const bundled = useMemo(
108 + () => hideDeprecatedFields(ctx.schema.bundled),
109 + [ctx.schema.bundled]
110 + );
111 + return (
112 + <PlaygroundSyncContext value={{ operation, server }}>
113 + <PlaygroundPage
114 + payload={{ bundled, proxyUrl: ctx.proxyUrl }}
115 + operations={[{ path, method }]}
116 + />
117 + </PlaygroundSyncContext>
118 + );
119 +}
120 +
121 function getRawRef(value: object): string | undefined {
122 if (!('$ref' in value)) return undefined;
123 return typeof value.$ref === 'string' ? value.$ref : undefined;
docs/lib/openapi-deprecated.ts
+1 -1
@@ -33,7 +33,7 @@ const SCHEMA_CHILDREN = new Set([
33 'unevaluatedProperties',
34 ]);
35
36 -/** Filter only the copy used by the docs; keep the published API contract intact. */
36 +/** Filter only the playground copy; keep the reference and published contract intact. */
37 export function hideDeprecatedFields<T extends object>(input: T): T {
38 const document = structuredClone(input);
39 function object(value: unknown) {
docs/lib/openapi.ts
+1 -2
@@ -1,6 +1,5 @@
1 import { readFile } from 'node:fs/promises';
2 import { join } from 'path';
3 -import { hideDeprecatedFields } from './openapi-deprecated';
3 import { createOpenAPI } from 'fumadocs-openapi/server';
4 import { declareOperationTags, type OpenAPIDocument } from './openapi-tags';
5
@@ -35,7 +34,7 @@ export const openapiV3 = createOpenAPI({
34
35 async function loadOpenAPISchema(path: string) {
36 const document = JSON.parse(await readFile(path, 'utf8')) as OpenAPIDocument;
38 - return declareOperationTags(normalizeNoAuthSecurity(hideDeprecatedFields(document)));
37 + return declareOperationTags(normalizeNoAuthSecurity(document));
38 }
39
40 export function normalizeNoAuthSecurity<T extends OpenAPIDocument>(document: T): T {
docs/tests/static/openapi-deprecated.test.ts
+11 -5
@@ -4,7 +4,7 @@ import { join } from 'node:path';
4 import { hideDeprecatedFields } from '../../lib/openapi-deprecated';
5 import { openapi, openapiV3 } from '../../lib/openapi';
6
7 -describe('docs OpenAPI deprecation filter', () => {
7 +describe('playground OpenAPI deprecation filter', () => {
8 test('removes fields and their values while preserving the source and legacy operations', () => {
9 const schema = {
10 type: 'object',
@@ -144,19 +144,24 @@ describe('docs OpenAPI deprecation filter', () => {
144 expect(hideDeprecatedFields(source)).toEqual(source);
145 });
146
147 - test('filters the actual documents consumed by both schema UI and playground', async () => {
147 + test('keeps deprecated reference fields and filters only the playground copy', async () => {
148 for (const server of [openapi, openapiV3]) {
149 const schemas = await server.getSchemas();
150 for (const [path, { bundled }] of Object.entries(schemas)) {
151 if (path.endsWith('openapi-webhooks.json')) continue;
152 - const managed = bundled.components?.schemas?.ComposioManagedAuthConfigCreate;
152 + const original = structuredClone(bundled);
153 + const reference = bundled.components?.schemas?.ComposioManagedAuthConfigCreate;
154 + expect(reference).toHaveProperty('properties.tool_access_config');
155 + expect(reference).toHaveProperty('properties.restrict_to_following_tools');
156 + const playground = hideDeprecatedFields(bundled);
157 + const managed = playground.components?.schemas?.ComposioManagedAuthConfigCreate;
158 expect(managed).toHaveProperty('properties.credentials');
159 expect(managed).not.toHaveProperty('properties.tool_access_config');
160 expect(managed).not.toHaveProperty('properties.restrict_to_following_tools');
156 - expect(bundled.components?.schemas?.CustomAuthConfigCreate).not.toHaveProperty(
161 + expect(playground.components?.schemas?.CustomAuthConfigCreate).not.toHaveProperty(
162 'properties.tool_access_config'
163 );
159 - const operation = Object.values(bundled.paths ?? {})
164 + const operation = Object.values(playground.paths ?? {})
165 .flatMap(item => item?.post ?? [])
166 .find(
167 item =>
@@ -164,6 +169,7 @@ describe('docs OpenAPI deprecation filter', () => {
169 );
170 expect(operation).toBeDefined();
171 expect(JSON.stringify(operation?.requestBody)).not.toContain('restrict_to_following_tools');
172 + expect(bundled).toEqual(original);
173 }
174 }
175 // The downloadable contract remains complete on disk.