Skip to content

Commit

Permalink
Merge branch 'main' into fix/go-cyclic-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Oct 4, 2024
2 parents c220c4e + ea596c0 commit c0329a9
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 45 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed cyclic depencies in generated Go code. [#2834](https://github.com/microsoft/kiota/issues/2834)

## [1.19.0] - 2024-10-03

### Added
Expand All @@ -38,7 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed registration of default serialization and deserialization classes in client constructor. [#5478](https://github.com/microsoft/kiota/pull/5478)
- Fixed incorrect type name generation in aliased scenario in TS due to broad searching of types in root namespaces. [#5404](https://github.com/microsoft/kiota/issues/5404)
- Fixed incorrect type mapping in request builders with subsequent paths with the same name. [#5462](https://github.com/microsoft/kiota/issues/5462)
- Fixed cyclic depencies in generated Go code. [#2834](https://github.com/microsoft/kiota/issues/2834)
- Fixed multipart generation to default Content-Types are defined for multipart [#5504](https://github.com/microsoft/kiota/issues/5504)

## [1.18.0] - 2024-09-05

Expand Down
2 changes: 1 addition & 1 deletion it/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<kiota-java.version>1.5.0</kiota-java.version>
<kiota-java.version>1.5.1</kiota-java.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ microsoft-kiota-authentication-azure==1.1.0

microsoft-kiota-http==1.3.3

microsoft-kiota-serialization-json==1.3.2
microsoft-kiota-serialization-json==1.3.3

microsoft-kiota-serialization-text==1.0.0

Expand Down
56 changes: 28 additions & 28 deletions it/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions it/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
},
"dependencies": {
"@azure/identity": "^4.4.1",
"@microsoft/kiota-abstractions": "^1.0.0-preview.66",
"@microsoft/kiota-authentication-azure": "^1.0.0-preview.61",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.65",
"@microsoft/kiota-serialization-form": "^1.0.0-preview.54",
"@microsoft/kiota-serialization-json": "^1.0.0-preview.66",
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.44",
"@microsoft/kiota-serialization-text": "^1.0.0-preview.63",
"@microsoft/kiota-abstractions": "^1.0.0-preview.68",
"@microsoft/kiota-authentication-azure": "^1.0.0-preview.63",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.67",
"@microsoft/kiota-serialization-form": "^1.0.0-preview.56",
"@microsoft/kiota-serialization-json": "^1.0.0-preview.68",
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.46",
"@microsoft/kiota-serialization-text": "^1.0.0-preview.65",
"express": "^5.0.0",
"node-fetch": "^2.7.0"
}
Expand Down
29 changes: 29 additions & 0 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,23 @@ private static void AddRequestConfigurationProperties(CodeClass? parameterClass,
}

private readonly ConcurrentDictionary<CodeElement, bool> multipartPropertiesModels = new();

private static bool IsSupportedMultipartDefault(OpenApiSchema openApiSchema,
StructuredMimeTypesCollection structuredMimeTypes)
{
// https://spec.openapis.org/oas/v3.0.3.html#special-considerations-for-multipart-content
if (openApiSchema.IsObjectType() && structuredMimeTypes.Contains("application/json"))
return true;

if (GetPrimitiveType(openApiSchema) is { IsExternal: true } primitiveType && // it s a primitive
(primitiveType.Name.Equals("binary", StringComparison.OrdinalIgnoreCase)
|| primitiveType.Name.Equals("base64", StringComparison.OrdinalIgnoreCase) // streams are handled irrespective of configs
|| structuredMimeTypes.Contains("text/plain"))) // other primitives need text/plain
return true;

return false;
}

private void AddRequestBuilderMethodParameters(OpenApiUrlTreeNode currentNode, OperationType operationType, OpenApiOperation operation, CodeClass requestConfigClass, CodeMethod method)
{
if (operation.GetRequestSchema(config.StructuredMimeTypes) is OpenApiSchema requestBodySchema)
Expand All @@ -1513,6 +1530,18 @@ private void AddRequestBuilderMethodParameters(OpenApiUrlTreeNode currentNode, O
multipartPropertiesModels.TryAdd(propertyType.TypeDefinition, true);
}
}
else if (requestBodySchema.Properties.Values.Any(schema => IsSupportedMultipartDefault(schema, config.StructuredMimeTypes))
&& operation.RequestBody.Content.Count == 1)// it's the only content type.
{
requestBodyType = new CodeType { Name = "MultipartBody", IsExternal = true, };
foreach (var property in requestBodySchema.Properties.Values.Where(schema => IsSupportedMultipartDefault(schema, config.StructuredMimeTypes)))
{
if (CreateModelDeclarations(currentNode, property,
operation, method, $"{operationType}RequestBody",
isRequestBody: true) is CodeType { TypeDefinition: not null } propertyType)
multipartPropertiesModels.TryAdd(propertyType.TypeDefinition, true);
}
}
else
{
requestBodyType = CreateModelDeclarations(currentNode, requestBodySchema, operation, method,
Expand Down
61 changes: 60 additions & 1 deletion tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7706,7 +7706,66 @@ public async Task SupportsMultiPartFormAsRequestBodyWithoutEncodingWithDefaultMi
Assert.NotNull(postMethod);
var bodyParameter = postMethod.Parameters.FirstOrDefault(static x => x.IsOfKind(CodeParameterKind.RequestBody));
Assert.NotNull(bodyParameter);
Assert.Equal("directoryObjectPostRequestBody", bodyParameter.Type.Name, StringComparer.OrdinalIgnoreCase);
Assert.Equal("MultipartBody", bodyParameter.Type.Name, StringComparer.OrdinalIgnoreCase);
var addressClass = codeModel.FindChildByName<CodeClass>("Address");
Assert.NotNull(addressClass);
}
[Fact]
public async Task SupportsMultiPartFormAsRequestBodyWithoutEncodingWithDefaultMimeTypesAsyncWithNonDefaultMimeTypesAsync()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
await using var fs = await GetDocumentStreamAsync(@"openapi: 3.0.1
info:
title: Example
description: Example
version: 1.0.1
servers:
- url: https://example.org
paths:
/directoryObject:
post:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
id:
type: string
format: uuid
address:
$ref: '#/components/schemas/address'
profileImage:
type: string
format: binary
responses:
'204':
content:
application/json:
schema:
type: string
components:
schemas:
address:
type: object
properties:
street:
type: string
city:
type: string");
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration { ClientClassName = "Graph", OpenAPIFilePath = tempFilePath, IncludeAdditionalData = false, StructuredMimeTypes = new StructuredMimeTypesCollection { "multipart/form-data;q=1" } }, _httpClient);
var document = await builder.CreateOpenApiDocumentAsync(fs);
var node = builder.CreateUriSpace(document);
var codeModel = builder.CreateSourceModel(node);
Assert.NotNull(codeModel);
var rbClass = codeModel.FindChildByName<CodeClass>("directoryObjectRequestBuilder");
Assert.NotNull(rbClass);
var postMethod = rbClass.FindChildByName<CodeMethod>("Post", false);
Assert.NotNull(postMethod);
var bodyParameter = postMethod.Parameters.FirstOrDefault(static x => x.IsOfKind(CodeParameterKind.RequestBody));
Assert.NotNull(bodyParameter);
Assert.Equal("DirectoryObjectPostRequestBody", bodyParameter.Type.Name, StringComparer.OrdinalIgnoreCase); //generate the model type as we do not have the serializer for the schema registered.
var addressClass = codeModel.FindChildByName<CodeClass>("Address");
Assert.NotNull(addressClass);
}
Expand Down
8 changes: 4 additions & 4 deletions vscode/microsoft-kiota/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vscode/microsoft-kiota/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"telemetryInstrumentationKey": "4c6357e0-daf9-42b5-bdfb-67878f8957b5",
"icon": "images/logo.png",
"engines": {
"vscode": "^1.93.0"
"vscode": "^1.94.0"
},
"license": "MIT",
"categories": [
Expand Down Expand Up @@ -470,7 +470,7 @@
"@types/adm-zip": "^0.5.5",
"@types/mocha": "^10.0.8",
"@types/node": "22.x",
"@types/vscode": "^1.93.0",
"@types/vscode": "^1.94.0",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"@vscode/test-electron": "^2.4.1",
Expand Down

0 comments on commit c0329a9

Please sign in to comment.