-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
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: OKNote how the request schema contains a oneOf with 2 items:
schema:
oneOf:
- type: object
- $ref: '#/components/schemas/dto.UpdateUserInput'
description: Update User Data
summary: dataThe 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: dataNote 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