Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/multipart and other type #5639

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/// <summary>
/// cleans application/vnd.github.mercy-preview+json to application/json
/// </summary>
internal static OpenApiSchema? GetResponseSchema(this OpenApiOperation operation, StructuredMimeTypesCollection structuredMimeTypes)

Check warning on line 24 in src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'GetResponseSchema' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)

Check warning on line 24 in src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'GetResponseSchema' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
{
ArgumentNullException.ThrowIfNull(operation);
// Return Schema that represents all the possible success responses!
Expand All @@ -41,7 +41,7 @@
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<string, OpenApiMediaType> source, StructuredMimeTypesCollection structuredMimeTypes)
{
return source.GetValidSchemas(structuredMimeTypes).FirstOrDefault() is OpenApiSchema schema &&
Expand All @@ -53,7 +53,7 @@
ArgumentNullException.ThrowIfNull(structuredMimeTypes);
if (structuredMimeTypes.Count == 0) return false;
if (!source.ContainsKey(multipartMimeTypes.First())) return false;
if (source.Count == 1) 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<OpenApiSchema> GetValidSchemas(this IDictionary<string, OpenApiMediaType> source, StructuredMimeTypesCollection structuredMimeTypes)
Expand Down
10 changes: 10 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@
_tempFiles.Add(tempFilePath);
}
[Fact]
public async Task DoesntThrowOnMissingServerForV2Async()

Check warning on line 1222 in tests/Kiota.Builder.Tests/KiotaBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Build

Add at least one assertion to this test case. (https://rules.sonarsource.com/csharp/RSPEC-2699)

Check warning on line 1222 in tests/Kiota.Builder.Tests/KiotaBuilderTests.cs

View workflow job for this annotation

GitHub Actions / Build

Add at least one assertion to this test case. (https://rules.sonarsource.com/csharp/RSPEC-2699)
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
await File.WriteAllLinesAsync(tempFilePath, new[] { "swagger: 2.0", "title: \"Todo API\"", "version: \"1.0.0\"", "host: mytodos.doesntexit", "basePath: v2", "schemes:", " - https", " - http" });
Expand Down Expand Up @@ -7603,6 +7603,16 @@
post:
requestBody:
content:
text/csv:
schema:
type: object
properties:
file:
type: string,
format: binary
encoding:
file:
style: form
multipart/form-data:
schema:
type: object
Expand Down
Loading