From c4dc8b35ce657092512f08ba68dc568dc66f105c Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 15:06:15 -0400 Subject: [PATCH 1/2] fix: multipart not detected because of other type --- CHANGELOG.md | 1 + .../Extensions/OpenApiOperationExtensions.cs | 4 ++-- tests/Kiota.Builder.Tests/KiotaBuilderTests.cs | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 958fa5fce4..a732d9914d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Fixed an issue where multipart request content would be ignored if other unstructured content was present in the description. [#5638](https://github.com/microsoft/kiota/issues/5638) - Fixed an issue where when generating Go code the deserializer for unions was using `CodeClass` as a filter and not `CodeInterface`. [#4844](https://github.com/microsoft/kiota/issues/4844) - Fixes mapping of `int16` format to the `integer` type rather than `double` when the type is `integer` or `number` [#5611](https://github.com/microsoft/kiota/issues/5611) - Fixes typing inconsistencies in generated code and libraries in Python [kiota-python#333](https://github.com/microsoft/kiota-python/issues/333) diff --git a/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs b/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs index aca62940e2..619c1e2f96 100644 --- a/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs +++ b/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs @@ -41,7 +41,7 @@ internal static IEnumerable GetResponseSchemas(this OpenApiOperat return operation.RequestBody?.Content .GetValidSchemas(structuredMimeTypes).FirstOrDefault(); } - private static readonly StructuredMimeTypesCollection multipartMimeTypes = new(new string[] { "multipart/form-data" }); + private static readonly StructuredMimeTypesCollection multipartMimeTypes = new(["multipart/form-data"]); internal static bool IsMultipartFormDataSchema(this IDictionary source, StructuredMimeTypesCollection structuredMimeTypes) { return source.GetValidSchemas(structuredMimeTypes).FirstOrDefault() is OpenApiSchema schema && @@ -53,7 +53,7 @@ internal static bool IsMultipartTopMimeType(this IDictionary !multipartMimeTypes.Contains(x)).Any(x => structuredMimeTypes.Contains(x))) return true; return structuredMimeTypes.First() == multipartMimeTypes.First(); } internal static IEnumerable GetValidSchemas(this IDictionary source, StructuredMimeTypesCollection structuredMimeTypes) diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index 32123dcde3..aaf4e8d449 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -7603,6 +7603,16 @@ public async Task SupportsMultiPartFormAsRequestBodyWithDefaultMimeTypesAsync() post: requestBody: content: + text/csv: + schema: + type: object + properties: + file: + type: string, + format: binary + encoding: + file: + style: form multipart/form-data: schema: type: object From beea9d3ddb249305ac5610fe43cd0e7237abb66f Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 18 Oct 2024 15:06:47 -0400 Subject: [PATCH 2/2] chore: code linting Signed-off-by: Vincent Biret --- src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs b/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs index 619c1e2f96..2ca1fd3009 100644 --- a/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs +++ b/src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs @@ -53,7 +53,7 @@ internal static bool IsMultipartTopMimeType(this IDictionary !multipartMimeTypes.Contains(x)).Any(x => structuredMimeTypes.Contains(x))) return true; + if (source.Count == 1 || !source.Keys.Where(static x => !multipartMimeTypes.Contains(x)).Any(structuredMimeTypes.Contains)) return true; return structuredMimeTypes.First() == multipartMimeTypes.First(); } internal static IEnumerable GetValidSchemas(this IDictionary source, StructuredMimeTypesCollection structuredMimeTypes)