@@ -192,7 +192,12 @@ class JSONReference(_enum.Enum):
192192
193193
194194class Discriminator (BaseModel ):
195- """Represent OpenAPI discriminator object."""
195+ """Represent OpenAPI discriminator object.
196+
197+ This is an OpenAPI-specific concept for supporting polymorphism.
198+ It identifies which schema applies based on a property value.
199+ Kept in jsonschema.py to avoid circular imports with openapi.py.
200+ """
196201
197202 propertyName : str # noqa: N815
198203 mapping : Optional [dict [str , str ]] = None # noqa: UP045
@@ -517,7 +522,7 @@ def _get_type(
517522 data_formats : dict [str , dict [str , Types ]] | None = None ,
518523) -> Types :
519524 """Get the appropriate Types enum for a given JSON Schema type and format."""
520- if data_formats is None :
525+ if data_formats is None : # pragma: no cover
521526 data_formats = json_schema_data_formats
522527 if type_ not in data_formats :
523528 return Types .any
@@ -3592,9 +3597,15 @@ def parse_id(self, obj: JsonSchemaObject, path: list[str]) -> None:
35923597
35933598 @contextmanager
35943599 def root_id_context (self , root_raw : dict [str , Any ]) -> Generator [None , None , None ]:
3595- """Context manager to temporarily set the root $id during parsing."""
3600+ """Context manager to temporarily set the root $id during parsing.
3601+
3602+ Uses schema_features.id_field to support both "id" (Draft 4) and "$id" (Draft 6+).
3603+ Falls back to checking both fields for lenient compatibility.
3604+ """
35963605 previous_root_id = self .root_id
3597- self .root_id = root_raw .get ("$id" ) or None
3606+ # Try version-specific field first, then fallback to alternative for compatibility
3607+ id_field = self .schema_features .id_field
3608+ self .root_id = root_raw .get (id_field ) or root_raw .get ("$id" ) or root_raw .get ("id" ) or None
35983609 yield
35993610 self .root_id = previous_root_id
36003611
0 commit comments