Doubled references for schemas combined with oneOf, anyOf, allOf
grasslasts opened this issue · comments
When combining schema that was previously added to components with oneOf, anyOf, allOf it get referenced with doubled reference.
Example:
from apispec import APISpec
from apispec.utils import OpenAPIVersion
spec = APISpec('test', 'v1', OpenAPIVersion('2.0'))
spec.components.schema(
'Request',
{
'properties': {
'bool_field': {
'type': 'boolean'
},
'id': {
'type': 'integer'
},
'name': {
'type': 'string',
'description': 'name'
},
'list_field': {
'type': 'array',
'items': {
'type': 'integer'
}
}
}
}
)
operations = {
'responses': {},
'parameters': [
{
'in': 'body',
'required': False,
'name': 'body',
'schema': {
'allOf': [
'#/definitions/Request'
],
'example': {
'id': 1,
'name': 'test',
'bool_field': True,
'list_field': [
1, 2, 3
]
}
}
}
]
}
spec.path(path='test', operations={'post': operations})
print(spec.to_dict())
Output:
{'paths': OrderedDict([('test', {'post': {'responses': OrderedDict(), 'parameters': [{'in': 'body', 'required': False, 'name': 'body', 'schema': {'allOf': [{'$ref':
'#/definitions/#/definitions/Request'
}], 'example': {'id': 1, 'name': 'test', 'bool_field': True, 'list_field': [1, 2, 3]}}}]}})]), 'info': {'title': 'test', 'version': 'v1'}, 'swagger': '2.0', 'definitions': {'Request': {'properties': {'bool_field': {'type': 'boolean'}, 'id': {'type': 'integer'}, 'name': {'type': 'string', 'description': 'name'}, 'list_field': {'type': 'array', 'items': {'type': 'integer'}}}}}}