-
-
Notifications
You must be signed in to change notification settings - Fork 539
Description
Describe the bug
I'm writing a controller that does a "direct" file upload (i.e. send the content in the body, without multi-part encoding. like curl --upload-file
). When I use the type InputStream
for my request body, the generated openapi docs omit the field. For example:
@PostMapping(path = "/upload")
public String upload(@RequestParam final String someParam, @RequestBody final InputStream body) {
return "";
}
produces
paths:
/upload:
post:
operationId: upload
parameters:
- name: someParam
in: query
required: true
schema:
type: string
responses:
"200":
description: default response
content:
'*/*':
schema:
type: string
Well, an InputStream could be anything, not necessarily a file, so it kind of makes sense but even when I add annotations from io.swagger.v3.oas.annotations
@PostMapping(path = "/upload")
public String upload(
@RequestParam final String someParam,
@io.swagger.v3.oas.annotations.parameters.RequestBody(
content =
@Content(
mediaType = "application/octet-stream",
schema = @Schema(type = "string", format = "binary")))
@RequestBody
final InputStream body) {
return "";
}
Interestingly, when I change the parameter type to File
, the code fails at runtime but it does produce the correct swagger code, even without the additional annotations.
@PostMapping(path = "/upload")
public String upload(@RequestParam final String someParam, @RequestBody final File body) {
return "";
}
paths:
/upload:
post:
operationId: upload
parameters:
- name: someParam
in: query
required: true
schema:
type: string
requestBody:
content:
'*/*':
schema:
type: string
format: binary
responses:
"200":
description: default response
content:
'*/*':
schema:
type: string
To be clear, the requestBody
section is what is missing in the other ones. And with annotations on File, I'm able to change the content-type and format.
Versions
Spring boot 2.2.4 plus
[INFO] +- org.springframework.restdocs:spring-restdocs-mockmvc:jar:2.0.4.RELEASE:test
[INFO] | +- javax.servlet:javax.servlet-api:jar:4.0.1:test
[INFO] | \- org.springframework.restdocs:spring-restdocs-core:jar:2.0.4.RELEASE:test
[INFO] +- org.springdoc:springdoc-openapi-core:jar:1.1.44:compile
[INFO] | \- org.springdoc:springdoc-openapi-common:jar:1.1.44:compile
[INFO] | +- io.swagger.core.v3:swagger-models:jar:2.0.9:compile
[INFO] | +- io.swagger.core.v3:swagger-annotations:jar:2.0.9:compile
[INFO] | \- io.swagger.core.v3:swagger-integration:jar:2.0.9:compile
[INFO] | +- io.github.classgraph:classgraph:jar:4.6.32:compile
[INFO] | \- io.swagger.core.v3:swagger-core:jar:2.0.9:compile
[INFO] | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.10.2:compile
[INFO] | \- javax.validation:validation-api:jar:2.0.1.Final:compile
Expected behavior
I expect the behavior I get with a File parameter, which produces a spec like this one https://swagger.io/docs/specification/describing-request-body/file-upload/