marshmallow-code / marshmallow-code/apispec

Doubled references for schemas combined with oneOf, anyOf, allOf

Open
#731 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.2k
Forks
202
Avg merge
3h 38m
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided APISpec example and tracing how components.schema references are processed when the schema is used through path operations with allOf, oneOf, or anyOf. Done means the generated reference contains a single '#/definitions/' prefix, with a regression test covering the demonstrated output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.