@@ -163,9 +163,9 @@ def property_from_data(
163163
164164 prop , schemas = _property_from_data (name , required , data , schemas , parent_name , config , process_properties , roots )
165165 if not isinstance (prop , PropertyError ) and isinstance (data , oai .Schema ):
166- prop . read_only = data .readOnly or False
167- # We are mutating the object instead of using evolve() because we may have already
168- # stored a reference to the original object in schema.classes_by_reference, etc.
166+ updated_prop = evolve ( prop , read_only = data .readOnly or False )
167+ schemas = _replace_schema ( schemas , prop , updated_prop )
168+ prop = updated_prop
169169 return prop , schemas
170170
171171
@@ -423,6 +423,29 @@ def _process_models(*, schemas: Schemas, config: Config) -> Schemas:
423423 return evolve (schemas , errors = [* schemas .errors , * errors ], models_to_process = to_process )
424424
425425
426+ def _replace_schema (schemas : Schemas , original_prop : Property , updated_prop : Property ) -> Schemas :
427+ if isinstance (original_prop , (ModelProperty , EnumProperty )):
428+ # TODO: replace that check with a protocol method like "has_class_info"
429+ class_info = original_prop .class_info
430+ if class_info .name in schemas .classes_by_name :
431+ schemas = evolve (
432+ schemas ,
433+ classes_by_name = {** schemas .classes_by_name , class_info .name : updated_prop },
434+ )
435+ # We don't have to worry about classes_by_reference, because that gets populated at
436+ # a higher level after property_from_data has returned.
437+ if isinstance (original_prop , ModelProperty ) and isinstance (updated_prop , ModelProperty ):
438+ # TODO: if models_to_process is generalized to hold other types, replace that check
439+ # with a protocol method like "needs_post_processing"
440+ updated_list = schemas .models_to_process .copy ()
441+ # Currently models_to_process is defined as a list of ModelProperty only, but that will
442+ # change, so for now let's do this step for all
443+ updated_list .remove (original_prop )
444+ updated_list .append (updated_prop )
445+ schemas = evolve (schemas , models_to_process = updated_list )
446+ return schemas
447+
448+
426449def build_schemas (
427450 * ,
428451 components : dict [str , oai .Reference | oai .Schema ],
0 commit comments