Skip to content

fix: avoid oneOf when @Accept adds default schema - #2131

Merged
ubogdan merged 1 commit into
swaggo:v2from
taba2424:fix/request-param
Apr 9, 2026
Merged

ubogdan merged 1 commit into
swaggo:v2from
taba2424:fix/request-param

Conversation

@taba2424

@taba2424 taba2424 commented Jan 10, 2026 •

Copy link
Copy Markdown

Describe the PR

  • Fix OpenAPI v3 requestBody schema generation so the default schema created by @Accept does not get merged via oneOf with the actual body schema.
  • Replace the placeholder type: object with the real body schema when @Param ... body is parsed after @Accept.
  • Add a regression test covering @Accept json + body parameter.

Relation issue

N/A (no related issue)

Additional context

Example setup:

// @Accept json
// @Param request body types.CreateRequest true "作成リクエスト"

Command (example):

Generated specs using swag init with OpenAPI v3.1 output and YAML format.
Before, the generated requestBody schema included:

oneOf:
  - type: object
  - $ref: '#/components/schemas/CreateRequest'

This PR ensures the placeholder type: object from @accept is replaced by the actual body schema, resulting in only the $ref entry.

@taba2424
taba2424 marked this pull request as ready for review January 10, 2026 20:51
@taba2424 taba2424 changed the title fix(v3): avoid oneOf when @Accept adds default schema fix: avoid oneOf when @Accept adds default schema Jan 10, 2026
@mmierzwa

mmierzwa commented Feb 5, 2026

Copy link
Copy Markdown

It would be great to have it. I was really confused when I discovered this oneOf result

@ubogdan ubogdan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ubogdan
ubogdan merged commit 05f82c4 into swaggo:v2 Apr 9, 2026
14 checks passed
@ubogdan

ubogdan commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

@taba2424 Thanks for your contribution.

@kundkingan

Copy link
Copy Markdown

When can we expect a new rc release @ubogdan

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.

4 participants

⌂ 换网址