Skip to content

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

Open
mbd3v wants to merge 1 commit intoswaggo:v2from
mbd3v:v2-fix-form-generation
Open

V2 Fix swag generating "oneOf" blocks for both form types#2157
mbd3v wants to merge 1 commit intoswaggo:v2from
mbd3v:v2-fix-form-generation

Conversation

@mbd3v
Copy link
Copy Markdown

@mbd3v mbd3v commented Mar 29, 2026

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!

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.

1 participant