Wrong schema generation on endpoint consuming multipart form data combined with JsonView
Describe the bug When using method consuming MediaType.MULTIPART_FORM_DATA_VALUE, schemas for RequestPart objects are generated based on JsonView from method level, which should be related only to response schema, instead of parameter level
To Reproduce Steps to reproduce the behavior:
- spring-boot version: 2.7.3
- springodc-openapi-ui version: 1.6.11
HelloController:
@PostMapping(value = "/foo", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@JsonView(ViewB.class)
public Foo postFoo(@RequestPart("input") @JsonView(ViewA.class) Foo foo) {
return null;
}
Foo:
@Data
public class Foo {
@JsonView(ViewA.class)
private String a;
@JsonView(ViewB.class)
private String b;
}
/v3/api-docs:
paths": {
"/foo": {
"post": {
"tags": [
"hello-controller"
],
"operationId": "postFoo",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"input"
],
"type": "object",
"properties": {
"input": {
"$ref": "#/components/schemas/Foo_ViewB"
}}}}}},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Foo_ViewB"
}}}}}}}},
"components": {
"schemas": {
"Foo_ViewB": {
"type": "object",
"properties": {
"b": {
"type": "string"
}}}}}
Analogically, when no JsonView annotation is present on method level then the only generated shema is Foo with properties a and b and both input and response objects refer to that schema, ignoring JsonView(ViewA.class) on parameter
Expected behavior
- 2 schemas are generated: Foo_ViewA with property a and Foo_ViewB with property b
- response schema should refer to Foo_ViewB and input object should refer to Foo_ViewA
I have similar issue, since version 1.6.10 all query Parameters on endpoint that consumes multipart/form-data are incorrectly reported as Request body parts.
Example:
@PostMapping(value = "/bitmap", consumes = "multipart/form-data", produces = "application/json")
public ImageInfoDTO uploadImage(
@Parameter(description = "Uploaded image", required = true) @RequestPart MultipartFile file,
@Parameter(description = "File access restriction (default is OWNER_ONLY)") @RequestParam Access access
) { ... }
Produces:
{
"paths": {
"/bitmap": {
"post": {
"tags": [
"Image"
],
"operationId": "uploadImage",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"file"
],
"type": "object",
"properties": {
"file": {
"type": "string",
"description": "Uploaded image",
"format": "binary"
},
"access": {
"description": "File access restriction (default is OWNER_ONLY)"
}
}
}
}
}
},
"responses": {...}
}
}
}
}
Expected behaviour:
Query parameter access should be listed within parameters and not as a part of requestBody schema
Same still on 1.6.11, I have discovered that just yesterday
Workaround is to use:
springdoc.default-support-form-data=false
This will be the default behavior, starting from 1.6.12
Issue reported in comment by mdjimy is indeed fixed, but what about my issue with wrong schema when using JsonView? I tried suggested workaround and upgraded to version 1.6.13 but both seem to not fix this issue, result is still the same
Actual controller that I'm using contains also MultipartFile, so that would be more precise reporduction:
@PostMapping(value = "/foo", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@JsonView(ViewB.class)
public Foo postFoo(@RequestPart("input") @JsonView(ViewA.class) Foo foo,
@RequestPart("file") MultipartFile file) {
return null;
}
Maybe your fix doesn't cover that case so it would be my fault by providing inaccurate reproduction step so sorry for that.