11import datetime
22from _decimal import Decimal
3+ from copy import deepcopy
34from enum import Enum
45
56from dataclasses import dataclass , field
@@ -178,7 +179,13 @@ def test_embeddable_json_schema():
178179 assert expected == Foo .json_schema (embeddable = True )
179180 expected = {'Point' : POINT_SCHEMA , 'Foo' : SWAGGER_V2_FOO_SCHEMA }
180181 assert expected == SubSchemas .all_json_schemas (schema_type = SchemaType .SWAGGER_V2 )
181- expected = {'Point' : POINT_SCHEMA , 'Foo' : SWAGGER_V3_FOO_SCHEMA }
182+ expected = {
183+ 'Point' : deepcopy (POINT_SCHEMA ),
184+ 'Foo' : deepcopy (SWAGGER_V3_FOO_SCHEMA ),
185+ }
186+ expected ['Point' ]['x-module-name' ] = 'tests.conftest'
187+ expected ['Foo' ]['x-module-name' ] = 'tests.conftest'
188+ expected ['Foo' ]['properties' ]['d' ]['x-module-name' ] = 'tests.conftest'
182189 assert expected == SubSchemas .all_json_schemas (schema_type = SchemaType .SWAGGER_V3 )
183190 expected = {
184191 'Point' : POINT_SCHEMA ,
@@ -441,9 +448,11 @@ class Test(JsonSchemaMixin):
441448 expected_full_schema = compose_schema (expected_schema )
442449 assert Test .json_schema () == expected_full_schema
443450 expected_schema ['properties' ]['name' ]['x-field-group' ] = 1
451+ expected_schema ['x-module-name' ] = 'tests.test_core'
444452 assert Test .json_schema (schema_type = SchemaType .OPENAPI_3 , embeddable = True ) == {'Test' : expected_schema }
445453 expected_schema ['properties' ]['name' ]['example' ] = 'foo'
446454 del expected_schema ['properties' ]['name' ]['examples' ]
455+ del expected_schema ['x-module-name' ]
447456 assert Test .json_schema (schema_type = SchemaType .SWAGGER_V2 , embeddable = True ) == {'Test' : expected_schema }
448457
449458
@@ -632,7 +641,8 @@ class Employee(JsonSchemaMixin):
632641 "name" : {"type" : "string" },
633642 "manager" : {"type" : "string" , "nullable" : True }
634643 },
635- "required" : ["name" ]
644+ "required" : ["name" ],
645+ "x-module-name" : "tests.test_core"
636646 }
637647 expected_json_schema = compose_schema ({
638648 "type" : "object" ,
@@ -696,7 +706,8 @@ class Dog(Pet):
696706 {
697707 "type" : "object" ,
698708 "properties" : {"breed" : {"type" : "string" }},
699- "required" : ["breed" ]
709+ "required" : ["breed" ],
710+ "x-module-name" : "tests.test_core" ,
700711 },
701712 ]
702713 },
@@ -708,7 +719,8 @@ class Dog(Pet):
708719 "name" : {"type" : "string" }
709720 },
710721 "required" : ["name" , "PetType" ],
711- "discriminator" : {"propertyName" : "PetType" }
722+ "discriminator" : {"propertyName" : "PetType" },
723+ "x-module-name" : "tests.test_core" ,
712724 }
713725 }
714726
@@ -951,3 +963,18 @@ class Pet(JsonSchemaMixin):
951963
952964 p = Pet .from_dict ({'name' : ' Fido ' , 'type' : 'dog' })
953965 assert p .name == 'Fido'
966+
967+
968+ def test_module_name_extension ():
969+ class PetType (Enum ):
970+ DOG = "dog"
971+ CAT = "cat"
972+
973+ @dataclass
974+ class Pet (JsonSchemaMixin ):
975+ name : str
976+ type : PetType
977+
978+ schema = Pet .json_schema (embeddable = True , schema_type = SchemaType .OPENAPI_3 )
979+ assert schema ['Pet' ]['x-module-name' ] == 'tests.test_core'
980+ assert schema ['Pet' ]['properties' ]['type' ]['x-module-name' ] == 'tests.test_core'
0 commit comments