diff --git a/src/source-spec-transformer.js b/src/source-spec-transformer.js index e8dbdbbd..511e484e 100644 --- a/src/source-spec-transformer.js +++ b/src/source-spec-transformer.js @@ -85,6 +85,10 @@ function rewriteRefs(obj, refMap) { }); } +function transformPlatformTagGroups(spec) { + delete spec['x-tagGroups']; +} + function platformSchemaName(name) { return name.startsWith('Platform') ? name : `Platform${name}`; } @@ -279,6 +283,7 @@ function transformPlatformOperations(spec) { } export function transformPlatformSpec(spec) { + transformPlatformTagGroups(spec); transformPlatformSchemas(spec); transformPlatformResponses(spec); transformPlatformApiTokenSecurity(spec); diff --git a/tests/source-spec-transformer.test.js b/tests/source-spec-transformer.test.js index a0b3d74b..3d2714e1 100644 --- a/tests/source-spec-transformer.test.js +++ b/tests/source-spec-transformer.test.js @@ -232,6 +232,7 @@ describe('OpenAPI YAML Transformer', () => { const platformSpec = { openapi: '3.0.0', info: { title: 'Glean Platform API', version: '2026-04-01' }, + 'x-tagGroups': [{ name: 'Platform', tags: ['Search'] }], servers: [{ url: 'https://{domain}-be.glean.com/api' }], components: { securitySchemes: { @@ -259,10 +260,41 @@ describe('OpenAPI YAML Transformer', () => { }, }, Tool: { type: 'object' }, + ToolCallRequest: { type: 'object' }, + ToolCallResponse: { + type: 'object', + properties: { + result: { $ref: '#/components/schemas/Result' }, + }, + }, + PersonReference: { type: 'object' }, + Person: { type: 'object' }, + DocumentSpec: { type: 'object' }, + PeopleSearchResponse: { + type: 'object', + properties: { + people: { + type: 'array', + items: { $ref: '#/components/schemas/Person' }, + }, + }, + }, + RunRequest: { type: 'object' }, + RunEvent: { type: 'object' }, Result: { type: 'object', properties: { related: { $ref: '#/components/schemas/SearchRequest' }, + creator: { $ref: '#/components/schemas/PersonReference' }, + }, + }, + SummarizeRequest: { + type: 'object', + properties: { + document_specs: { + type: 'array', + items: { $ref: '#/components/schemas/DocumentSpec' }, + }, }, }, PlatformExisting: { type: 'object' }, @@ -322,6 +354,64 @@ describe('OpenAPI YAML Transformer', () => { }, }, }, + '/tools/call': { + post: { + tags: ['Tools'], + operationId: 'platform-tools-call', + 'x-glean-sdk': { + group: 'platform.tools', + method: 'call', + }, + requestBody: { + content: { + 'application/json': { + schema: { $ref: '#/components/schemas/ToolCallRequest' }, + }, + }, + }, + responses: { + 200: { + description: 'ok', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/ToolCallResponse', + }, + }, + }, + }, + }, + }, + }, + '/agents/{agent_id}/runs': { + post: { + tags: ['Agents'], + operationId: 'platform-agents-create-run', + 'x-glean-sdk': { + group: 'platform.agents', + method: 'createRun', + }, + requestBody: { + content: { + 'application/json': { + schema: { $ref: '#/components/schemas/RunRequest' }, + }, + }, + }, + responses: { + 200: { + description: 'ok', + content: { + 'text/event-stream': { + schema: { + $ref: '#/components/schemas/RunEvent', + }, + }, + }, + }, + }, + }, + }, }, }; @@ -334,12 +424,24 @@ describe('OpenAPI YAML Transformer', () => { ); expect(transformedSpec.paths).toHaveProperty('/api/search'); expect(transformedSpec.paths).toHaveProperty('/api/tools'); + expect(transformedSpec.paths).toHaveProperty('/api/tools/call'); + expect(transformedSpec.paths).toHaveProperty('/api/agents/{agent_id}/runs'); + expect(transformedSpec['x-tagGroups']).toBeUndefined(); expect(Object.keys(transformedSpec.components.schemas).sort()).toEqual([ + 'PlatformDocumentSpec', 'PlatformExisting', + 'PlatformPeopleSearchResponse', + 'PlatformPerson', + 'PlatformPersonReference', 'PlatformResult', + 'PlatformRunEvent', + 'PlatformRunRequest', 'PlatformSearchRequest', + 'PlatformSummarizeRequest', 'PlatformTool', + 'PlatformToolCallRequest', + 'PlatformToolCallResponse', 'PlatformToolsListResponse', ]); expect( @@ -350,6 +452,17 @@ describe('OpenAPI YAML Transformer', () => { expect( transformedSpec.components.schemas.PlatformResult.properties.related.$ref, ).toBe('#/components/schemas/PlatformSearchRequest'); + expect( + transformedSpec.components.schemas.PlatformResult.properties.creator.$ref, + ).toBe('#/components/schemas/PlatformPersonReference'); + expect( + transformedSpec.components.schemas.PlatformPeopleSearchResponse.properties + .people.items.$ref, + ).toBe('#/components/schemas/PlatformPerson'); + expect( + transformedSpec.components.schemas.PlatformSummarizeRequest.properties + .document_specs.items.$ref, + ).toBe('#/components/schemas/PlatformDocumentSpec'); expect(transformedSpec.components.responses).toHaveProperty( 'PlatformBadRequest', ); @@ -380,6 +493,35 @@ describe('OpenAPI YAML Transformer', () => { expect(transformedSpec.paths['/api/tools'].get).not.toHaveProperty( 'x-glean-sdk', ); + expect(transformedSpec.paths['/api/tools/call'].post).toMatchObject({ + 'x-speakeasy-group': 'platform.tools', + 'x-speakeasy-name-override': 'call', + }); + expect( + transformedSpec.paths['/api/tools/call'].post.responses[200].content[ + 'application/json' + ].schema.$ref, + ).toBe('#/components/schemas/PlatformToolCallResponse'); + expect( + transformedSpec.components.schemas.PlatformToolCallResponse.properties + .result.$ref, + ).toBe('#/components/schemas/PlatformResult'); + expect(transformedSpec.paths['/api/tools/call'].post).not.toHaveProperty( + 'x-glean-sdk', + ); + expect( + transformedSpec.paths['/api/agents/{agent_id}/runs'].post, + ).toMatchObject({ + 'x-speakeasy-group': 'platform.agents', + 'x-speakeasy-name-override': 'createRun', + }); + expect( + transformedSpec.paths['/api/agents/{agent_id}/runs'].post.responses[200] + .content['text/event-stream'].schema.$ref, + ).toBe('#/components/schemas/PlatformRunEvent'); + expect( + transformedSpec.paths['/api/agents/{agent_id}/runs'].post, + ).not.toHaveProperty('x-glean-sdk'); expect(transformedSpec.security).toEqual([{ APIToken: [] }]); expect(transformedSpec.components.securitySchemes).toHaveProperty( 'APIToken',