Skip to content

Add requestBody component (#886) - #1080

Closed
ansh-rohilla wants to merge 1 commit into
marshmallow-code:devfrom
ansh-rohilla:feat/add-requestbody-component-886
Closed

ansh-rohilla wants to merge 1 commit into
marshmallow-code:devfrom
ansh-rohilla:feat/add-requestbody-component-886

Conversation

@ansh-rohilla

Copy link
Copy Markdown

Summary

Adds support for OpenAPI v3 reusable requestBodies components as requested in #886.

Changes

  • Component Subsections: Added "request_body": "requestBodies" to COMPONENT_SUBSECTIONS[3] in apispec/utils.py.
  • Components API:
    • Initialized request_bodies and request_bodies_lazy dictionaries on Components.
    • Added Components.request_body(component_id, component=None, *, lazy=False, **kwargs).
    • Updated _resolve_refs_in_request_body to use request_body.get("content", {}) to safely handle referenced bodies.
    • Updated _resolve_refs_in_operation to resolve string references for requestBody via get_ref("request_body", ...).
  • Plugins:
    • Added request_body_helper to BasePlugin.
    • Added request_body_helper to MarshmallowPlugin to support resolving marshmallow schemas in request body components.
  • Testing:
    • Added get_request_bodies helper in tests/utils.py.
    • Added unit tests in tests/test_core.py for registration, method chaining, duplicate detection, schema/examples ref resolution, lazy registration, and operation reference resolution with validate_spec.
    • Added plugin test in tests/test_ext_marshmallow.py for registering request bodies with marshmallow schemas.
  • Changelog: Added entry under unreleased features.

Fixes #886

Add support for OpenAPI v3 requestBodies components:
- Register request_body in COMPONENT_SUBSECTIONS for OpenAPI v3.
- Add Components.request_body() for registering reusable request bodies.
- Support lazy registration and resolution of referenced request bodies in operations.
- Add request_body_helper to BasePlugin and MarshmallowPlugin.
- Add test coverage and validation against OpenAPI schema.
@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 requestBody component

2 participants