77import copy
88from functools import partial
99
10- from .schema_util import _get_decorators , _get_function_full_qual_name , __functions_schema__
10+ from .schema_util import _get_decorators , _get_function_full_qual_name , __functions_schema__ , __versions__
1111from .parameter_types .abstract_parameter_type import AbstractParameterType
1212from ._constants import INPUT_SCHEMA_ATTR , OUTPUT_SCHEMA_ATTR
1313
@@ -39,8 +39,9 @@ def input_schema(param_name, param_type, convert_to_provided_type=True):
3939 'of the AbstractParameterType.' )
4040
4141 swagger_schema = {param_name : param_type .input_to_swagger ()}
42+ supported_versions = param_type .supported_versions ()
4243
43- @_schema_decorator (attr_name = INPUT_SCHEMA_ATTR , schema = swagger_schema )
44+ @_schema_decorator (attr_name = INPUT_SCHEMA_ATTR , schema = swagger_schema , supported_versions = supported_versions )
4445 def decorator_input (user_run , instance , args , kwargs ):
4546 if convert_to_provided_type :
4647 args = list (args )
@@ -82,16 +83,17 @@ def output_schema(output_type):
8283 'of the AbstractParameterType.' )
8384
8485 swagger_schema = output_type .input_to_swagger ()
86+ supported_versions = output_type .supported_versions ()
8587
86- @_schema_decorator (attr_name = OUTPUT_SCHEMA_ATTR , schema = swagger_schema )
88+ @_schema_decorator (attr_name = OUTPUT_SCHEMA_ATTR , schema = swagger_schema , supported_versions = supported_versions )
8789 def decorator_input (user_run , instance , args , kwargs ):
8890 return user_run (* args , ** kwargs )
8991
9092 return decorator_input
9193
9294
9395# Heavily based on the wrapt.decorator implementation
94- def _schema_decorator (wrapper = None , enabled = None , attr_name = None , schema = None ):
96+ def _schema_decorator (wrapper = None , enabled = None , attr_name = None , schema = None , supported_versions = None ):
9597 """
9698 Decorator to generate decorators, preserving the metadata passed to the
9799 decorator arguments, that is needed to be able to extact that information
@@ -107,6 +109,8 @@ def _schema_decorator(wrapper=None, enabled=None, attr_name=None, schema=None):
107109 :type attr_name: str | None
108110 :param schema:
109111 :type schema: dict | None
112+ :param supported_versions:
113+ :type supported_versions: List | None
110114 :return:
111115 :rtype: function | FunctionWrapper
112116 """
@@ -134,6 +138,7 @@ def _capture(target_wrapped):
134138 return _capture
135139
136140 _add_schema_to_global_schema_dictionary (attr_name , schema , args [0 ])
141+ _add_versions_to_global_versions_dictionary (attr_name , supported_versions , args [0 ])
137142 target_wrapped = args [0 ]
138143
139144 _enabled = enabled
@@ -165,7 +170,8 @@ def _capture(target_wrapped):
165170 _schema_decorator ,
166171 enabled = enabled ,
167172 attr_name = attr_name ,
168- schema = schema
173+ schema = schema ,
174+ supported_versions = supported_versions
169175 )
170176
171177
@@ -201,6 +207,35 @@ def _add_schema_to_global_schema_dictionary(attr_name, schema, user_func):
201207 pass
202208
203209
210+ def _add_versions_to_global_versions_dictionary (attr_name , versions , user_func ):
211+ """
212+ function to add supported swagger versions for 'attr_name', to the function versions dict
213+
214+ :param attr_name:
215+ :type attr_name: str
216+ :param versions:
217+ :type versions: List
218+ :param user_func:
219+ :type user_func: function | FunctionWrapper
220+ :return:
221+ :rtype:
222+ """
223+
224+ if attr_name is None or versions is None :
225+ pass
226+
227+ decorators = _get_decorators (user_func )
228+ base_func_name = _get_function_full_qual_name (decorators [- 1 ])
229+
230+ if base_func_name not in __versions__ .keys ():
231+ __versions__ [base_func_name ] = {}
232+
233+ if attr_name == INPUT_SCHEMA_ATTR or attr_name == OUTPUT_SCHEMA_ATTR :
234+ _add_attr_versions_to_global_schema_dictionary (base_func_name , versions , attr_name )
235+ else :
236+ pass
237+
238+
204239def _add_input_schema_to_global_schema_dictionary (base_func_name , arg_names , schema ):
205240 """
206241 function to add a generated input schema, to the function schema dict
@@ -233,6 +268,29 @@ def _add_input_schema_to_global_schema_dictionary(base_func_name, arg_names, sch
233268 __functions_schema__ [base_func_name ][INPUT_SCHEMA_ATTR ]["properties" ][k ] = item_swagger
234269
235270
271+ def _add_attr_versions_to_global_schema_dictionary (base_func_name , versions , attr ):
272+ """
273+ function to add supported swagger versions to the version dict
274+
275+ :param base_func_name: function full qualified name
276+ :type base_func_name: str
277+ :param versions:
278+ :type versions: list
279+ :param attr:
280+ :type attr: str
281+ :return:
282+ :rtype:
283+ """
284+
285+ if attr not in __versions__ [base_func_name ].keys ():
286+ __versions__ [base_func_name ][attr ] = {
287+ "type" : "object" ,
288+ "versions" : {}
289+ }
290+
291+ __versions__ [base_func_name ][attr ]["versions" ] = versions
292+
293+
236294def _add_output_schema_to_global_schema_dictionary (base_func_name , schema ):
237295 """
238296 function to add a generated output schema, to the function schema dict
0 commit comments