marshmallow-code / marshmallow-code/apispec

`apispec` ignores `oneOf` from `marshmallow-oneofschema`

Open
#1,012 6 comments 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

I need `oneOf` in my schema:

```py
class AerthlingsShopOffer(OneOfSchema):
"""Polymorphic offer type discriminated by the 'type' field."""
type_field = "type"
type_schemas = {
"character": AerthlingsCharacterOffer,
"mutation_point": AerthlingsMpOffer,
}
```

Marshmallow doesn't seem to support this. Fortunately, there is an extension, [`marshmallow-oneofschema`](https://github.com/marshmallow-code/marshmallow-oneofschema). Unfortunately, when presented with the class above, `apispec` silently ignores it, producing

```py
"AerthlingsShopOffer": {
"type": "object",
"properties": {}
},
```

and omitting `AerthlingsCharacterOffer` and `AerthlingsMpOffer` entirely.

I have a fix for this, but I think it requires discussion, and I have not yet written a unit test for it. If you think this is worth doing, I can complete the work and submit a PR. If not, that is no problem for me; I can continue to use my forked `apispec` in my own project.

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

No source file or test path is named; start by locating the marshmallow-oneofschema handling in apispec and reading the relevant schema-generation tests. Reproduce the AerthlingsShopOffer example, then add regression coverage confirming that oneOf and both concrete offer schemas are emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.