File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 1- #! /usr/bin/env python
1+ #! /usr/bin/env python3
22'''
3- Copyright (c) 2022, Tutteo Limited.
3+ Copyright (c) 2022-2023 , Tutteo Limited.
44'''
55
66from copy import deepcopy
@@ -26,18 +26,34 @@ def walk_tree(base, in_inheritance=False):
2626 # flatten allOf for code generator
2727 if k == 'allOf' or k == 'oneOf' :
2828 children_props = {}
29+ required = []
2930 for children_set in base [k ]:
3031 # $ref to another schema
3132 if '$ref' in children_set :
3233 schema_key = children_set ['$ref' ].split ('/' ).pop ()
3334 models_flatten .append (schema_key )
3435 children_ref = walk_tree (data ['components' ]['schemas' ][schema_key ], in_inheritance = True )
36+
3537 if children_ref != 'remove' :
38+ # Properties from children
3639 children_props .update (deepcopy (walk_tree (children_ref ['properties' ])))
40+ # Combine required arrays
41+ if 'required' in children_ref and children_ref ['required' ] is not None :
42+ required .extend (children_ref ['required' ])
43+
3744 # direct children props
3845 else :
3946 children_props .update (deepcopy (walk_tree (children_set ['properties' ])))
40- return {'type' : 'object' , 'properties' : children_props }
47+
48+ result = {
49+ 'type' : 'object' ,
50+ 'properties' : children_props ,
51+ }
52+ if len (required ) > 0 :
53+ required .sort ()
54+ result ['required' ] = required
55+ return result
56+
4157 # walk childrens
4258 result = walk_tree (v )
4359 if result == 'remove' :
You can’t perform that action at this time.
0 commit comments