|
9 | 9 | """ |
10 | 10 |
|
11 | 11 | import copy |
| 12 | + |
12 | 13 | import collections |
| 14 | +import collections.abc |
| 15 | + |
13 | 16 | from datetime import datetime |
14 | 17 | import itertools |
15 | 18 | import json |
@@ -64,9 +67,9 @@ def _dict_merge(dct, merge_dct): |
64 | 67 | dct: dict onto which the merge is executed |
65 | 68 | merge_dct: dct merged into dct |
66 | 69 | """ |
67 | | - for k, v in merge_dct.items(): |
| 70 | + for k in merge_dct.keys(): |
68 | 71 | if (k in dct and isinstance(dct[k], dict) |
69 | | - and isinstance(merge_dct[k], collections.Mapping)): |
| 72 | + and isinstance(merge_dct[k], collections.abc.Mapping)): |
70 | 73 | _dict_merge(dct[k], merge_dct[k]) |
71 | 74 | else: |
72 | 75 | dct[k] = merge_dct[k] |
@@ -105,11 +108,17 @@ def _parse_schema(schema, method): |
105 | 108 | schema_type = schema.get('type', 'object') |
106 | 109 |
|
107 | 110 | if schema_type == 'array': |
108 | | - # special case oneOf so that we can show examples for all possible |
109 | | - # combinations |
| 111 | + # special case oneOf and anyOf so that we can show examples for all |
| 112 | + # possible combinations |
110 | 113 | if 'oneOf' in schema['items']: |
111 | 114 | return [ |
112 | | - _parse_schema(x, method) for x in schema['items']['oneOf']] |
| 115 | + _parse_schema(x, method) for x in schema['items']['oneOf'] |
| 116 | + ] |
| 117 | + |
| 118 | + if 'anyOf' in schema['items']: |
| 119 | + return [ |
| 120 | + _parse_schema(x, method) for x in schema['items']['anyOf'] |
| 121 | + ] |
113 | 122 |
|
114 | 123 | return [_parse_schema(schema['items'], method)] |
115 | 124 |
|
@@ -181,7 +190,8 @@ def _example(media_type_objects, method=None, endpoint=None, status=None, |
181 | 190 | if examples is None: |
182 | 191 | examples = {} |
183 | 192 | if not example: |
184 | | - if content_type != 'application/json': |
| 193 | + if re.match(r"application/[a-zA-Z\+]*json", content_type) is \ |
| 194 | + None: |
185 | 195 | LOG.info('skipping non-JSON example generation.') |
186 | 196 | continue |
187 | 197 | example = _parse_schema(content['schema'], method=method) |
|
0 commit comments