Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"helmet": "^8.3.0",
"https-proxy-agent": "^7.0.6",
"ioredis": "^5.11.1",
"js-yaml": "^4.3.2",
"js-yaml": "^5.4.1",
"mongodb": "^7.6.0",
"mssql": "^12.7.2",
"mysql2": "^3.24.4",
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/connectors/parsers/openapi.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ describe('OpenApiParser', () => {
expect(tools).toHaveLength(0);
});

it('should parse a YAML spec with anchors and merge keys', async () => {
const yamlSpec = [
'openapi: 3.0.0',
'info: { title: Test API, version: 1.0.0 }',
'x-common: &paging',
' in: query',
' schema: { type: integer }',
'paths:',
' /points:',
' get:',
' operationId: listPoints',
' parameters:',
' - <<: *paging',
' name: y',
' description: Vertical offset',
' responses:',
" '200': { description: OK }",
].join('\n');
const tools = await parser.parse(yamlSpec);
expect(tools).toHaveLength(1);
const params = tools[0].parameters as any;
// The merged keys land on the parameter, and `y` stays a name, not `true`.
expect(params.properties.y).toBeDefined();
expect(params.properties.y.type).toBe('integer');
expect(tools[0].endpointMapping.queryParams).toEqual(expect.objectContaining({ y: '$y' }));
});

// ── GET endpoints ──────────────────────────────────────────────────────

it('should parse a simple GET endpoint', async () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/backend/src/connectors/parsers/openapi.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { capToolName } from './tool-name.util';
const SwaggerParser = require('swagger-parser');
import axios from 'axios';

const yaml = require('js-yaml') as { load: (s: string) => unknown };
import { CORE_SCHEMA, load as loadYaml, mergeTag, timestampTag } from 'js-yaml';
import { assertSafeOutboundUrl } from '../../common/ssrf.util';
import { normalizeOpenApi31 } from './openapi-3.1-normalizer';

// js-yaml 5 loads with the bare YAML 1.2 core schema. Real-world specs use
// `<<: *anchor` merge keys, which it would keep as a literal "<<" property,
// so add merge (and timestamps) back: the same result js-yaml 4 gave. Not
// YAML11_SCHEMA: its 1.1 booleans turn a property named `y` or `on` into `true`.
const SPEC_YAML_SCHEMA = CORE_SCHEMA.withTags(mergeTag, timestampTag);

export interface ParsedTool {
name: string;
/**
Expand Down Expand Up @@ -169,7 +175,7 @@ export class OpenApiParser {
return JSON.parse(input);
}
try {
return yaml.load(input);
return loadYaml(input, { schema: SPEC_YAML_SCHEMA });
} catch (yamlErr) {
// Last-resort: try JSON anyway so the original error surfaces if the
// input is genuinely malformed.
Expand Down
Loading