diff --git a/CHANGELOG.md b/CHANGELOG.md index 96f37bf98b..c5a5c43cf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,10 +44,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixes a bug where CLI Generation does not handle path parameters of type "string" and format "date", "date-time", "time", etc. [#4615](https://github.com/microsoft/kiota/issues/4615) - Fixes a bug where request executors would be missing Untyped parameters in dotnet [#4692](https://github.com/microsoft/kiota/issues/4692) - Fixes a bug where indexers in include/exclude patters were not normalized if the indexer was the last segment without a slash at the end [#4715](https://github.com/microsoft/kiota/issues/4715) -- Fixes a bug where CLI generation doesnot handle parameters of type string array. [#4707](https://github.com/microsoft/kiota/issues/4707) +- Fixes a bug where CLI generation doesn't handle parameters of type string array. [#4707](https://github.com/microsoft/kiota/issues/4707) - Fixed a bug where models would not be created when a multipart content schema existed with no encoding [#4734](https://github.com/microsoft/kiota/issues/4734) - Types generated by Kiota are now referenced with their full name to avoid namespace ambiguities [#4475](https://github.com/microsoft/kiota/issues/4475) - Fixes a bug where warnings about discriminator not being inherited were generated [#4761](https://github.com/microsoft/kiota/issues/4761) +- Fix scalar member composed type serialization in PHP [#2827](https://github.com/microsoft/kiota/issues/2827) - Trims unused components from output openApi document when generating plugins [#4672](https://github.com/microsoft/kiota/issues/4672) ## [1.14.0] - 2024-05-02 diff --git a/src/Kiota.Builder/Refiners/PhpRefiner.cs b/src/Kiota.Builder/Refiners/PhpRefiner.cs index c861b2405e..95985de135 100644 --- a/src/Kiota.Builder/Refiners/PhpRefiner.cs +++ b/src/Kiota.Builder/Refiners/PhpRefiner.cs @@ -14,6 +14,7 @@ public class PhpRefiner : CommonLanguageRefiner private static readonly CodeUsingDeclarationNameComparer usingComparer = new(); public PhpRefiner(GenerationConfiguration configuration) : base(configuration) { } + private const string AbstractionsNamespaceName = @"Microsoft\Kiota\Abstractions"; public override Task Refine(CodeNamespace generatedCode, CancellationToken cancellationToken) { @@ -31,7 +32,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance Name = "BaseRequestBuilder", Declaration = new CodeType { - Name = "Microsoft\\Kiota\\Abstractions", + Name = $@"{AbstractionsNamespaceName}", IsExternal = true } }, AccessModifier.Public); @@ -45,7 +46,10 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance ConvertUnionTypesToWrapper(generatedCode, _configuration.UsesBackingStore, static s => s, - false); + false, + $@"{AbstractionsNamespaceName}\Serialization", + "ComposedTypeWrapper" + ); ReplaceReservedNames(generatedCode, new PhpReservedNamesProvider(), reservedWord => $"Escaped{reservedWord.ToFirstCharacterUpperCase()}", new HashSet { typeof(CodeEnumOption) }); AddQueryParameterFactoryMethod(generatedCode); AddPrimaryErrorMessage(generatedCode, "getPrimaryErrorMessage", () => new CodeType { IsExternal = true, IsNullable = false, Name = "string" }); @@ -71,7 +75,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance AddParentClassToErrorClasses( generatedCode, "ApiException", - "Microsoft\\Kiota\\Abstractions" + AbstractionsNamespaceName ); MoveClassesWithNamespaceNamesUnderNamespace(generatedCode); AddConstructorsForDefaultValues(generatedCode, true); @@ -106,7 +110,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance } ); cancellationToken.ThrowIfCancellationRequested(); - AddSerializationModulesImport(generatedCode, ["Microsoft\\Kiota\\Abstractions\\ApiClientBuilder"], null, '\\'); + AddSerializationModulesImport(generatedCode, [$@"{AbstractionsNamespaceName}\ApiClientBuilder"], null, '\\'); cancellationToken.ThrowIfCancellationRequested(); AddPropertiesAndMethodTypesImports(generatedCode, true, false, true); CorrectBackingStoreSetterParam(generatedCode); @@ -119,7 +123,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance Name = "BaseRequestConfiguration", Declaration = new CodeType { - Name = "Microsoft\\Kiota\\Abstractions", + Name = AbstractionsNamespaceName, IsExternal = true } }); @@ -143,7 +147,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance Name = "Date", Declaration = new CodeType { - Name = "Microsoft\\Kiota\\Abstractions\\Types", + Name = $@"{AbstractionsNamespaceName}\Types", IsExternal = true, }, }) @@ -154,7 +158,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance Name = "Time", Declaration = new CodeType { - Name = "Microsoft\\Kiota\\Abstractions\\Types", + Name = $@"{AbstractionsNamespaceName}\Types", IsExternal = true, }, }) @@ -184,34 +188,34 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance }; private static readonly AdditionalUsingEvaluator[] defaultUsingEvaluators = { new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.RequestAdapter), - "Microsoft\\Kiota\\Abstractions", "RequestAdapter"), + AbstractionsNamespaceName, "RequestAdapter"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestGenerator), - "Microsoft\\Kiota\\Abstractions", "HttpMethod", "RequestInformation"), + AbstractionsNamespaceName, "HttpMethod", "RequestInformation"), new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model) && @class.Properties.Any(static y => y.IsOfKind(CodePropertyKind.AdditionalData)), - "Microsoft\\Kiota\\Abstractions\\Serialization", "AdditionalDataHolder"), + $@"{AbstractionsNamespaceName}\Serialization", "AdditionalDataHolder"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Serializer), - "Microsoft\\Kiota\\Abstractions\\Serialization", "SerializationWriter"), + $@"{AbstractionsNamespaceName}\Serialization", "SerializationWriter"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Deserializer), - "Microsoft\\Kiota\\Abstractions\\Serialization", "ParseNode"), + $@"{AbstractionsNamespaceName}\Serialization", "ParseNode"), new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model), - "Microsoft\\Kiota\\Abstractions\\Serialization", "Parsable"), + $@"{AbstractionsNamespaceName}\Serialization", "Parsable"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.ClientConstructor) && method.Parameters.Any(y => y.IsOfKind(CodeParameterKind.BackingStore)), - "Microsoft\\Kiota\\Abstractions\\Store", "BackingStoreFactory", "BackingStoreFactorySingleton"), + $@"{AbstractionsNamespaceName}\Store", "BackingStoreFactory", "BackingStoreFactorySingleton"), new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.BackingStore), - "Microsoft\\Kiota\\Abstractions\\Store", "BackingStore", "BackedModel", "BackingStoreFactorySingleton" ), + $@"{AbstractionsNamespaceName}\Store", "BackingStore", "BackedModel", "BackingStoreFactorySingleton" ), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestExecutor), "Http\\Promise", "Promise"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestExecutor), "", "Exception"), - new (static x => x is CodeEnum, "Microsoft\\Kiota\\Abstractions\\", "Enum"), + new (static x => x is CodeEnum, AbstractionsNamespaceName, "Enum"), new(static x => x is CodeProperty {Type.Name: {}} property && property.Type.Name.Equals("DateTime", StringComparison.OrdinalIgnoreCase), "", "\\DateTime"), new(static x => x is CodeProperty {Type.Name: {}} property && property.Type.Name.Equals("DateTimeOffset", StringComparison.OrdinalIgnoreCase), "", "\\DateTime"), - new(static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.ClientConstructor), "Microsoft\\Kiota\\Abstractions", "ApiClientBuilder"), - new(static x => x is CodeProperty property && property.IsOfKind(CodePropertyKind.QueryParameter) && !string.IsNullOrEmpty(property.SerializationName), "Microsoft\\Kiota\\Abstractions", "QueryParameter"), - new(static x => x is CodeClass codeClass && codeClass.IsOfKind(CodeClassKind.RequestConfiguration), "Microsoft\\Kiota\\Abstractions", "RequestOption"), + new(static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.ClientConstructor), AbstractionsNamespaceName, "ApiClientBuilder"), + new(static x => x is CodeProperty property && property.IsOfKind(CodePropertyKind.QueryParameter) && !string.IsNullOrEmpty(property.SerializationName), AbstractionsNamespaceName, "QueryParameter"), + new(static x => x is CodeClass codeClass && codeClass.IsOfKind(CodeClassKind.RequestConfiguration), AbstractionsNamespaceName, "RequestOption"), new (static x => x is CodeClass { OriginalComposedType: CodeIntersectionType intersectionType } && intersectionType.Types.Any(static y => !y.IsExternal), - "Microsoft\\Kiota\\Abstractions\\Serialization", "ParseNodeHelper"), + $@"{AbstractionsNamespaceName}\Serialization", "ParseNodeHelper"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestExecutor, CodeMethodKind.RequestGenerator) && method.Parameters.Any(static y => y.IsOfKind(CodeParameterKind.RequestBody) && y.Type.Name.Equals(MultipartBodyClassName, StringComparison.OrdinalIgnoreCase)), - @"Microsoft\Kiota\Abstractions", MultipartBodyClassName) + AbstractionsNamespaceName, MultipartBodyClassName) }; private const string MultipartBodyClassName = "MultiPartBody"; @@ -339,7 +343,7 @@ private void AddCollectionValidationUtilImportToModels(CodeElement codeElement) { if (codeElement is CodeClass codeClass && codeClass.Kind == CodeClassKind.Model) { - var typeUtilsUsing = new CodeUsing { Name = "TypeUtils", Declaration = new CodeType { Name = "Microsoft\\Kiota\\Abstractions\\Types", IsExternal = true } }; + var typeUtilsUsing = new CodeUsing { Name = "TypeUtils", Declaration = new CodeType { Name = $@"{AbstractionsNamespaceName}\Types", IsExternal = true } }; if (codeClass.Properties.Any(x => x.Kind == CodePropertyKind.Custom && x.Type is CodeType codeType diff --git a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs index 4a96bd3eec..8b8c870165 100644 --- a/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs @@ -855,7 +855,7 @@ private void WriteModelFactoryMethodBody(CodeMethod codeElement, CodeClass paren { if (parentClass.DiscriminatorInformation.ShouldWriteDiscriminatorForUnionType || parentClass.DiscriminatorInformation.ShouldWriteDiscriminatorForIntersectionType) writer.WriteLine($"{ResultVarName} = new {parentClass.Name.ToFirstCharacterUpperCase()}();"); - var writeDiscriminatorValueRead = parentClass.DiscriminatorInformation.ShouldWriteParseNodeCheck && !parentClass.DiscriminatorInformation.ShouldWriteDiscriminatorForIntersectionType; + var writeDiscriminatorValueRead = parentClass.DiscriminatorInformation is { ShouldWriteParseNodeCheck: true, ShouldWriteDiscriminatorForIntersectionType: false, HasBasicDiscriminatorInformation: true }; if (writeDiscriminatorValueRead && codeElement.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParameter) @@ -868,7 +868,7 @@ private void WriteModelFactoryMethodBody(CodeMethod codeElement, CodeClass paren if (parentClass.DiscriminatorInformation.ShouldWriteDiscriminatorForInheritedType) WriteFactoryMethodBodyForInheritedModel(parentClass.DiscriminatorInformation.DiscriminatorMappings, writer, codeElement); - else if (parentClass.DiscriminatorInformation.ShouldWriteDiscriminatorForUnionType && parentClass.DiscriminatorInformation.HasBasicDiscriminatorInformation) + else if (parentClass.DiscriminatorInformation is { ShouldWriteDiscriminatorForUnionType: true, HasBasicDiscriminatorInformation: true }) WriteFactoryMethodBodyForUnionModelForDiscriminatedTypes(codeElement, parentClass, writer); else if (parentClass.DiscriminatorInformation.ShouldWriteDiscriminatorForIntersectionType) WriteFactoryMethodBodyForIntersectionModel(codeElement, parentClass, writer);