marshmallow-code / marshmallow-code/apispec
Marshmallow’s Nested fields with a restricted schema steal the full schema’s registry spot
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 202
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 3
Description
If we e.g. have a marshmallow Schema like this:
```py
from marshmallow_sqlalchemy import fields, SQLAlchemyAutoSchema
class FooSchema(SQLAlchemyAutoSchema):
parent = fields.Nested("BarSchema", only=("id", "name"))
```
and call `spec.components.schema('Foo', schema=FooSchema)`, then “BarSchema” gets registered as having only the fields `id` and `name`, and subsequent tries to register the real thing fail.
The problem lies here:
https://github.com/marshmallow-code/apispec/blob/d418e3efa27f799ae3dabbdbb00ccd07eb10ce07/src/apispec/ext/marshmallow/openapi.py#L108
As that function somehow doesn’t give us something useful. Also it should first modify names for schemas where `schema.only is not None` before it modifies schemas where `schema.only is None`.
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 at src/apispec/ext/marshmallow/openapi.py around line 108 and reproduce the issue with the FooSchema example using a restricted Nested field. Verify that registering FooSchema does not reserve BarSchema with only the restricted fields, and that a later registration preserves the full schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100