@@ -992,6 +992,73 @@ def test_main_root_id_jsonschema_with_absolute_local_file(output_file: Path) ->
992992 )
993993
994994
995+ def test_main_url_with_relative_root_id_resolves_relative_refs (mocker : MockerFixture , tmp_path : Path ) -> None :
996+ """Test --url input keeps resolving relative refs remotely when root $id is path-only."""
997+ main_response = mocker .Mock ()
998+ main_response .status_code = 200
999+ main_response .headers = {}
1000+ main_response .text = json .dumps ({
1001+ "$id" : "/schemas/v1/main.schema.json" ,
1002+ "$schema" : "http://json-schema.org/draft-07/schema#" ,
1003+ "title" : "Main" ,
1004+ "type" : "object" ,
1005+ "properties" : {
1006+ "sub" : {
1007+ "$ref" : "sub.schema.json" ,
1008+ }
1009+ },
1010+ "required" : ["sub" ],
1011+ })
1012+ sub_response = mocker .Mock ()
1013+ sub_response .status_code = 200
1014+ sub_response .headers = {}
1015+ sub_response .text = json .dumps ({
1016+ "$id" : "/schemas/v1/sub.schema.json" ,
1017+ "$schema" : "http://json-schema.org/draft-07/schema#" ,
1018+ "title" : "Sub" ,
1019+ "type" : "string" ,
1020+ "pattern" : "^[0-9a-f]{8}$" ,
1021+ })
1022+ httpx_get_mock = mocker .patch ("httpx.get" , side_effect = [main_response , sub_response ])
1023+ output_dir = tmp_path / "output"
1024+
1025+ result = run_main_with_args ([
1026+ "--url" ,
1027+ "http://localhost:8888/schemas/v1/main.schema.json" ,
1028+ "--output" ,
1029+ str (output_dir ),
1030+ "--input-file-type" ,
1031+ "jsonschema" ,
1032+ "--output-model-type" ,
1033+ "pydantic_v2.BaseModel" ,
1034+ ])
1035+
1036+ assert result == Exit .OK
1037+ main_content = (output_dir / "__init__.py" ).read_text (encoding = "utf-8" )
1038+ sub_content = (output_dir / "sub.py" ).read_text (encoding = "utf-8" )
1039+ assert "class Main(BaseModel):" in main_content
1040+ assert "sub: sub_1.Schema" in main_content
1041+ assert "class Schema(RootModel[constr(pattern=r'^[0-9a-f]{8}$')]):" in sub_content
1042+ httpx_get_mock .assert_has_calls ([
1043+ call (
1044+ "http://localhost:8888/schemas/v1/main.schema.json" ,
1045+ headers = None ,
1046+ verify = True ,
1047+ follow_redirects = True ,
1048+ params = None ,
1049+ timeout = 30.0 ,
1050+ ),
1051+ call (
1052+ "http://localhost:8888/schemas/v1/sub.schema.json" ,
1053+ headers = None ,
1054+ verify = True ,
1055+ follow_redirects = True ,
1056+ params = None ,
1057+ timeout = 30.0 ,
1058+ ),
1059+ ])
1060+
1061+
9951062def test_main_remote_ref_emits_deprecation_warning (mocker : MockerFixture , tmp_path : Path ) -> None :
9961063 """Test that implicit remote $ref fetching emits a FutureWarning when flag is not set."""
9971064 person_response = mocker .Mock ()
0 commit comments