Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4058bc6359
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not values: | ||
| # Empty enum means no valid value; fall back to Any to avoid | ||
| # Pydantic's AssertionError on ``Literal[()]``. | ||
| return Any |
There was a problem hiding this comment.
Keep empty enum unsatisfiable instead of widening to Any
Returning Any for {"enum": []} silently inverts JSON Schema semantics: an empty enum means no value is valid, but this branch now accepts every input and can let invalid payloads pass validation in production. This is especially risky because callers will not see an error anymore and may assume schema constraints are being enforced; using the existing unsatisfiable type (like the false schema path) would avoid the crash without dropping the constraint.
Useful? React with 👍 / 👎.
9b372eb to
d644946
Compare
Test Failure AnalysisSummary: The static analysis ( Root Cause: Suggested Solution: Run the following locally, then commit and push the resulting changes: uv run prek run --all-filesThis will auto-fix the import ordering and formatting issues. The change is minor — Detailed AnalysisFailed checks:
Diff applied by ruff (from CI log): --- a/tests/utilities/json_schema_type/test_real_world_schemas.py
+++ b/tests/utilities/json_schema_type/test_real_world_schemas.py
@@ -19,9 +19,9 @@
from pathlib import Path
import pytest
import yaml
+from pydantic import TypeAdapter
from fastmcp.utilities.json_schema_type import json_schema_to_type
-from pydantic import TypeAdapterNot blocking (yet): The Related Files
|
60a66b0 to
d644946
Compare
jlowin
left a comment
There was a problem hiding this comment.
Fixes look correct across all five crash paths. Lint fixup pushed — good to go.
- Handle boolean schemas (True/False) at the public entry point - Append trailing underscore to Python keyword property names (PEP 8) - Return Any for empty enum values instead of crashing Pydantic - Deduplicate field names after sanitization to prevent collisions (e.g. "foo-bar" and "foo_bar" both sanitizing to "foo_bar") 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
59067fc to
43d09d2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 43d09d28ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if schema is True: | ||
| return Any | ||
| if schema is False: | ||
| return _UnsatisfiableType # type: ignore[return-value] # ty:ignore[invalid-return-type] |
There was a problem hiding this comment.
Enforce name validation for top-level boolean schemas
The new boolean fast-path returns immediately for schema is True/False, which bypasses the existing non-object name validation. As a result, json_schema_to_type(True, name="X") and json_schema_to_type(False, name="X") now succeed while other non-object schemas still raise ValueError, violating the documented contract that name is only for object schemas. In callers that always pass a name, this can silently turn a schema mismatch into Any (or an unsatisfiable type) instead of surfacing the error.
Useful? React with 👍 / 👎.
Summary
json_schema_to_type()crashes on several valid JSON Schema inputs that appear in real-world OpenAPI specs. This PR fixes five crash paths without changing any public API.Python keyword property names (
class,return,from,in, etc.) crashedmake_dataclass. Now appends a trailing underscore per PEP 8 convention (class_), with the original name preserved in field alias metadata for JSON round-tripping. This is the dominant crash pattern — 388 out of 388 TypeErrors (100%) across 232K real-world schemas from APIs.guru are keyword crashes.fromalone accounts for 232 of them (common in AWS API pagination/date-range schemas).Boolean schemas at the public entry point — #3785 fixed
_schema_to_type(internal) for boolean property schemas, but callingjson_schema_to_type(True)directly still crashes since the public function's type hint isMapping[str, Any]. This PR widens the signature toMapping[str, Any] | booland adds the same handling at the entry point. Related: #3783.Empty enum values (
{"enum": []}) producedLiteral[()]which crashes Pydantic's schema generator. Now returns the unsatisfiable type (matching JSON Schema 2020-12 semantics: empty enum = no value is valid).Name collisions after sanitization (
foo-barandfoo_barboth becomefoo_bar) crashedmake_dataclasswith a duplicate field error. Now appends a numeric suffix (foo_bar_2).All changes are crash→works. No existing working behavior is modified.
Impact on real-world schemas
Tested against 232K schemas from 4,120 OpenAPI specs (APIs.guru directory):
Closes #3817
🤖 Generated with Claude Code