Skip to content

Commit

Permalink
Merge pull request #1831 from microsoft/bugfix/parse-node-type
Browse files Browse the repository at this point in the history
bugfix/parse node type
  • Loading branch information
baywet authored Sep 9, 2022
2 parents e41e482 + 9546430 commit 10db5be
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Changed

## [0.5.1] - 2022-09-09

### Added

- Exempts read only properties from being serialized and sent to the service. [#1828](https://github.com/microsoft/kiota/issues/1828)

### Changed

- Fixed a regression where parse node parameter type for factories would be incorrect in Go, Ruby, Swift, Java and TypeScript.

## [0.5.0] - 2022-09-08

### Added
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 @@ -12,7 +12,7 @@
<Title>Microsoft.OpenApi.Kiota.Builder</Title>
<PackageId>Microsoft.OpenApi.Kiota.Builder</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<Version>0.5.0-preview</Version>
<Version>0.5.1-preview</Version>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
</PackageReleaseNotes>
Expand Down
10 changes: 7 additions & 3 deletions src/Kiota.Builder/Refiners/GoRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,16 @@ private static void CorrectMethodType(CodeMethod currentMethod) {
if(rawUrlParam != null)
rawUrlParam.Type.IsNullable = false;
currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.RequestAdapter))
.Where(x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase))
.Where(static x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase))
.ToList()
.ForEach(x => x.Type.Name = x.Type.Name[1..]); // removing the "I"
.ForEach(static x => x.Type.Name = x.Type.Name[1..]); // removing the "I"
} else if(currentMethod.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility, CodeMethodKind.RequestBuilderWithParameters, CodeMethodKind.RequestBuilderBackwardCompatibility, CodeMethodKind.Factory)) {
currentMethod.ReturnType.IsNullable = true;
currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.ParseNode)).ToList().ForEach(x => x.Type.IsNullable = false);
if (currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam) {
parseNodeParam.Type.IsNullable = false;
parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..];
}

if(currentMethod.IsOfKind(CodeMethodKind.Factory))
currentMethod.ReturnType = new CodeType { Name = "Parsable", IsNullable = false, IsExternal = true };
}
Expand Down
3 changes: 2 additions & 1 deletion src/Kiota.Builder/Refiners/JavaRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ private static void CorrectMethodType(CodeMethod currentMethod) {
var urlTplParams = currentMethod.Parameters.FirstOrDefault(x => x.IsOfKind(CodeParameterKind.PathParameters));
if(urlTplParams != null)
urlTplParams.Type.Name = "HashMap<String, Object>";
}
} else if(currentMethod.IsOfKind(CodeMethodKind.Factory) && currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam)
parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..];
CorrectDateTypes(currentMethod.Parent as CodeClass, DateTypesReplacements, currentMethod.Parameters
.Select(x => x.Type)
.Union(new CodeTypeBase[] { currentMethod.ReturnType})
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 @@ -187,7 +187,7 @@ private static void CorrectMethodType(CodeMethod method)
method.ReturnType.Name = "array";
}
CorrectDateTypes(method.Parent as CodeClass, DateTypesReplacements, method.Parameters
.Select(x => x.Type)
.Select(static x => x.Type)
.Union(new CodeTypeBase[] { method.ReturnType})
.ToArray());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/Refiners/PythonRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ private static void CorrectMethodType(CodeMethod currentMethod) {
currentMethod.ReturnType.Name = $"Dict[str, Callable[[ParseNode], None]]";
else if(currentMethod.IsOfKind(CodeMethodKind.ClientConstructor, CodeMethodKind.Constructor, CodeMethodKind.Factory)) {
currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.RequestAdapter, CodeParameterKind.BackingStore, CodeParameterKind.ParseNode))
.Where(x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase))
.Where(static x => x.Type.Name.StartsWith("I", StringComparison.InvariantCultureIgnoreCase))
.ToList()
.ForEach(x => x.Type.Name = x.Type.Name[1..]); // removing the "I"
.ForEach(static x => x.Type.Name = x.Type.Name[1..]); // removing the "I"
var urlTplParams = currentMethod.Parameters.FirstOrDefault(x => x.IsOfKind(CodeParameterKind.PathParameters));
if(urlTplParams != null &&
urlTplParams.Type is CodeType originalType) {
Expand Down
2 changes: 2 additions & 0 deletions src/Kiota.Builder/Refiners/RubyRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public override void Refine(CodeNamespace generatedCode)
new [] { "microsoft_kiota_abstractions.ParseNodeFactoryRegistry" });
}
private static void CorrectMethodType(CodeMethod currentMethod) {
if(currentMethod.IsOfKind(CodeMethodKind.Factory) && currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam)
parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..];
CorrectDateTypes(currentMethod.Parent as CodeClass, DateTypesReplacements, currentMethod.Parameters
.Select(x => x.Type)
.Union(new CodeTypeBase[] { currentMethod.ReturnType})
Expand Down
5 changes: 4 additions & 1 deletion src/Kiota.Builder/Refiners/SwiftRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ private static void CorrectMethodType(CodeMethod currentMethod) {
.ForEach(x => x.Type.Name = x.Type.Name[1..]); // removing the "I"
} else if(currentMethod.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility, CodeMethodKind.RequestBuilderWithParameters, CodeMethodKind.RequestBuilderBackwardCompatibility, CodeMethodKind.Factory)) {
currentMethod.ReturnType.IsNullable = true;
currentMethod.Parameters.Where(x => x.IsOfKind(CodeParameterKind.ParseNode)).ToList().ForEach(x => x.Type.IsNullable = false);
if (currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam) {
parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..];
parseNodeParam.Type.IsNullable = false;
}
if(currentMethod.IsOfKind(CodeMethodKind.Factory))
currentMethod.ReturnType = new CodeType { Name = "Parsable", IsNullable = false, IsExternal = true };
}
Expand Down
3 changes: 2 additions & 1 deletion src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ private static void CorrectMethodType(CodeMethod currentMethod) {
});
urlTplParams.Type = unionType;
}
}
} else if(currentMethod.IsOfKind(CodeMethodKind.Factory) && currentMethod.Parameters.OfKind(CodeParameterKind.ParseNode) is CodeParameter parseNodeParam)
parseNodeParam.Type.Name = parseNodeParam.Type.Name[1..];
CorrectDateTypes(currentMethod.Parent as CodeClass, DateTypesReplacements, currentMethod.Parameters
.Select(x => x.Type)
.Union(new CodeTypeBase[] { currentMethod.ReturnType})
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/kiota.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Title>Microsoft.OpenApi.Kiota</Title>
<PackageId>Microsoft.OpenApi.Kiota</PackageId>
<PackageOutputPath>./nupkg</PackageOutputPath>
<Version>0.5.0-preview</Version>
<Version>0.5.1-preview</Version>
<PackageReleaseNotes>
https://github.com/microsoft/kiota/releases
</PackageReleaseNotes>
Expand Down

0 comments on commit 10db5be

Please sign in to comment.