OpenAPI.NET icon indicating copy to clipboard operation
OpenAPI.NET copied to clipboard

multipart/form-data in V2 is not properly handled

Open justinyoo opened this issue 3 years ago • 2 comments

Hi, Team.

I found that there had been an issue #509 and fix #511 with regards to the file upload through the multipart/form-data content type. However, when I checked the source code, it only partially covers the cases.

  1. According to the OpenAPI v3.0.1 spec, file input/output can be the schema type/format of string/binary or string/base64. However, the codebase only looks after the string/binary pair.

    https://github.com/microsoft/OpenAPI.NET/blob/a636ec2c97ee62ddd42bcd74ffca1dfc7141a256/src/Microsoft.OpenApi/Models/OpenApiOperation.cs#L233-L236

  2. According to the 3.0.1 spec, it's valid to have schema reference (the $ref value) under the requestBody/content/<media-type>/schema object instead of the properties object. However, the current codebase only looks after the properties object.

    https://github.com/microsoft/OpenAPI.NET/blob/a636ec2c97ee62ddd42bcd74ffca1dfc7141a256/src/Microsoft.OpenApi/Models/OpenApiOperation.cs#L229

Therefore, these two issues need to be resolved for proper V3 ➡️ V2 conversion. The Azure Functions OpenAPI extension has addressed this issue, which relies on this OpenAPI.NET package.

justinyoo avatar Feb 17 '22 04:02 justinyoo

Thanks for reporting this. We will investigate.

darrelmiller avatar Feb 22 '22 03:02 darrelmiller

The first option can be resolved with this update.

 if (paramSchema.Type == "string" && (paramSchema.Format == "binary" || paramSchema.Format == "base64") ) { 
     paramSchema.Type = "file"; 
     paramSchema.Format = null; 
 } 

The second item shouldn't actually be an issue as $ref should get resolved during reference resolution after reading the file in.

darrelmiller avatar Aug 23 '22 21:08 darrelmiller