mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-16 02:29:11 +02:00
* Normalize OpenAPI $ref everywhere (incl. propertyNames); migrate components→$defs; add regression test * Fix: normalize $ref in propertyNames and additionalProperties; add regression test * Deterministic migration: components.schemas override $defs on collision; preserve direct $defs refs via alias; add collision test * Fix: rewrite $ref in propertyNames and patternProperties in _replace_ref_with_defs * Fix syntax error, formatting, and stray files * Skip boolean subschemas in patternProperties --------- Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from fastmcp.utilities.openapi.schemas import _replace_ref_with_defs
|
|
|
|
|
|
def test_replace_ref_with_defs_rewrites_propertyNames_ref():
|
|
"""
|
|
Regression test for issue #3303.
|
|
|
|
When using dict[StrEnum, Model], Pydantic generates:
|
|
|
|
{
|
|
"type": "object",
|
|
"propertyNames": {"$ref": "#/components/schemas/Category"},
|
|
"additionalProperties": {"$ref": "#/components/schemas/ItemInfo"}
|
|
}
|
|
|
|
_replace_ref_with_defs should rewrite BOTH refs to #/$defs/.
|
|
"""
|
|
|
|
schema = {
|
|
"type": "object",
|
|
"propertyNames": {"$ref": "#/components/schemas/Category"},
|
|
"additionalProperties": {"$ref": "#/components/schemas/ItemInfo"},
|
|
}
|
|
|
|
result = _replace_ref_with_defs(schema)
|
|
|
|
# additionalProperties ref is rewritten
|
|
assert result["additionalProperties"]["$ref"] == "#/$defs/ItemInfo"
|
|
|
|
# propertyNames ref must also be rewritten (this was the bug)
|
|
assert result["propertyNames"]["$ref"] == "#/$defs/Category"
|
|
|
|
# Ensure no dangling OpenAPI refs remain
|
|
assert "#/components/schemas/" not in str(result)
|