@@ -674,7 +674,31 @@ def test_dataclass_arguments_invalid(json_str: str, match: str) -> None:
674674
675675@pytest .mark .cli_doc (
676676 options = ["--type-overrides" ],
677- option_description = """Replace schema model types with custom Python types via JSON mapping.""" ,
677+ option_description = """Replace schema model types with custom Python types via JSON mapping.
678+
679+ This option is useful for importing models from external libraries (like `geojson-pydantic`)
680+ instead of generating them.
681+
682+ **Override Formats:**
683+
684+ | Format | Description |
685+ |--------|-------------|
686+ | `{"ModelName": "package.Type"}` | Model-level: Skip generating `ModelName` and import from `package` |
687+ | `{"Model.field": "package.Type"}` | Scoped: Override only specific field in specific model |
688+
689+ !!! note "Model-level overrides skip generation"
690+ When you specify a model-level override (without a dot in the key), the generator will
691+ **skip generating that model entirely** and import it from the specified package instead.
692+
693+ **Common Use Cases:**
694+
695+ | Use Case | Example Override |
696+ |----------|------------------|
697+ | GeoJSON types | `{"Feature": "geojson_pydantic.Feature"}` |
698+ | Custom datetime | `{"Timestamp": "pendulum.DateTime"}` |
699+ | MongoDB ObjectId | `{"ObjectId": "bson.ObjectId"}` |
700+ | Custom validators | `{"Email": "my_app.types.ValidatedEmail"}` |
701+ """ ,
678702 input_schema = "jsonschema/type_overrides_test.json" ,
679703 cli_args = ["--type-overrides" , '{"CustomType": "my_app.types.CustomType"}' ],
680704 golden_output = "main/type_overrides_model_level.py" ,
@@ -695,6 +719,31 @@ def test_type_overrides_model_level(output_file: Path) -> None:
695719 )
696720
697721
722+ @pytest .mark .cli_doc (
723+ options = ["--type-overrides" ],
724+ option_description = """Replace schema model types with custom Python types via JSON mapping.""" ,
725+ input_schema = "jsonschema/type_overrides_external_lib.json" ,
726+ cli_args = [
727+ "--type-overrides" ,
728+ '{"Feature": "geojson_pydantic.Feature", "FeatureCollection": "geojson_pydantic.FeatureCollection"}' ,
729+ ],
730+ golden_output = "main/type_overrides_external_lib.py" ,
731+ )
732+ @freeze_time (TIMESTAMP )
733+ def test_type_overrides_external_lib (output_file : Path ) -> None :
734+ """Test --type-overrides with external library types like geojson-pydantic."""
735+ run_main_and_assert (
736+ input_path = JSON_SCHEMA_DATA_PATH / "type_overrides_external_lib.json" ,
737+ output_path = output_file ,
738+ input_file_type = "jsonschema" ,
739+ assert_func = assert_file_content ,
740+ extra_args = [
741+ "--type-overrides" ,
742+ '{"Feature": "geojson_pydantic.Feature", "FeatureCollection": "geojson_pydantic.FeatureCollection"}' ,
743+ ],
744+ )
745+
746+
698747@freeze_time (TIMESTAMP )
699748def test_type_overrides_scoped (output_file : Path ) -> None :
700749 """Test --type-overrides with scoped override replaces specific field only."""
0 commit comments