Skip to content

Commit

Permalink
Merge branch 'main' into task/extension/show-plugins-and-clients-in-p…
Browse files Browse the repository at this point in the history
…anel
  • Loading branch information
thewahome authored Nov 15, 2024
2 parents 1aadd1f + 84255ef commit 7fbaeea
Show file tree
Hide file tree
Showing 22 changed files with 162 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/01-kiota-bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ body:
id: logs
attributes:
label: Debug output
description: Please copy and paste the output when using the `--debug`` flag. This will be automatically formatted into code, so no need for backticks.
description: Please copy and paste the output when using the `--ll debug`` flag. This will be automatically formatted into code, so no need for backticks.
value: |
<details><summary>Click to expand log</summary>
```
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed python generation in scenarios with opening/closing tags for code comments. [#5636](https://github.com/microsoft/kiota/issues/5636)
- Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637)
- Fix anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353)
- Fixed invalid code in Php caused by "*/*/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635)

## [1.20.0] - 2024-11-07

Expand Down
14 changes: 3 additions & 11 deletions it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@
"Language": "typescript",
"Rationale": "https://github.com/microsoft/kiota/issues/5634"
},
{
"Language": "php",
"Rationale": "https://github.com/microsoft/kiota/issues/5635"
},
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/1816"
},
{
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/5636"
"Language": "php",
"Rationale": "https://github.com/microsoft/kiota/issues/5779"
}
],
"ExcludePatterns": [
Expand Down Expand Up @@ -247,10 +243,6 @@
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/2484"
},
{
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/5744"
}
]
},
Expand All @@ -267,4 +259,4 @@
"Suppressions": [],
"IdempotencySuppressions": []
}
}
}
14 changes: 7 additions & 7 deletions it/csharp/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.14.0" />
<PackageReference Include="Microsoft.kiota.Serialization.Multipart" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.15.2" />
<PackageReference Include="Microsoft.kiota.Serialization.Multipart" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.15.2" />

<Compile Remove="basic\**" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ urllib3==2.2.3 ; python_version >= '3.7'

wrapt==1.15.0 ; python_version < '3.11'

yapf==0.40.2
yapf==0.43.0

zipp==3.21.0 ; python_version >= '3.7'

aiohttp==3.10.10 ; python_version >= '3.6'
aiohttp==3.11.2 ; python_version >= '3.6'

aiosignal==1.3.1 ; python_version >= '3.7'

Expand Down
12 changes: 6 additions & 6 deletions src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
<PackageReference Include="AsyncKeyedLock" Version="7.1.3" />
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.14.0" />
<PackageReference Include="Microsoft.kiota.Serialization.Multipart" Version="1.14.0" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.15.2" />
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.15.2" />
<PackageReference Include="Microsoft.kiota.Serialization.Multipart" Version="1.15.2" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.22" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.5-preview" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.22" />
Expand Down
16 changes: 9 additions & 7 deletions src/Kiota.Builder/Refiners/CliRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,17 @@ private static CodeType CreateCommandType(CodeTypeBase.CodeTypeCollectionKind co
}

private static readonly AdditionalUsingEvaluator[] additionalUsingEvaluators =
{
new(x => x is CodeClass { Kind: CodeClassKind.RequestBuilder },
[
new(static x => x is CodeClass { Kind: CodeClassKind.RequestBuilder },
"System.CommandLine", "Command", "RootCommand", "IConsole"),
new(x => x is CodeClass { Kind: CodeClassKind.RequestBuilder },
new(static x => x is CodeClass { Kind: CodeClassKind.RequestBuilder },
"Microsoft.Kiota.Cli.Commons.IO", "IOutputFormatter", "IOutputFormatterFactory", "FormatterType",
"PageLinkData", "IPagingService"),
new(x => x is CodeClass { Kind: CodeClassKind.RequestBuilder },
new(static x => x is CodeClass { Kind: CodeClassKind.RequestBuilder },
"System.Text", "Encoding"),
new(x => x is CodeMethod { Kind: CodeMethodKind.RequestExecutor or CodeMethodKind.RequestGenerator },
"Microsoft.Kiota.Cli.Commons.Extensions", "GetRequestAdapter")
};
new(static x => x is CodeClass { Kind: CodeClassKind.RequestBuilder },
"System.Linq", "Enumerable"),
new(static x => x is CodeMethod { Kind: CodeMethodKind.RequestExecutor or CodeMethodKind.RequestGenerator },
"Microsoft.Kiota.Cli.Commons.Extensions", "GetRequestAdapter"),
];
}
25 changes: 19 additions & 6 deletions src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,15 +1475,28 @@ protected static void RemoveRequestConfigurationClassesCommonProperties(CodeElem

CrawlTree(currentElement, x => RemoveRequestConfigurationClassesCommonProperties(x, baseTypeUsing));
}
protected static void RemoveUntypedNodePropertyValues(CodeElement currentElement)
protected static void RemoveUntypedNodeTypeValues(CodeElement currentElement)
{
if (currentElement is CodeProperty currentProperty
&& currentElement.Parent is CodeClass parentClass
&& currentProperty.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))
switch (currentElement)
{
parentClass.RemoveChildElement(currentProperty);
case CodeProperty currentProperty when currentElement.Parent is CodeClass parentClass && currentProperty.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase):
parentClass.RemoveChildElement(currentProperty);
break;
case CodeMethod currentMethod when currentMethod.IsOfKind(CodeMethodKind.RequestExecutor):
if (currentMethod.ReturnType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))
{
currentMethod.ReturnType = new CodeType { Name = "binary", IsExternal = true };
}
if (currentMethod.Parameters.Where(x => x.Kind is CodeParameterKind.RequestBody && x.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)).ToList() is { Count: > 0 } parameters)
{
foreach (var parameter in parameters)
{
parameter.Type = new CodeType { Name = "binary", IsExternal = true };
}
}
break;
}
CrawlTree(currentElement, RemoveUntypedNodePropertyValues);
CrawlTree(currentElement, RemoveUntypedNodeTypeValues);
}
protected static void RemoveRequestConfigurationClasses(CodeElement currentElement, CodeUsing? configurationParameterTypeUsing = null, CodeType? defaultValueForGenericTypeParam = null, bool keepRequestConfigurationClass = false, bool addDeprecation = false, CodeUsing? usingForDefaultGenericParameter = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/PhpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
AddParsableImplementsForModelClasses(generatedCode, "Parsable");
AddRequestConfigurationConstructors(generatedCode);
AddDefaultImports(generatedCode, defaultUsingEvaluators);
RemoveUntypedNodePropertyValues(generatedCode);
RemoveUntypedNodeTypeValues(generatedCode);
AddCollectionValidationUtilImportToModels(generatedCode);
cancellationToken.ThrowIfCancellationRequested();
AddGetterAndSetterMethods(generatedCode,
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/PythonRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
);
CorrectCommonNames(generatedCode);
RemoveMethodByKind(generatedCode, CodeMethodKind.RawUrlConstructor);
RemoveUntypedNodePropertyValues(generatedCode);
RemoveUntypedNodeTypeValues(generatedCode);
DisableActionOf(generatedCode,
CodeParameterKind.RequestConfiguration);
MoveRequestBuilderPropertiesToBaseType(generatedCode,
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/RubyRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
cancellationToken.ThrowIfCancellationRequested();
AddParsableImplementsForModelClasses(generatedCode, "MicrosoftKiotaAbstractions::Parsable");
AddDefaultImports(generatedCode, defaultUsingEvaluators);
RemoveUntypedNodePropertyValues(generatedCode);
RemoveUntypedNodeTypeValues(generatedCode);
CorrectCoreType(generatedCode, CorrectMethodType, CorrectPropertyType, CorrectImplements);
cancellationToken.ThrowIfCancellationRequested();
ReplacePropertyNames(generatedCode,
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/SwiftRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public override Task RefineAsync(CodeNamespace generatedCode, CancellationToken
true,
false,
true);
RemoveUntypedNodeTypeValues(generatedCode);
AddDefaultImports(
generatedCode,
defaultUsingEvaluators);
RemoveUntypedNodePropertyValues(generatedCode);
cancellationToken.ThrowIfCancellationRequested();
CorrectCoreType(
generatedCode,
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/CLI/CliCodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ protected virtual void WriteCommandHandlerBody(CodeMethod codeElement, CodeClass
if (requestBodyParamType?.TypeDefinition is CodeClass)
{
writer.WriteLine($"using var stream = new MemoryStream(Encoding.UTF8.GetBytes({requestBodyParam.Name}));");
writer.WriteLine($"var parseNode = ParseNodeFactoryRegistry.DefaultInstance.GetRootParseNode(\"{generatorMethod.RequestBodyContentType.SanitizeDoubleQuote()}\", stream);");
writer.WriteLine($"var parseNode = await ParseNodeFactoryRegistry.DefaultInstance.GetRootParseNodeAsync(\"{generatorMethod.RequestBodyContentType.SanitizeDoubleQuote()}\", stream, {CancellationTokenParamName});");

var typeString = conventions.GetTypeString(requestBodyParamType, requestBodyParam, false);

Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write
writer.IncreaseIndent();
foreach (var enumProperty in enumProperties)
{
writer.WriteLine($"public const {GetEnumValueName(enumProperty.Name)} = '{enumProperty.WireName}';");
writer.WriteLine($"public const {GetEnumValueName(enumProperty.Name)} = \"{enumProperty.WireName}\";");
}
}
[GeneratedRegex(@"([A-Z]{1})", RegexOptions.Singleline, 500)]
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Php/PhpConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private string GetCollectionDocString(CodeParameter codeParameter)
return codeParameter.Optional ? $"{doc}|null" : doc;
}

internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase);
internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase).Replace("*/", string.Empty, StringComparison.OrdinalIgnoreCase);
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
Expand Down
28 changes: 19 additions & 9 deletions src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,15 @@ private void WriteDirectAccessProperties(CodeClass parentClass, LanguageWriter w
{
var returnType = conventions.GetTypeString(propWithDefault.Type, propWithDefault, true, writer);
var defaultValue = propWithDefault.DefaultValue;
if (propWithDefault.Type is CodeType propertyType && propertyType.TypeDefinition is CodeEnum enumDefinition)
switch (propWithDefault.Type)
{
_codeUsingWriter.WriteDeferredImport(parentClass, enumDefinition.Name, writer);
defaultValue = $"{enumDefinition.Name}({defaultValue})";
case CodeType { TypeDefinition: CodeEnum enumDefinition }:
_codeUsingWriter.WriteDeferredImport(parentClass, enumDefinition.Name, writer);
defaultValue = $"{enumDefinition.Name}({defaultValue})";
break;
case CodeType propType when propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase):
defaultValue = defaultValue.TrimQuotes().ToFirstCharacterUpperCase();// python booleans start in uppercase
break;
}
conventions.WriteInLineDescription(propWithDefault, writer);
if (parentClass.IsOfKind(CodeClassKind.Model))
Expand All @@ -412,10 +417,15 @@ private void WriteSetterAccessProperties(CodeClass parentClass, LanguageWriter w
.ThenBy(static x => x.Name))
{
var defaultValue = propWithDefault.DefaultValue;
if (propWithDefault.Type is CodeType propertyType && propertyType.TypeDefinition is CodeEnum enumDefinition)
switch (propWithDefault.Type)
{
_codeUsingWriter.WriteDeferredImport(parentClass, enumDefinition.Name, writer);
defaultValue = $"{enumDefinition.Name}({defaultValue})";
case CodeType { TypeDefinition: CodeEnum enumDefinition }:
_codeUsingWriter.WriteDeferredImport(parentClass, enumDefinition.Name, writer);
defaultValue = $"{enumDefinition.Name}({defaultValue})";
break;
case CodeType propType when propType.Name.Equals("boolean", StringComparison.OrdinalIgnoreCase):
defaultValue = defaultValue.TrimQuotes().ToFirstCharacterUpperCase();// python booleans start in uppercase
break;
}
var returnType = conventions.GetTypeString(propWithDefault.Type, propWithDefault, true, writer);
conventions.WriteInLineDescription(propWithDefault, writer);
Expand Down Expand Up @@ -583,7 +593,7 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
var isStream = conventions.StreamTypeName.Equals(returnType, StringComparison.OrdinalIgnoreCase);
var returnTypeWithoutCollectionSymbol = GetReturnTypeWithoutCollectionSymbol(codeElement, returnType);
var genericTypeForSendMethod = GetSendRequestMethodName(isVoid, isStream, codeElement.ReturnType.IsCollection, returnTypeWithoutCollectionSymbol, isEnum);
var newFactoryParameter = GetTypeFactory(isVoid, isStream, isEnum, returnTypeWithoutCollectionSymbol);
var newFactoryParameter = GetTypeFactory(isVoid, isStream, isEnum, returnTypeWithoutCollectionSymbol, codeElement.ReturnType.IsCollection);
var errorMappingVarName = NoneKeyword;
if (codeElement.ErrorMappings.Any())
{
Expand Down Expand Up @@ -809,11 +819,11 @@ private string GetSerializationMethodName(CodeTypeBase propType)
_ => "write_object_value",
};
}
internal string GetTypeFactory(bool isVoid, bool isStream, bool isEnum, string returnType)
internal string GetTypeFactory(bool isVoid, bool isStream, bool isEnum, string returnType, bool isCollection)
{
if (isVoid) return string.Empty;
if (isStream || isEnum) return $" \"{returnType}\",";
if (conventions.IsPrimitiveType(returnType)) return $" {returnType},";
if (conventions.IsPrimitiveType(returnType)) return isCollection ? $" {returnType}," : $" \"{returnType}\",";
return $" {returnType},";
}
private string GetSendRequestMethodName(bool isVoid, bool isStream, bool isCollection, string returnType,
Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/Writers/Python/PythonConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override string GetTypeString(CodeTypeBase code, CodeElement targetElemen
throw new InvalidOperationException($"type of type {code.GetType()} is unknown");
}
#pragma warning restore CA1822 // Method should be static
internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase);
internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase).Replace("\"\"\"", "\\\"\\\"\\\"", StringComparison.OrdinalIgnoreCase);
public override string TranslateType(CodeType type)
{
ArgumentNullException.ThrowIfNull(type);
Expand Down Expand Up @@ -130,7 +130,7 @@ public bool IsPrimitiveType(string typeName)
{
return typeName switch
{
"int" or "float" or "str" or "bool" or "None" => true,
"int" or "float" or "str" or "bool" or "None" or "datetime.datetime" or "datetime.timedelta" or "datetime.date" or "datetime.time" => true,
_ => false,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.SDK" Version="17.11.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading

0 comments on commit 7fbaeea

Please sign in to comment.