Skip to content

Default parameter name to schema class name or 'body' in schema2parameters - #1077

Closed
DYNOSuprovo wants to merge 1 commit into
marshmallow-code:devfrom
DYNOSuprovo:fix/schema2parameters-default-name-829
Closed

DYNOSuprovo wants to merge 1 commit into
marshmallow-code:devfrom
DYNOSuprovo:fix/schema2parameters-default-name-829

Conversation

@DYNOSuprovo

Copy link
Copy Markdown

Closes #829

Summary

When location="body" in OpenAPIConverter.schema2parameters, the parameter name previously defaulted unconditionally to "body". This change updates name: str | None = None and dynamically resolves:

  • If name is explicitly provided, use it as specified.
  • If name is not specified and schema is a Schema class or instance, default to the schema's class name.
  • If schema is not a schema class or instance and name is not specified, fall back to "body" to preserve a valid OpenAPI 2.0 parameter object.

Changes

  • Updated schema2parameters in src/apispec/ext/marshmallow/openapi.py with dynamic fallback resolution for location == "body".
  • Added test_schema_body_name_default in tests/test_ext_marshmallow_openapi.py covering class, instance, custom name, and fallback.
  • Added changelog entry in CHANGELOG.rst.

…eters

Signed-off-by: DYNOSuprovo <DYNOSuprovo@users.noreply.github.com>
@lafrech

lafrech commented Oct 3, 2026

Copy link
Copy Markdown
Member

I wouldn't qualify current behaviour as a bug but oh well.

I'm reluctant to add this complexity for a change that seems cosmetic to me. Or is it not?

What is your motivation for this? Do you have an example of a real-life use case where this affects users?

@DYNOSuprovo

Copy link
Copy Markdown
Author

Thanks for the feedback @lafrech! The initial thought was addressing #829 where the parameter name was questioned, but you are right that in OpenAPI 2.0 the body parameter name is largely conventional and primarily cosmetic. If you feel this adds unnecessary complexity without enough practical benefit to users, I am completely fine with closing the PR and keeping the existing behavior as-is.

@lafrech lafrech closed this Oct 3, 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.

wrong default value for 'name' in schema2parameters

2 participants