Skip to content

V2 Fix swag generating "oneOf" blocks for both form types - #2157

Merged
ubogdan merged 3 commits into
swaggo:v2from
mbd3v:v2-fix-form-generation
Aug 18, 2026
Merged

ubogdan merged 3 commits into
swaggo:v2from
mbd3v:v2-fix-form-generation

Conversation

@mbd3v

@mbd3v mbd3v commented Mar 29, 2026 •

Copy link
Copy Markdown

Describe the PR
Currently v2 branch has an issue with the generation of x-www-form-urlencoded and multipart/form-data schemas. For some reason, when generating the yaml and json for the swagger files, it is decided that if you have multiple //@Param comments then they all get bundled into a single oneOf statement which is not supposed to happen. For both forms they should look something like the following:

// @Accept          multipart/form-data
// @Produce         plain
// @Param           zip                   formData file    true  "Zip file containing checks.toml, users.toml, and/or settings.toml"
// @Param           destructiveChecks     formData boolean false "If true, destructively replace existing checks during checks.toml import"
// @Param           destructiveUsers      formData boolean false "If true, destructively replace existing users during users.toml import"
// @Param           destructiveSettings   formData boolean false "If true, destructively replace existing settings during settings.toml import"

Above comments correctly generates the below yaml:

requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                destructiveChecks:
                  description: If true, destructively replace existing checks during
                    checks.toml import
                  type: boolean
                destructiveSettings:
                  description: If true, destructively replace existing settings during
                    settings.toml import
                  type: boolean
                destructiveUsers:
                  description: If true, destructively replace existing users during
                    users.toml import
                  type: boolean
                zip:
                  description: Zip file containing checks.toml, users.toml, and/or
                    settings.toml
                  format: binary
                  type: string
              required:
              - zip
              type: object
// @Accept          application/x-www-form-urlencoded
// @Param           id          formData    int     true    "Check ID to update"
// @Param           name        formData    string  false   "Update check name"
// @Param           description formData    string  false   "Update check description"
// @Param           weight      formData    int     false   "Update check weight"
// @Param           activated   formData    boolean false   "Update check activation"
// @Param           allow_user_secrets  formData boolean false  "Are teams allowed to change the checks auth parameters?"
// @Param           type        formData    string  false   "Update check type"
// @Param           source      formData    string  false   "Update check source"
// @Param           metadata    formData    string  false   "Update check metadata"

Above x-www-form-urlencoded form correctly produces the following yaml:

      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              properties:
                activated:
                  description: Update check activation
                  type: boolean
                allow_user_secrets:
                  description: Are teams allowed to change the checks auth parameters?
                  type: boolean
                description:
                  description: Update check description
                  type: string
                id:
                  description: Check ID to update
                  type: integer
                metadata:
                  description: Update check metadata
                  type: string
                name:
                  description: Update check name
                  type: string
                source:
                  description: Update check source
                  type: string
                type:
                  description: Update check type
                  type: string
                weight:
                  description: Update check weight
                  type: integer
              required:
              - id
              type: object

Relation issue
Issue 242
Issue 2086

Both of the above issues are related to this. I didn't have time to test and see if this also fixed the json body issues that they were having but I know it at least works for the issues I have described.

PR 2131 also seems to fix the //@Accept issue so if that gets merged in first then I can remove it from this PR as well

Additional context
Go version: 1.25.8
Swag Version: 2.0.0 (Commit 8c7a6f6)

Please let me know if there is anything I should change to help get this merged in soon. Thanks for making this project!

Comment thread operationv3.go Resolved
Comment thread operationv3.go Resolved
@ubogdan

ubogdan commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

@mbd3v let's define some constants , rebase and fix conflicts.

@CefasR

CefasR commented Jun 8, 2026

Copy link
Copy Markdown

@ubogdan is there something preventing this to be merged and released?

ryansuhartanto added a commit to ryansuhartanto/koda-b8-backend2 that referenced this pull request Jul 23, 2026
Issue on multipart/form-data:
swaggo/swag#2157
@mbd3v

mbd3v commented Aug 17, 2026

Copy link
Copy Markdown
Author

sorry for the dealy. I wrote this PR right before finals and kinda forgot about it over the summer. completed the rebase/fixed conflicts and made some constants (as well as added two new tests)

@mbd3v
mbd3v force-pushed the v2-fix-form-generation branch from 889e67e to 4edde01 Compare August 17, 2026 21:02
@ubogdan

ubogdan commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@mbd3v Thanks for your contribution!

@ubogdan
ubogdan merged commit e73d748 into swaggo:v2 Aug 18, 2026
2 checks passed
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.

3 participants

⌂ 换网址