@@ -811,9 +811,12 @@ def property_from_data(
811811
812812
813813def _create_schemas (
814- * , components : Dict [str , Union [oai .Reference , oai .Schema ]], schemas : Schemas , config : Config
814+ * ,
815+ input_schemas : Dict [str , Union [oai .Reference , oai .Schema ]],
816+ schemas : Schemas ,
817+ config : Config ,
815818) -> Schemas :
816- to_process : Iterable [Tuple [str , Union [oai .Reference , oai .Schema ]]] = components .items ()
819+ to_process : Iterable [Tuple [str , Union [oai .Reference , oai .Schema ]]] = input_schemas .items ()
817820 still_making_progress = True
818821 errors : List [PropertyError ] = []
819822
@@ -844,6 +847,32 @@ def _create_schemas(
844847 return schemas
845848
846849
850+ def _process_responses (
851+ * ,
852+ input_responses : Dict [str , oai .Response ],
853+ schemas : Schemas ,
854+ config : Config ,
855+ ) -> Schemas :
856+ for name , data in input_responses .items ():
857+ if not isinstance (data , oai .Response ):
858+ schemas .errors .append (PropertyError (data = data , detail = "Only reference schemas are supported." ))
859+ continue
860+
861+ schema_ref_path = parse_reference_path (f"#/components/schemas/{ name } " )
862+ if isinstance (schema_ref_path , ParseError ):
863+ schemas .errors .append (PropertyError (detail = schema_ref_path .detail , data = data ))
864+ continue
865+ response_ref_path = parse_reference_path (f"#/components/responses/{ name } " )
866+ if isinstance (response_ref_path , ParseError ):
867+ schemas .errors .append (PropertyError (detail = response_ref_path .detail , data = data ))
868+ continue
869+
870+ prop = schemas .classes_by_reference .get (schema_ref_path )
871+ if prop :
872+ schemas = evolve (schemas , classes_by_reference = {response_ref_path : prop , ** schemas .classes_by_reference })
873+ return schemas
874+
875+
847876def _propogate_removal (* , root : Union [ReferencePath , utils .ClassName ], schemas : Schemas , error : PropertyError ) -> None :
848877 if isinstance (root , utils .ClassName ):
849878 schemas .classes_by_name .pop (root , None )
@@ -904,10 +933,16 @@ def _process_models(*, schemas: Schemas, config: Config) -> Schemas:
904933
905934
906935def build_schemas (
907- * , components : Dict [str , Union [oai .Reference , oai .Schema ]], schemas : Schemas , config : Config
936+ * ,
937+ input_schemas : Dict [str , Union [oai .Reference , oai .Schema ]],
938+ input_responses : Optional [Dict [str , Union [oai .Reference , oai .Schema ]]],
939+ schemas : Schemas ,
940+ config : Config ,
908941) -> Schemas :
909942 """Get a list of Schemas from an OpenAPI dict"""
910- schemas = _create_schemas (components = components , schemas = schemas , config = config )
943+ schemas = _create_schemas (input_schemas = input_schemas , schemas = schemas , config = config )
944+ if input_responses :
945+ schemas = _process_responses (input_responses = input_responses , schemas = schemas , config = config )
911946 schemas = _process_models (schemas = schemas , config = config )
912947 return schemas
913948
0 commit comments