Skip to content

feat(marshmallow): support Tuple field in OpenAPI 3.1+ (closes #399) - #1084

Closed
ansh-rohilla wants to merge 1 commit into
marshmallow-code:devfrom
ansh-rohilla:feat/support-marshmallow-tuple-399
Closed

ansh-rohilla wants to merge 1 commit into
marshmallow-code:devfrom
ansh-rohilla:feat/support-marshmallow-tuple-399

Conversation

@ansh-rohilla

Copy link
Copy Markdown

Summary

Implements support for marshmallow.fields.Tuple translation into OpenAPI 3.1+ schema definitions according to the JSON Schema 2020-12 standard (fixes #399).

Per discussion in #399:

  • OpenAPI 3.1+ translates fields.Tuple into {"type": "array", "prefixItems": [...], "items": False}.
  • If an older OpenAPI version (< 3.1.0) is used, an informative APISpecError is raised indicating that Tuple is only supported in OpenAPI 3.1.0 and above.
  • In apispec.core.Components._resolve_refs_in_schema and SchemaResolver.resolve_schema_dict:
    • items resolution guards against boolean schemas (such as items: False) to prevent them from being incorrectly mutated into reference objects ({'$ref': '#/components/schemas/False'}).
    • Added recursive reference resolution for schemas within prefixItems.
  • Registered marshmallow.fields.Tuple in DEFAULT_FIELD_MAPPING, _VALID_PROPERTIES, field2length, and added tuple2properties.

Testing

  • Added comprehensive unit tests in tests/test_ext_marshmallow_field.py covering scalar fields, empty tuples, nullable tuples, Length validators, dump/load only, metadata, and nested tuples.
  • Added integration tests in tests/test_ext_marshmallow.py testing schemas with tuples, nested schemas with references inside tuples, and operations with tuples validated against openapi-spec-validator.
  • Added core ref resolution test in tests/test_core.py for OpenAPI 3.1 tuple schemas with prefixItems and items: False.
  • All linters and test suites pass (pytest, mypy, ruff, pre-commit).

@sloria sloria closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Marshmallow Tuple field

2 participants