@@ -18,26 +18,32 @@ def normalize_default_value(data) -> str:
1818 return data
1919
2020
21+ def merge_descriptions (yaml , other ):
22+ if yaml .get ('description' ) and other .get ('description' ):
23+ description = yaml ['description' ].strip ()
24+ if not description .endswith ('.' ):
25+ description += '.'
26+ description += ' <i>Each of the elements:</i> ' + other ['description' ]
27+
28+ value_merged = yaml .copy ()
29+ value_merged ['description' ] = description
30+ return value_merged
31+ elif yaml .get ('description' ):
32+ return yaml
33+ else :
34+ return other
35+
36+
2137def visit_object (yaml , prefix : str = '' ):
2238 properties = yaml .get ('properties' , {})
2339
2440 for key , value in properties .items ():
2541 if value .get ('type' ) == 'array' :
2642 if value ['items' ].get ('type' ) == 'object' :
2743 yield from visit_object (value ['items' ], prefix + key + '.[].' )
28- elif value .get ('description' ) and value ['items' ].get ('description' ):
29- description = value ['description' ].strip ()
30- if not description .endswith ('.' ):
31- description += '.'
32- description += ' Each of the array elements: ' + value ['items' ]['description' ]
33-
34- value_cloned = value .copy ()
35- value_cloned ['description' ] = description
36- yield (prefix + key + '.[]' , value_cloned )
37- elif value .get ('description' ):
38- yield (prefix + key + '.[]' , value )
3944 else :
40- yield (prefix + key + '.[]' , value ['items' ])
45+ value_merged = merge_descriptions (value , value ['items' ])
46+ yield (prefix + key + '.[]' , value_merged )
4147 elif value .get ('type' ) == 'object' :
4248 yield from visit_object (value , prefix + key + '.' )
4349 else :
@@ -46,8 +52,16 @@ def visit_object(yaml, prefix: str = ''):
4652 additionals = yaml .get ('additionalProperties' )
4753 if additionals is True :
4854 yield (prefix + '*' , yaml )
49- elif additionals :
55+ elif not additionals :
56+ return
57+ elif additionals .get ('type' ) == 'object' :
5058 yield from visit_object (yaml ['additionalProperties' ], prefix + '*.' )
59+ elif additionals .get ('type' ) == 'array' :
60+ value_merged = merge_descriptions (yaml , additionals ['items' ])
61+ yield (prefix + '*.[]' , value_merged )
62+ else :
63+ value_merged = merge_descriptions (yaml , additionals )
64+ yield (prefix + '*' , value_merged )
5165
5266
5367def format_schema (yaml ) -> str :
0 commit comments