Commit 482609bc authored by Vitalii Fisenko's avatar Vitalii Fisenko
Browse files

Updated swagger generator to build nested onyOf definitions

parent 059698e8
......@@ -42,11 +42,13 @@ class SchemaTransformer:
if 'allOf' in model:
schema_model = self._merge_model(schema, model)
elif 'anyOf' in model:
schema_model = {'anyOf': {
self._split_model_name(ref['$ref']): self.expand_schema_model(schema, ref)
for ref in model['anyOf'] if isinstance(ref, dict) # <- this condition is needed to avoid
# of re-expanding expanded schema
}}
schema_model = deepcopy(model)
schema_model['anyOf'] = {}
for ref in model['anyOf']:
if isinstance(ref, dict):
schema_model['anyOf'][self._split_model_name(ref['$ref'])] = self.expand_schema_model(schema, ref)
else:
schema_model['anyOf'][ref] = self.expand_schema_model(schema, ref)
else:
schema_model = deepcopy(model)
......@@ -134,14 +136,20 @@ class BaseSchemaBuilder:
def _build_poly_model(self, prop_data):
models = []
model_props = self._map_params(prop_data)
for name, model in prop_data['items']['anyOf'].items():
is_array = True if 'type' in prop_data and prop_data['type'] == 'array' else False
allOf_items = prop_data['items']['anyOf'] if is_array else prop_data['anyOf']
for name, model in allOf_items.items():
attr_model = getattr(self.module, name.split('.')[-1], None)
if attr_model:
models.append(attr_model)
else:
models.append(self._create_schema_model_class(name.split('.')[-1], model))
poly_model = types.PolyModelType(
model_spec=models,
claim_function=get_class_from_path(prop_data['x-claim-func']),
required=model_props.get('is_required', False)
)
if 'type' in prop_data and prop_data['type'] == 'array':
if is_array:
poly_model = types.ListType(poly_model, **model_props)
return poly_model
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment