Skip to content

@Schema(types = "xxx") does not work for multipart param with enabled springdoc.default-support-form-data config option #2852

Closed

Description

@kkochanski

I'm using.

  • Spring Boot v3.4.1
  • Springdoc OpenAPI v2.8.1
  • OAS v3.1

In my example I'm using @Schema(types = "boolean").

Here's a code that will generate a valid Swagger definition.

@PostMapping(path = "/dummy", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(value = HttpStatus.OK)
public String dummy(
    @RequestPart(value = "file", required = false) MultipartFile file,
    @Parameter(description = "There is dummy param", schema = @Schema(types = "boolean")) @RequestParam(name = "is_dummy") String isDummy
) {
    return "";
}

The param definition is as follows. It's valid.

"parameters": [
    {
        "name": "is_dummy",
        "in": "query",
        "description": "There is dummy param",
        "required": true,
        "schema": {
            "type": "boolean"
        }
    }
],
"requestBody": {
    "content": {
        "multipart/form-data": {
            "schema": {
                "type": "object",
                "properties": {
                    "file": {
                        "type": "string",
                        "format": "binary"
                    }
                }
            }
        }
    }
}

Then let's try to set true for springdoc.default-support-form-data config option. We will get a param definition as follows.

"requestBody": {
    "content": {
        "multipart/form-data": {
            "schema": {
                "type": "object",
                "properties": {
                    "file": {
                        "type": "string",
                        "format": "binary"
                    },
                    "is_dummy": {
                        "description": "There is dummy param"
                    }
                }
            }
        }
    }
}

The schema to is_dummy field is not added anymore.

Another example properly working example. Code below. POST with application/x-www-form-urlencoded content type.

@PostMapping(path = "/dummy", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @ResponseStatus(value = HttpStatus.OK)
    public String dummy(
        @Parameter(description = "There is dummy param", schema = @Schema(types = "boolean")) @RequestParam(name = "is_dummy") String isDummy
    ) {
        return "";
    }

It produces valid param definition.

"requestBody": {
    "content": {
        "application/x-www-form-urlencoded": {
            "schema": {
                "type": "boolean",
                "description": "There is dummy param"
            }
        }
    }
},

Activity

  1. added a commit that references this issue on Jan 13, 2025
    06b297a
  2. added a commit that references this issue on May 17, 2025
    64bf43f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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