Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- fixes extraneous indexer for CLI #3091

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Added backing store support for Python. [#2858](https://github.com/microsoft/kiota/issues/2858)

### Changed


## [1.5.1] - 2023-08-08

### Added

- Added backing store support for Python. [#2858](https://github.com/microsoft/kiota/issues/2858)
- Added support for indexer parameter description. [#2978](https://github.com/microsoft/kiota/issues/2978)

### Changed

- Renamed the Shell language to CLI. [#3023](https://github.com/microsoft/kiota/issues/3023)
- Fixed a bug where and extraneous indexer would be generated for CLI. [#3088](https://github.com/microsoft/kiota/issues/3088)
- Fixed a bug where type specific indexers would fail to build in Go. [#3090](https://github.com/microsoft/kiota/issues/3090)

## [1.5.0] - 2023-08-04

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 @@ -16,7 +16,7 @@
<Title>Microsoft.OpenApi.Kiota.Builder</Title>
<PackageId>Microsoft.OpenApi.Kiota.Builder</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionPrefix>1.5.1</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
Expand Down
16 changes: 14 additions & 2 deletions src/Kiota.Builder/Refiners/CliRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
IsExternal = true
}
});
RemoveBackwardCompatibleIndexers(generatedCode);
RemoveRequestConfigurationClasses(generatedCode,
new CodeUsing
{
Expand Down Expand Up @@ -95,6 +96,17 @@
CreateCommandBuilders(generatedCode);
}, cancellationToken);
}
private static void RemoveBackwardCompatibleIndexers(CodeElement currentElement)
{//TODO remove for v2

Check warning on line 100 in src/Kiota.Builder/Refiners/CliRefiner.cs

View workflow job for this annotation

GitHub Actions / Build

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
if (currentElement is CodeClass currentClass && currentClass.IsOfKind(CodeClassKind.RequestBuilder) && currentClass.Indexer is CodeIndexer specificIndexer &&
!specificIndexer.IndexParameter.Type.Name.Equals("string", StringComparison.OrdinalIgnoreCase) && !(specificIndexer.Deprecation?.IsDeprecated ?? false) &&
currentClass.GetChildElements(true).OfType<CodeIndexer>().FirstOrDefault(i => i != specificIndexer && i.IndexParameter.Type.Name.Equals("string", StringComparison.OrdinalIgnoreCase) && (i.Deprecation?.IsDeprecated ?? false)) is CodeIndexer backwardCompatibleIndexer)
{
currentClass.RemoveChildElement(backwardCompatibleIndexer);
}

CrawlTree(currentElement, RemoveBackwardCompatibleIndexers);
}

private static void RenameDuplicateIndexerNavProperties(CodeElement currentElement)
{
Expand Down Expand Up @@ -126,8 +138,8 @@
if (matchInIdx.Type.AllTypes.First().TypeDefinition is CodeClass ccIdx
&& propsInClass[matchInIdx.Name].Type.AllTypes.First().TypeDefinition is CodeClass ccClass)
{
// Check for execuable command matches
// This list is usually small. Upto a max of ~9 for each HTTP method
// Check for executable command matches
// This list is usually small. Up to a max of ~9 for each HTTP method
// In reality, most instances would have 1 - 3 methods
var lookup = ccClass.UnorderedMethods
.Where(static m => m.IsOfKind(CodeMethodKind.RequestExecutor))
Expand Down
3 changes: 3 additions & 0 deletions src/Kiota.Builder/Refiners/GoRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ private static void AddErrorImportForEnums(CodeElement currentElement)
method.Parameters.Any(x => x.IsOfKind(CodeParameterKind.Path) &&
!typeToSkipStrConv.Contains(x.Type.Name)),
"strconv", "FormatBool"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) &&
method.OriginalIndexer is CodeIndexer indexer && !indexer.IndexParameter.Type.Name.Equals("string", StringComparison.OrdinalIgnoreCase),
"strconv", "FormatInt"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Serializer),
"github.com/microsoft/kiota-abstractions-go/serialization", "SerializationWriter"),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Deserializer, CodeMethodKind.Factory),
Expand Down
16 changes: 11 additions & 5 deletions src/Kiota.Builder/Writers/Go/GoConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,21 @@ internal void AddParametersAssignment(LanguageWriter writer, CodeTypeBase? pathP
foreach (var p in parameters)
{
var isStringStruct = !p.Item1.IsNullable && p.Item1.Name.Equals("string", StringComparison.OrdinalIgnoreCase);
var defaultValue = isStringStruct ? "\"\"" : "nil";
var pointerDereference = isStringStruct ? string.Empty : "*";
writer.StartBlock($"if {p.Item3} != {defaultValue} {{");
var (defaultValue, pointerDereference, shouldCheckNullability) = (isStringStruct, p.Item1.IsNullable) switch
{
(true, _) => ("\"\"", string.Empty, true),
(_, true) => ("nil", "*", true),
(_, false) => (string.Empty, string.Empty, false),
};
if (shouldCheckNullability)
writer.StartBlock($"if {p.Item3} != {defaultValue} {{");
writer.WriteLine($"{pathParametersTarget}[\"{p.Item2}\"] = {GetValueStringConversion(p.Item1.Name, pointerDereference + p.Item3)}");
writer.CloseBlock();
if (shouldCheckNullability)
writer.CloseBlock();
}
}
#pragma warning restore CA1822 // Method should be static
private const string StrConvHash = "i53ac87e8cb3cc9276228f74d38694a208cacb99bb8ceb705eeae99fb88d4d274";
internal const string StrConvHash = "i53ac87e8cb3cc9276228f74d38694a208cacb99bb8ceb705eeae99fb88d4d274";
private const string TimeFormatHash = "i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e";
private static string GetValueStringConversion(string typeName, string reference)
{
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/kiota.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Title>Microsoft.OpenApi.Kiota</Title>
<PackageId>Microsoft.OpenApi.Kiota</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionPrefix>1.5.1</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
Expand Down
Loading