Skip to content

Commit 5bfd689

Browse files
committed
chore: updated spec-flatten script to merge required lists
1 parent edb9a1a commit 5bfd689

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

spec/spec-flatten.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

66
from 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':

0 commit comments

Comments
 (0)