Skip to content

Request body param always generate oneOf, and incorrectly (v2) #2086

@vnen

Description

@vnen

Describe the bug
The @Param tag with body and an object type always generate an oneOf list even if it's alone and the entries are also created incorrectly.

Example output:

  /user:
    put:
      description: Update user.
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
              - type: object
              - $ref: '#/components/schemas/dto.UpdateUserInput'
                description: Update User Data
                summary: data
        description: Update User Data
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/dto.UpdateUserOutput'
          description: OK

Note how the request schema contains a oneOf with 2 items:

schema:
  oneOf:
  - type: object
  - $ref: '#/components/schemas/dto.UpdateUserInput'
    description: Update User Data
    summary: data

The first item is type: object and the second is the $ref. Instead, it should generate a single object:

schema:
  oneOf:
  - type: object
    $ref: '#/components/schemas/dto.UpdateUserInput'
    description: Update User Data
    summary: data

Note the missing - (dash) before $ref. This makes the type part of the schema. Or remove the type altogether since the reference implies it.

Of course, ideally in this case there should not be a oneOf. My guess this happens because there are 2 spurious entries (one with type and one with the reference) instead of a single one.

To Reproduce
Using the following comment:

//	@Summary		Update user.
//
//	@Description	Update user.
//
//	@Accept			json
//	@Produce		json
//
//	@Param			data body dto.UpdateUserInput true "Update User Data"
//
//	@Success		200	{object}	dto.UpdateUserOutput
//
//	@Router			/user [put]

Your swag version
v2.0.0 (bc4b08e)

Your go version
1.25.3

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser: N/A
  • Version: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions