Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/no-cotent-additional-codes
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Mar 21, 2024
2 parents e79bc95 + dd4ecd6 commit ee91375
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 135 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixed a bug where multiple Visual Studio Code instances would make the extension install/update fail. [#3686](https://github.com/microsoft/kiota/issues/3686)
- Fixed a bug where models properties named "additionalData" or "backingstore" would be ignored. [#4224](https://github.com/microsoft/kiota/issues/4224)
- PREVIEW: Renamed the config commands to workspace. [#4310](https://github.com/microsoft/kiota/issues/4310)
- PREVIEW: Moved preview configuration files to the .kiota directory. [#4310](https://github.com/microsoft/kiota/issues/4310)
- PREVIEW: Moved the copy descriptions to dedicated folders. [#4310](https://github.com/microsoft/kiota/issues/4310)
- PREVIEW: Renamed the config to workspace file. [#4310](https://github.com/microsoft/kiota/issues/4310)
- Fixed a bug where TypeScript generation would consider boolean argument as empty when false. [#4103](https://github.com/microsoft/kiota/issues/4103)
- Changed Csharp code generation to put braces on new lines (where it makes sense). [#4347](https://github.com/microsoft/kiota/issues/4347)
- Fixed a bug where some no-content status codes would be considered structured (301, 302, 303, 307) when described. [#4190](https://github.com/microsoft/kiota/issues/4190)
- TypeScript is now a preview language!

## [1.12.0] - 2024-03-06

Expand Down
2 changes: 1 addition & 1 deletion it/csharp/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.7.12" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.8.0" />
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.1.4" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.3.7" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.1.5" />
Expand Down
90 changes: 45 additions & 45 deletions it/typescript/package-lock.json

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

16 changes: 8 additions & 8 deletions it/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
},
"dependencies": {
"@azure/identity": "^4.0.1",
"@microsoft/kiota-abstractions": "^1.0.0-preview.47",
"@microsoft/kiota-authentication-azure": "^1.0.0-preview.42",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.46",
"@microsoft/kiota-serialization-form": "^1.0.0-preview.36",
"@microsoft/kiota-serialization-json": "^1.0.0-preview.47",
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.26",
"@microsoft/kiota-serialization-text": "^1.0.0-preview.44",
"express": "^4.18.3",
"@microsoft/kiota-abstractions": "^1.0.0-preview.48",
"@microsoft/kiota-authentication-azure": "^1.0.0-preview.43",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.47",
"@microsoft/kiota-serialization-form": "^1.0.0-preview.37",
"@microsoft/kiota-serialization-json": "^1.0.0-preview.48",
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.27",
"@microsoft/kiota-serialization-text": "^1.0.0-preview.45",
"express": "^4.19.1",
"node-fetch": "^2.7.0"
}
}
2 changes: 1 addition & 1 deletion src/Kiota.Builder/CodeDOM/CodeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private string ResolveUniquePropertyName(string name)
ArgumentException.ThrowIfNullOrEmpty(serializationName);

if (BaseClass is CodeClass currentParentClass)
if (currentParentClass.FindPropertyByWireName(serializationName) is CodeProperty currentProperty && !currentProperty.ExistsInBaseType)
if (currentParentClass.FindPropertyByWireName(serializationName) is CodeProperty currentProperty && !currentProperty.ExistsInBaseType && currentProperty.Kind is not CodePropertyKind.AdditionalData or CodePropertyKind.BackingStore)
return currentProperty;
else
return currentParentClass.GetOriginalPropertyDefinedFromBaseType(serializationName);
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="AsyncKeyedLock" Version="6.3.4" />
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.7.12" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.8.0" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.3.7" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.1.5" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.1.8" />
Expand Down
5 changes: 3 additions & 2 deletions src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private static string GetDefaultValueLiteralForProperty(CodeProperty codePropert
return $"{enumDefinition.CodeEnumObject.Name.ToFirstCharacterUpperCase()}.{codeProperty.DefaultValue.Trim('"').CleanupSymbolName().ToFirstCharacterUpperCase()}";
return codeProperty.DefaultValue;
}
private static void WriteDefensiveStatements(CodeMethod codeElement, LanguageWriter writer)
private void WriteDefensiveStatements(CodeMethod codeElement, LanguageWriter writer)
{
if (codeElement.IsOfKind(CodeMethodKind.Setter)) return;

Expand All @@ -271,7 +271,8 @@ private static void WriteDefensiveStatements(CodeMethod codeElement, LanguageWri
.OrderBy(static x => x.Name, StringComparer.OrdinalIgnoreCase))
{
var parameterName = parameter.Name.ToFirstCharacterLowerCase();
writer.WriteLine($"if(!{parameterName}) throw new Error(\"{parameterName} cannot be undefined\");");
if (!"boolean".Equals(conventions.TranslateType(parameter.Type), StringComparison.OrdinalIgnoreCase))
writer.WriteLine($"if(!{parameterName}) throw new Error(\"{parameterName} cannot be undefined\");");
}
}
private string GetDeserializationMethodName(CodeTypeBase propType, CodeFunction codeFunction)
Expand Down
4 changes: 2 additions & 2 deletions src/kiota/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"DependencyInstallCommand": "go get {0}@{1}"
},
"TypeScript": {
"MaturityLevel": "Experimental",
"MaturityLevel": "Preview",
"Dependencies": [
{
"Name": "@microsoft/kiota-abstractions",
Expand Down Expand Up @@ -284,4 +284,4 @@
"DependencyInstallCommand": "dotnet add package {0} --version {1}"
}
}
}
}
77 changes: 77 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,83 @@ public async Task TrimsInheritanceUnusedModels()
Assert.Null(modelsNS.FindChildByName<CodeClass>("AuditEvent", false)); //unused type
}
[Fact]
public async Task DisambiguatesReservedProperties()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
await using var fs = await GetDocumentStream(@"openapi: 3.0.1
info:
title: OData Service for namespace microsoft.graph
description: This OData service is located at https://graph.microsoft.com/v1.0
version: v1.0
x-ms-generated-by:
toolName: Microsoft.OpenApi.OData
toolVersion: 1.0.9.0
servers:
- url: https://graph.microsoft.com/v1.0
paths:
'/security/alerts_v2/{alert-id}':
get:
responses:
200:
content:
application/json:
schema:
$ref: '#/components/schemas/microsoft.graph.alert'
components:
schemas:
microsoft.graph.entity:
title: entity
required:
- '@odata.type'
type: object
properties:
id:
type: string
'@odata.type':
type: string
microsoft.graph.dictionary:
title: dictionary
required:
- '@odata.type'
type: object
properties:
'@odata.type':
type: string
microsoft.graph.alert:
allOf:
- $ref: '#/components/schemas/microsoft.graph.entity'
- title: alert
required:
- '@odata.type'
type: object
properties:
actorDisplayName:
type: string
nullable: true
additionalData:
anyOf:
- $ref: '#/components/schemas/microsoft.graph.dictionary'
- type: object
nullable: true");
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration { ClientClassName = "Graph", OpenAPIFilePath = tempFilePath }, _httpClient);
var document = await builder.CreateOpenApiDocumentAsync(fs);
var node = builder.CreateUriSpace(document);
var codeModel = builder.CreateSourceModel(node);
var modelsNS = codeModel.FindNamespaceByName("ApiSdk.models.microsoft.graph");
Assert.NotNull(modelsNS);
var entityClass = modelsNS.FindChildByName<CodeClass>("Entity", false);
Assert.NotNull(entityClass);
var additionalDataProperty = entityClass.FindChildByName<CodeProperty>("AdditionalData", false);
Assert.NotNull(additionalDataProperty);
Assert.True(additionalDataProperty.Kind is CodePropertyKind.AdditionalData);
var alertClass = modelsNS.FindChildByName<CodeClass>("Alert", false);
Assert.NotNull(alertClass);
var additionalDataEscapedProperty = alertClass.FindChildByName<CodeProperty>("AdditionalDataProperty", false);
Assert.NotNull(additionalDataEscapedProperty);
Assert.True(additionalDataEscapedProperty.Kind is CodePropertyKind.Custom);
}
[Fact]
public async Task TrimsInheritanceUnusedModelsWithUnion()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
Expand Down
Loading

0 comments on commit ee91375

Please sign in to comment.