Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kkochanski opened this issue Jan 13, 2025 · 0 comments

Comments

@kkochanski
Copy link

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"
            }
        }
    }
},
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

No branches or pull requests

1 participant