vertx-web icon indicating copy to clipboard operation
vertx-web copied to clipboard

openapi : File with content type \\Qimage/\\E.* and name license is missing

Open Indexea opened this issue 3 years ago • 5 comments

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.

Indexea avatar Mar 28 '22 09:03 Indexea

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.

ayhanap avatar Feb 13 '23 12:02 ayhanap

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

Indexea avatar Feb 13 '23 14:02 Indexea

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:

  1. unrequired property shall not be checked if missing
  2. none file part shall not be processed like a file part.

dprincethg avatar Mar 01 '23 10:03 dprincethg

@Indexea In your case, as temporary workaround, I think you should try to remove the 'encoding' section.

dprincethg avatar Mar 01 '23 10:03 dprincethg

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.

matthi-g avatar Jun 14 '23 00:06 matthi-g