Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubled references for schemas combined with oneOf, anyOf, allOf #731

Open
grasslasts opened this issue Nov 18, 2021 · 0 comments
Open

Doubled references for schemas combined with oneOf, anyOf, allOf #731

grasslasts opened this issue Nov 18, 2021 · 0 comments

Comments

@grasslasts
Copy link

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'}}}}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant