vertx-web
vertx-web copied to clipboard
openapi : File with content type \\Qimage/\\E.* and name license is missing
Questions
I have define an openapi endpoint with
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
name:
type: string
license:
type: string
format: binary
required:
- name
encoding:
license:
contentType: 'image/*'
only the 'name' properties is required.
but if i give license a image file , it works, if nothing to license then get exception:
File with content type \\Qimage/\\E.* and name license is missing
i don't know why vert.x must to verify parameter license when is not required , can someone tell me this ?
thx
Version
Vert.x 4.2.6
and i check the source code in MultipartFormBodyProcessorGenerator and RequestPredicate found in:
static RequestPredicate multipartFileUploadExists(String propertyName, String contentTypePattern) {
Pattern contentType = Pattern.compile(contentTypePattern);
return rc -> {
if (
rc.request().headers().contains(HttpHeaders.CONTENT_TYPE) &&
rc.request().getHeader(HttpHeaders.CONTENT_TYPE).contains("multipart/form-data")
) {
Set<FileUpload> files = rc.fileUploads();
for (FileUpload f : files) {
if (f.name().equals(propertyName) && contentType.matcher(f.contentType()).matches()) return success();
}
return failed(String.format("File with content type %s and name %s is missing", contentType, propertyName));
} else return success();
};
}
it don't check whether a field is required or not , just check the fileUpload exists, this may be the problem? i think.
Any update on this? I see some referenced commits, but it didn't move on. If no one is looking into it, I might supply a PR if needed.
Any update on this? I see some referenced commits, but it didn't move on. If no one is looking into it, I might supply a PR if needed.
no update any more
Hello,
I have similar (but not exactly) issue on my side.
In the above, the multipartFileUploadExists Predicate is added to context for 'licence' part, BUT it shall not be the case as the 'licence' part is NOT a file part.
I've checked the vertx code for: https://github.com/vert-x3/vertx-web/blob/master/vertx-web-openapi/src/main/java/io/vertx/ext/web/openapi/impl/MultipartFormBodyProcessorGenerator.java
at line 57,
the multipartFileUploadExists Predicate is added by mistake because it is wrongly assumed that a part with encoding contentType is a file part that seems not be specified by OpenAPI standard:
So there is 2 issues linked to this thread:
- unrequired property shall not be checked if missing
- none file part shall not be processed like a file part.
@Indexea In your case, as temporary workaround, I think you should try to remove the 'encoding' section.
Is there any update? The issue was created more than a year ago and I still get the same error with a similar spec. It does not matter, if you add the encoding section or not in my case.