marshmallow-code / marshmallow-code/apispec
Doubled references for schemas combined with oneOf, anyOf, allOf
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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