Populate $defs with referenced schemas to produce valid JSON Schema#24
Open
asseti6 wants to merge 3 commits intoanyproto:mainfrom
Open
Populate $defs with referenced schemas to produce valid JSON Schema#24asseti6 wants to merge 3 commits intoanyproto:mainfrom
$defs with referenced schemas to produce valid JSON Schema#24asseti6 wants to merge 3 commits intoanyproto:mainfrom
Conversation
3 tasks
Author
|
@jmetrikat I saw the update mentioned in #21 (comment). Looks like that does resolve the issue, but returns an empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The OpenAPI-to-MCP converter was generating invalid JSON Schema that caused MCP clients to fail with schema validation errors:
API Error:
400 - Invalid $ref in schema: '#/$defs/FilterExpression' does not exist. Ensure all $ref targets are defined in the schema's definitions or $defs.This affected any MCP client that validates tool schemas against JSON Schema spec in some cases.
Root Cause
When converting OpenAPI schemas to JSON Schema, the converter:
$refpaths from#/components/schemas/*→#/$defs/*$defsempty with comments stating:// Omit this.convertComponentsToJsonSchema() to reduce definition sizeThis created dangling references—the
$refpointers existed but their targets didn't.The issue occurred in two code paths in
src/openapi/parser.ts:resolveRefs=false(explicit non-resolution)Both paths emitted
$ref: "#/$defs/*"but never populated$defs.Solution
Track which schemas are actually referenced during conversion, then populate
$defswith only those schemas. This maintains the original size optimization goal while producing valid JSON Schema.Worth Noting