@@ -495,3 +495,133 @@ def test_cli_schema_version_mode() -> None:
495495 schema_version_mode = VersionMode .Lenient ,
496496 )
497497 assert result is not None
498+
499+
500+ def test_schema_paths_lenient_mode_draft7 () -> None :
501+ """Test schema_paths returns both paths in Lenient mode for Draft 7."""
502+ from datamodel_code_generator .parser .jsonschema import JsonSchemaParser
503+
504+ parser = JsonSchemaParser ("" , jsonschema_version = JsonSchemaVersion .Draft7 )
505+ paths = parser .schema_paths
506+ assert paths == snapshot ([
507+ ("#/definitions" , ["definitions" ]),
508+ ("#/$defs" , ["$defs" ]),
509+ ])
510+
511+
512+ def test_schema_paths_lenient_mode_2020_12 () -> None :
513+ """Test schema_paths returns $defs first in Lenient mode for 2020-12."""
514+ from datamodel_code_generator .parser .jsonschema import JsonSchemaParser
515+
516+ parser = JsonSchemaParser ("" , jsonschema_version = JsonSchemaVersion .Draft202012 )
517+ paths = parser .schema_paths
518+ assert paths == snapshot ([
519+ ("#/$defs" , ["$defs" ]),
520+ ("#/definitions" , ["definitions" ]),
521+ ])
522+
523+
524+ def test_schema_paths_strict_mode_draft7 () -> None :
525+ """Test schema_paths returns only definitions in Strict mode for Draft 7."""
526+ from datamodel_code_generator .parser .jsonschema import JsonSchemaParser
527+
528+ parser = JsonSchemaParser (
529+ "" ,
530+ jsonschema_version = JsonSchemaVersion .Draft7 ,
531+ schema_version_mode = VersionMode .Strict ,
532+ )
533+ paths = parser .schema_paths
534+ assert paths == snapshot ([("#/definitions" , ["definitions" ])])
535+
536+
537+ def test_schema_paths_strict_mode_2020_12 () -> None :
538+ """Test schema_paths returns only $defs in Strict mode for 2020-12."""
539+ from datamodel_code_generator .parser .jsonschema import JsonSchemaParser
540+
541+ parser = JsonSchemaParser (
542+ "" ,
543+ jsonschema_version = JsonSchemaVersion .Draft202012 ,
544+ schema_version_mode = VersionMode .Strict ,
545+ )
546+ paths = parser .schema_paths
547+ assert paths == snapshot ([("#/$defs" , ["$defs" ])])
548+
549+
550+ def test_openapi_schema_paths_unchanged () -> None :
551+ """Test that OpenAPI schema_paths uses SCHEMA_PATHS regardless of version mode."""
552+ from datamodel_code_generator .parser .openapi import OpenAPIParser
553+
554+ parser = OpenAPIParser (
555+ "" ,
556+ openapi_version = OpenAPIVersion .V31 ,
557+ schema_version_mode = VersionMode .Strict ,
558+ )
559+ paths = parser .schema_paths
560+ assert paths == snapshot ([("#/components/schemas" , ["components" , "schemas" ])])
561+
562+
563+ def test_nullable_keyword_openapi_31_strict_warning () -> None :
564+ """Test that nullable keyword emits warning in OpenAPI 3.1 Strict mode."""
565+ import warnings
566+
567+ from datamodel_code_generator .parser .jsonschema import JsonSchemaObject
568+ from datamodel_code_generator .parser .openapi import OpenAPIParser
569+
570+ parser = OpenAPIParser (
571+ "" ,
572+ openapi_version = OpenAPIVersion .V31 ,
573+ schema_version_mode = VersionMode .Strict ,
574+ strict_nullable = True ,
575+ )
576+ obj = JsonSchemaObject (type = "string" , nullable = True )
577+
578+ with warnings .catch_warnings (record = True ) as w :
579+ warnings .simplefilter ("always" )
580+ parser .get_data_type (obj )
581+ assert len (w ) == 1
582+ assert issubclass (w [0 ].category , DeprecationWarning )
583+ assert "nullable keyword is deprecated" in str (w [0 ].message )
584+
585+
586+ def test_nullable_keyword_openapi_30_no_warning () -> None :
587+ """Test that nullable keyword does NOT emit warning in OpenAPI 3.0."""
588+ import warnings
589+
590+ from datamodel_code_generator .parser .jsonschema import JsonSchemaObject
591+ from datamodel_code_generator .parser .openapi import OpenAPIParser
592+
593+ parser = OpenAPIParser (
594+ "" ,
595+ openapi_version = OpenAPIVersion .V30 ,
596+ schema_version_mode = VersionMode .Strict ,
597+ strict_nullable = True ,
598+ )
599+ obj = JsonSchemaObject (type = "string" , nullable = True )
600+
601+ with warnings .catch_warnings (record = True ) as w :
602+ warnings .simplefilter ("always" )
603+ parser .get_data_type (obj )
604+ deprecation_warnings = [x for x in w if issubclass (x .category , DeprecationWarning )]
605+ assert len (deprecation_warnings ) == 0
606+
607+
608+ def test_nullable_keyword_openapi_31_lenient_no_warning () -> None :
609+ """Test that nullable keyword does NOT emit warning in OpenAPI 3.1 Lenient mode."""
610+ import warnings
611+
612+ from datamodel_code_generator .parser .jsonschema import JsonSchemaObject
613+ from datamodel_code_generator .parser .openapi import OpenAPIParser
614+
615+ parser = OpenAPIParser (
616+ "" ,
617+ openapi_version = OpenAPIVersion .V31 ,
618+ schema_version_mode = VersionMode .Lenient ,
619+ strict_nullable = True ,
620+ )
621+ obj = JsonSchemaObject (type = "string" , nullable = True )
622+
623+ with warnings .catch_warnings (record = True ) as w :
624+ warnings .simplefilter ("always" )
625+ parser .get_data_type (obj )
626+ deprecation_warnings = [x for x in w if issubclass (x .category , DeprecationWarning )]
627+ assert len (deprecation_warnings ) == 0
0 commit comments