feat: add list_as_array flag to MarshmallowPlugin for array-root requestBody#982
Open
nomi3 wants to merge 3 commits intomarshmallow-code:devfrom
Open
feat: add list_as_array flag to MarshmallowPlugin for array-root requestBody#982nomi3 wants to merge 3 commits intomarshmallow-code:devfrom
list_as_array flag to MarshmallowPlugin for array-root requestBody#982nomi3 wants to merge 3 commits intomarshmallow-code:devfrom
Conversation
lafrech
reviewed
Jul 25, 2025
|
|
||
| :param schema: schema to add to the spec | ||
| """ | ||
| if isinstance(schema, marshmallow.fields.List) and getattr( |
Member
There was a problem hiding this comment.
Why use getattr? Isn't list_as_array always defined?
Author
There was a problem hiding this comment.
You're right! I've removed the getattr calls and now use self.list_as_array directly.
Member
|
Does it have to be optional? I mean is there any reason to pass an array if this flag is not set? If so, wouldn't that use case be broken if this flag is set to accommodate for a given resource? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenAPI 3.x fully supports request bodies whose root schema is an array, but apispec + marshmallow currently cannot generate such schemas automatically. Projects must hand-write YAML/dict snippets for every endpoint that needs it.
This PR introduces an opt-in flag—list_as_array—to MarshmallowPlugin that lets the plugin emit type: array schemas automatically when:
The default behaviour remains unchanged (object-root), so the change is non-breaking.