@@ -141,25 +141,28 @@ def generate_json_schema(models: List[Type[BaseModel]]) -> str:
141
141
'[k: string]: any' from being added to every interface. This change is reverted
142
142
once the schema has been generated.
143
143
"""
144
- model_extras = [m .Config . extra for m in models ]
144
+ model_extras = [getattr ( m .Config , ' extra' , None ) for m in models ]
145
145
146
- for m in models :
147
- if m .Config .extra != Extra .allow :
148
- m .Config .extra = Extra .forbid
146
+ try :
147
+ for m in models :
148
+ if getattr (m .Config , 'extra' , None ) != Extra .allow :
149
+ m .Config .extra = Extra .forbid
149
150
150
- master_model = create_model ("_Master_" , ** {m .__name__ : (m , ...) for m in models })
151
- master_model .Config .extra = Extra .forbid
152
- master_model .Config .schema_extra = staticmethod (clean_schema )
151
+ master_model = create_model ("_Master_" , ** {m .__name__ : (m , ...) for m in models })
152
+ master_model .Config .extra = Extra .forbid
153
+ master_model .Config .schema_extra = staticmethod (clean_schema )
153
154
154
- schema = json .loads (master_model .schema_json ())
155
+ schema = json .loads (master_model .schema_json ())
155
156
156
- for d in schema .get ("definitions" , {}).values ():
157
- clean_schema (d )
157
+ for d in schema .get ("definitions" , {}).values ():
158
+ clean_schema (d )
158
159
159
- for m , x in zip (models , model_extras ):
160
- m .Config .extra = x
160
+ return json .dumps (schema , indent = 2 )
161
161
162
- return json .dumps (schema , indent = 2 )
162
+ finally :
163
+ for m , x in zip (models , model_extras ):
164
+ if x is not None :
165
+ m .Config .extra = x
163
166
164
167
165
168
def generate_typescript_defs (
@@ -196,6 +199,7 @@ def generate_typescript_defs(
196
199
banner_comment = "\n " .join (
197
200
[
198
201
"/* tslint:disable */" ,
202
+ "/* eslint-disable */" ,
199
203
"/**" ,
200
204
"/* This file was automatically generated from pydantic models by running pydantic2ts." ,
201
205
"/* Do not modify it by hand - just update the pydantic models and then re-run the script" ,
0 commit comments