Skip to content

Commit

Permalink
Merge branch 'main' into feature/typescript/composed-types
Browse files Browse the repository at this point in the history
  • Loading branch information
koros committed Jun 14, 2024
2 parents b3e5655 + 9c8d937 commit 8c26bde
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- TypeScript imports are now using ES6 imports with the .js extension.
- Remove LINQ usage in generated code.
- Ensures descriptions are not empty in sliced OpenApi file when generating a plugin.

## [1.15.0] - 2024-06-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 @@ -21,4 +21,4 @@
<Compile Remove="basic\**" />
</ItemGroup>

</Project>
</Project>
3 changes: 2 additions & 1 deletion scripts/update-versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function Get-LatestNugetVersion {

$url = "https://api.nuget.org/v3/registration5-gz-semver2/$($packageId.ToLowerInvariant())/index.json"
$response = Invoke-RestMethod -Uri $url -Method Get
$response.items[0].upper
$version = $response.items | Select-Object -ExpandProperty upper | ForEach-Object { [System.Management.Automation.SemanticVersion]$_ } | sort-object | Select-Object -Last 1
$version.ToString()
}
# Get the latest github release
function Get-LatestGithubRelease {
Expand Down
3 changes: 3 additions & 0 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu
//empty out all the responses with a single empty 2XX
foreach (var operation in doc.Paths.SelectMany(static item => item.Value.Operations.Values))
{
var responseDescription = operation.Responses.Values.Select(static response => response.Description)
.FirstOrDefault(static desc => !string.IsNullOrEmpty(desc)) ?? "Api Response";
operation.Responses = new OpenApiResponses()
{
{
"2XX",new OpenApiResponse
{
Description = responseDescription,
Content = new Dictionary<string, OpenApiMediaType>
{
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/CSharpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected static void MakeEnumPropertiesNullable(CodeElement currentElement)
new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.RequestBuilder),
"System.Threading.Tasks", "Task"),
new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model, CodeClassKind.RequestBuilder),
"System.Linq", "Enumerable"),
ExtensionsNamespaceName, "Enumerable"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.ClientConstructor) &&
method.Parameters.Any(y => y.IsOfKind(CodeParameterKind.BackingStore)),
StoreNamespaceName, "IBackingStoreFactory", "IBackingStoreFactorySingleton"),
Expand Down
6 changes: 3 additions & 3 deletions src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class CodeMethodWriter : BaseElementWriter<CodeMethod, CSharpConventionSe
{
public CodeMethodWriter(CSharpConventionService conventionService) : base(conventionService)
{

}

public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter writer)
{
ArgumentNullException.ThrowIfNull(codeElement);
Expand Down Expand Up @@ -350,7 +350,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me
{
if (isCollection)
{
var collectionMethod = propType.IsArray ? "?.ToArray()" : "?.ToList()";
var collectionMethod = propType.IsArray ? "?.AsArray()" : "?.AsList()";
if (currentType.TypeDefinition == null)
return $"GetCollectionOfPrimitiveValues<{propertyType}>(){collectionMethod}";
else if (currentType.TypeDefinition is CodeEnum)
Expand Down Expand Up @@ -407,7 +407,7 @@ protected void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams re
};
writer.WriteLine($"{prefix}await RequestAdapter.{GetSendRequestMethodName(isVoid, codeElement, codeElement.ReturnType)}(requestInfo{returnTypeFactory}, {errorMappingVarName}, cancellationToken).ConfigureAwait(false);");
if (codeElement.ReturnType.IsCollection)
writer.WriteLine("return collectionResult?.ToList();");
writer.WriteLine("return collectionResult?.AsList();");
}
private const string RequestInfoVarName = "requestInfo";
private void WriteRequestGeneratorBody(CodeMethod codeElement, RequestParams requestParams, CodeClass currentClass, LanguageWriter writer)
Expand Down
72 changes: 36 additions & 36 deletions src/kiota/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@
"Dependencies": [
{
"Name": "Microsoft.Kiota.Abstractions",
"Version": "1.8.1"
"Version": "1.9.6"
},
{
"Name": "Microsoft.Kiota.Http.HttpClientLibrary",
"Version": "1.3.8"
"Version": "1.4.3"
},
{
"Name": "Microsoft.Kiota.Serialization.Form",
"Version": "1.1.5"
"Version": "1.2.4"
},
{
"Name": "Microsoft.Kiota.Serialization.Json",
"Version": "1.2.0"
"Version": "1.3.3"
},
{
"Name": "Microsoft.Kiota.Authentication.Azure",
"Version": "1.1.4"
"Version": "1.1.7"
},
{
"Name": "Microsoft.Kiota.Serialization.Text",
"Version": "1.1.4"
"Version": "1.2.2"
},
{
"Name": "Microsoft.Kiota.Serialization.Multipart",
"Version": "1.1.3"
"Version": "1.1.5"
}
],
"DependencyInstallCommand": "dotnet add package {0} --version {1}"
Expand All @@ -61,35 +61,35 @@
"Dependencies": [
{
"Name": "com.microsoft.kiota:microsoft-kiota-abstractions",
"Version": "1.1.3"
"Version": "1.1.14"
},
{
"Name": "com.microsoft.kiota:microsoft-kiota-http-okHttp",
"Version": "1.1.3"
"Version": "1.1.14"
},
{
"Name": "com.microsoft.kiota:microsoft-kiota-serialization-form",
"Version": "1.1.3"
"Version": "1.1.14"
},
{
"Name": "com.microsoft.kiota:microsoft-kiota-serialization-json",
"Version": "1.1.3"
"Version": "1.1.14"
},
{
"Name": "com.microsoft.kiota:microsoft-kiota-authentication-azure",
"Version": "1.1.3"
"Version": "1.1.14"
},
{
"Name": "com.microsoft.kiota:microsoft-kiota-serialization-text",
"Version": "1.1.3"
"Version": "1.1.14"
},
{
"Name": "com.microsoft.kiota:microsoft-kiota-serialization-multipart",
"Version": "1.1.3"
"Version": "1.1.14"
},
{
"Name": "jakarta.annotation:jakarta.annotation-api",
"Version": "3.0.0-M1"
"Version": "3.0.0"
}
],
"DependencyInstallCommand": "{0}:{1}"
Expand All @@ -103,7 +103,7 @@
},
{
"Name": "github.com/microsoft/kiota-http-go",
"Version": "v1.3.3"
"Version": "v1.4.1"
},
{
"Name": "github.com/microsoft/kiota-serialization-form-go",
Expand Down Expand Up @@ -133,31 +133,31 @@
"Dependencies": [
{
"Name": "@microsoft/kiota-abstractions",
"Version": "1.0.0-preview.50"
"Version": "1.0.0-preview.56"
},
{
"Name": "@microsoft/kiota-http-fetchlibrary",
"Version": "1.0.0-preview.49"
"Version": "1.0.0-preview.55"
},
{
"Name": "@microsoft/kiota-serialization-form",
"Version": "1.0.0-preview.39"
"Version": "1.0.0-preview.45"
},
{
"Name": "@microsoft/kiota-serialization-json",
"Version": "1.0.0-preview.50"
"Version": "1.0.0-preview.56"
},
{
"Name": "@microsoft/kiota-authentication-azure",
"Version": "1.0.0-preview.45"
"Version": "1.0.0-preview.51"
},
{
"Name": "@microsoft/kiota-serialization-text",
"Version": "1.0.0-preview.47"
"Version": "1.0.0-preview.53"
},
{
"Name": "@microsoft/kiota-serialization-multipart",
"Version": "1.0.0-preview.28"
"Version": "1.0.0-preview.34"
}
],
"DependencyInstallCommand": "npm install {0}@{1} -SE"
Expand All @@ -167,31 +167,31 @@
"Dependencies": [
{
"Name": "microsoft/kiota-abstractions",
"Version": "1.2.0"
"Version": "1.4.0"
},
{
"Name": "microsoft/kiota-http-guzzle",
"Version": "1.3.0"
},
{
"Name": "microsoft/kiota-serialization-json",
"Version": "1.1.0"
"Version": "1.3.0"
},
{
"Name": "microsoft/kiota-authentication-phpleague",
"Version": "1.1.0"
},
{
"Name": "microsoft/kiota-serialization-text",
"Version": "1.0.1"
"Version": "1.1.0"
},
{
"Name": "microsoft/kiota-serialization-multipart",
"Version": "1.0.0"
},
{
"Name": "microsoft/kiota-serialization-form",
"Version": "1.0.0"
"Version": "1.1.1"
}
],
"DependencyInstallCommand": "composer require {0}:{1}"
Expand All @@ -201,15 +201,15 @@
"Dependencies": [
{
"Name": "microsoft-kiota-abstractions",
"Version": "1.3.2"
"Version": "1.3.3"
},
{
"Name": "microsoft-kiota-http",
"Version": "1.3.1"
},
{
"Name": "microsoft-kiota-serialization-json",
"Version": "1.1.0"
"Version": "1.2.0"
},
{
"Name": "microsoft-kiota-authentication-azure",
Expand Down Expand Up @@ -262,31 +262,31 @@
"Dependencies": [
{
"Name": "Microsoft.Kiota.Abstractions",
"Version": "1.8.1"
"Version": "1.9.6"
},
{
"Name": "Microsoft.Kiota.Http.HttpClientLibrary",
"Version": "1.3.8"
"Version": "1.4.3"
},
{
"Name": "Microsoft.Kiota.Serialization.Form",
"Version": "1.1.5"
"Version": "1.2.4"
},
{
"Name": "Microsoft.Kiota.Serialization.Json",
"Version": "1.2.0"
"Version": "1.3.3"
},
{
"Name": "Microsoft.Kiota.Authentication.Azure",
"Version": "1.1.4"
"Version": "1.1.7"
},
{
"Name": "Microsoft.Kiota.Serialization.Text",
"Version": "1.1.4"
"Version": "1.2.2"
},
{
"Name": "Microsoft.Kiota.Cli.Commons",
"Version": "1.1.0"
"Version": "1.1.1"
}
],
"DependencyInstallCommand": "dotnet add package {0} --version {1}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public async Task GeneratesManifestAndCleansUpInputDescription()
Assert.Empty(resultDocument.Extensions); // no extension at root (unsupported extension is removed)
Assert.Equal(2, resultDocument.Paths.Count); // document has only two paths
Assert.Single(resultDocument.Paths["/test"].Operations[OperationType.Get].Responses); // other responses are removed from the document
Assert.NotEmpty(resultDocument.Paths["/test"].Operations[OperationType.Get].Responses["2XX"].Description); // response description string is not empty
Assert.Single(resultDocument.Paths["/test/{id}"].Operations[OperationType.Get].Responses); // 2 responses originally
Assert.NotEmpty(resultDocument.Paths["/test/{id}"].Operations[OperationType.Get].Responses["2XX"].Description);// response description string is not empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public void WritesRequestExecutorBodyForCollection()
Assert.Contains("var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>", result);
Assert.Contains("{ \"4XX\", Error4XX.CreateFromDiscriminatorValue },", result);
Assert.Contains("SendCollectionAsync", result);
Assert.Contains("return collectionResult?.ToList()", result);
Assert.Contains("return collectionResult?.AsList()", result);
Assert.Contains($"{ReturnTypeName}.CreateFromDiscriminatorValue", result);
AssertExtensions.CurlyBracesAreClosed(result, 1);
}
Expand Down Expand Up @@ -592,7 +592,7 @@ public void WritesModelFactoryBodyForUnionModels()
Assert.Contains("ComplexType1Value = new ComplexType1()", result);
Assert.Contains("else if(parseNode.GetStringValue() is string stringValueValue)", result);
Assert.Contains("StringValue = stringValueValue", result);
Assert.Contains("parseNode.GetCollectionOfObjectValues<ComplexType2>(ComplexType2.CreateFromDiscriminatorValue)?.ToList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("parseNode.GetCollectionOfObjectValues<ComplexType2>(ComplexType2.CreateFromDiscriminatorValue)?.AsList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("ComplexType2Value = complexType2ValueValue", result);
Assert.Contains("return result", result);
AssertExtensions.Before("GetStringValue() is string stringValueValue", "GetCollectionOfObjectValues<ComplexType2>", result);
Expand Down Expand Up @@ -631,7 +631,7 @@ public void WritesModelFactoryBodyForIntersectionModels()
Assert.DoesNotContain("if(\"#kiota.complexType1\".Equals(mappingValue, StringComparison.OrdinalIgnoreCase))", result);
Assert.Contains("if(parseNode.GetStringValue() is string stringValueValue)", result);
Assert.Contains("StringValue = stringValueValue", result);
Assert.Contains("parseNode.GetCollectionOfObjectValues<ComplexType2>(ComplexType2.CreateFromDiscriminatorValue)?.ToList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("parseNode.GetCollectionOfObjectValues<ComplexType2>(ComplexType2.CreateFromDiscriminatorValue)?.AsList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("ComplexType2Value = complexType2ValueValue", result);
Assert.Contains("ComplexType1Value = new ComplexType1()", result);
Assert.Contains("return result", result);
Expand Down

0 comments on commit 8c26bde

Please sign in to comment.