diff --git a/src/core/capabilities/compoundParameters.test.ts b/src/core/capabilities/compoundParameters.test.ts new file mode 100644 index 0000000..ec35e54 --- /dev/null +++ b/src/core/capabilities/compoundParameters.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it } from 'vitest'; +import { compileOpenApi } from './openapi'; + +function spec(parameter: Record, method = 'get') { + return { + openapi: '3.0.3', + info: { title: 'Events', version: '1' }, + servers: [{ url: 'https://events.example.test' }], + paths: { + '/events': { + [method]: { + operationId: 'events.list', + parameters: [ + { name: 'q', in: 'query', schema: { type: 'string' } }, + parameter + ], + responses: { '200': { description: 'ok', content: { 'application/json': { schema: { type: 'array', items: { type: 'string' } } } } } } + } + } + } + }; +} + +describe('compound query and header parameters', () => { + it('leaves an optional array parameter out, and keeps the operation', () => { + const { manifests, errors } = compileOpenApi(spec({ name: 'eventTypes', in: 'query', style: 'form', explode: true, schema: { type: 'array', items: { type: 'string' } } })); + expect(errors).toEqual([]); + expect(manifests[0].inputs.map(input => input.name)).toEqual(['q']); + }); + + it('leaves an optional object header out', () => { + const { manifests } = compileOpenApi(spec({ name: 'X-Filter', in: 'header', schema: { type: 'object', properties: { a: { type: 'string' } } } })); + expect(manifests[0].inputs.map(input => input.name)).toEqual(['q']); + }); + + it('still refuses a write with an optional compound parameter', () => { + const { manifests, errors } = compileOpenApi(spec({ name: 'tags', in: 'query', schema: { type: 'array', items: { type: 'string' } } }, 'post')); + expect(manifests).toEqual([]); + expect(errors[0].message).toBe('tags: compound query parameters are outside the supported subset'); + }); + + it('still refuses an operation whose required parameter is compound', () => { + const { manifests, errors } = compileOpenApi(spec({ name: 'ids', in: 'query', required: true, schema: { type: 'array', items: { type: 'string' } } })); + expect(manifests).toEqual([]); + expect(errors[0].message).toBe('ids: compound query parameters are outside the supported subset'); + }); +}); diff --git a/src/core/capabilities/openapi.ts b/src/core/capabilities/openapi.ts index 95189c2..1833b7f 100644 --- a/src/core/capabilities/openapi.ts +++ b/src/core/capabilities/openapi.ts @@ -398,8 +398,16 @@ function collectInputs( return { error: `parameter location ${String(location)} is unsupported` }; } const converted = fromJsonSchema(isRecord(parameter.schema) || Array.isArray(parameter.schema) ? parameter.schema : { type: 'string' }, spec); + const rawSchema = deref(spec, parameter.schema); + const rawCompound = isRecord(rawSchema) && (rawSchema.type === 'array' || rawSchema.type === 'object'); + const readOnly = method === 'GET' || method === 'HEAD'; + if (!converted.ok && readOnly && location !== 'path' && parameter.required !== true && rawCompound) continue; if (!converted.ok) return { error: `${String(parameter.name)}: ${converted.error}` }; if ((location === 'query' || location === 'header') && (converted.schema.kind === 'object' || converted.schema.kind === 'array')) { + // An optional one can be left out of a read: the operation still + // works without it (Google Calendar's events.list and eventTypes). + // Not of a write, which would add write surface (AGENTS.md stop condition 3). + if (parameter.required !== true && (method === 'GET' || method === 'HEAD')) continue; return { error: `${String(parameter.name)}: compound ${location} parameters are outside the supported subset` }; } const name = String(parameter.name);