зеркало из https://github.com/microsoft/kiota.git
Merge pull request #5327 from microsoft/fix/missing-untype-node-imports
fix: missing untyped node imports
This commit is contained in:
Коммит
e3f3d2b11d
|
@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Fixed shorthand for refresh option in workspace experience. [#5240](https://github.com/microsoft/kiota/issues/5240)
|
||||
- Fixed a bug where untyped node imports would be missing CSharp/Go/TypeScript/Java. [#5326](https://github.com/microsoft/kiota/issues/5326)
|
||||
- Fixed missing type options in help for plugin commands. [#5230](https://github.com/microsoft/kiota/issues/5230)
|
||||
- Removed OpenAI plugins generation since the service does not support them anymore.
|
||||
- Fixed a bug where the error message would not be deserialized if the property name matched a reserved property. [#5311](https://github.com/microsoft/kiota/issues/5311)
|
||||
|
|
|
@ -185,6 +185,9 @@ public class CSharpRefiner : CommonLanguageRefiner, ILanguageRefiner
|
|||
AbstractionsNamespaceName, "RequestHeaders"),
|
||||
new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.Custom) && prop.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase),
|
||||
SerializationNamespaceName, KiotaBuilder.UntypedNodeName),
|
||||
new (static x => x is CodeMethod @method && @method.IsOfKind(CodeMethodKind.RequestExecutor) && (method.ReturnType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase) ||
|
||||
method.Parameters.Any(x => x.Kind is CodeParameterKind.RequestBody && x.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))),
|
||||
SerializationNamespaceName, KiotaBuilder.UntypedNodeName),
|
||||
new (static x => x is CodeEnum prop && prop.Options.Any(x => x.IsNameEscaped),
|
||||
"System.Runtime.Serialization", "EnumMemberAttribute"),
|
||||
new (static x => x is IDeprecableElement element && element.Deprecation is not null && element.Deprecation.IsDeprecated,
|
||||
|
|
|
@ -598,6 +598,9 @@ public class GoRefiner : CommonLanguageRefiner
|
|||
AbstractionsNamespaceName, MultipartBodyClassName),
|
||||
new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.Custom) && prop.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase),
|
||||
SerializationNamespaceName, KiotaBuilder.UntypedNodeName),
|
||||
new (static x => x is CodeMethod @method && @method.IsOfKind(CodeMethodKind.RequestExecutor) && (method.ReturnType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase) ||
|
||||
method.Parameters.Any(x => x.Kind is CodeParameterKind.RequestBody && x.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))),
|
||||
SerializationNamespaceName, KiotaBuilder.UntypedNodeName),
|
||||
new (static x => x is CodeEnum @enum && @enum.Flags,"", "math"),
|
||||
};
|
||||
private const string MultipartBodyClassName = "MultipartBody";
|
||||
|
|
|
@ -264,7 +264,10 @@ public class JavaRefiner : CommonLanguageRefiner, ILanguageRefiner
|
|||
AbstractionsNamespaceName, "QueryParameters"),
|
||||
new (static x => x is CodeClass @class && @class.OriginalComposedType is CodeIntersectionType intersectionType && intersectionType.Types.Any(static y => !y.IsExternal),
|
||||
SerializationNamespaceName, "ParseNodeHelper"),
|
||||
new (static x => (x is CodeMethod @method && @method.IsOfKind(CodeMethodKind.Getter, CodeMethodKind.Setter) && @method.AccessedProperty != null && (@method.AccessedProperty.IsOfKind(CodePropertyKind.Custom) && @method.AccessedProperty.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase) )) ,
|
||||
new (static x => x is CodeMethod @method && @method.IsOfKind(CodeMethodKind.Getter, CodeMethodKind.Setter) && @method.AccessedProperty != null && @method.AccessedProperty.IsOfKind(CodePropertyKind.Custom) && @method.AccessedProperty.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase),
|
||||
SerializationNamespaceName, KiotaBuilder.UntypedNodeName),
|
||||
new (static x => x is CodeMethod @method && @method.IsOfKind(CodeMethodKind.RequestExecutor) && (method.ReturnType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase) ||
|
||||
method.Parameters.Any(x => x.Kind is CodeParameterKind.RequestBody && x.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))),
|
||||
SerializationNamespaceName, KiotaBuilder.UntypedNodeName),
|
||||
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)),
|
||||
AbstractionsNamespaceName, MultipartBodyClassName)
|
||||
|
|
|
@ -727,7 +727,7 @@ public class TypeScriptRefiner : CommonLanguageRefiner, ILanguageRefiner
|
|||
new (static x => x is CodeMethod m && HasMultipartBody(m),
|
||||
AbstractionsPackageName, MultipartBodyClassName, $"serialize{MultipartBodyClassName}"),
|
||||
new (static x => (x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.Custom) && prop.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))
|
||||
|| (x is CodeMethod method && (method.Parameters.Any(param => param.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)) || method.ReturnType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))),
|
||||
|| (x is CodeMethod method && (method.Parameters.Any(param => param.Kind is CodeParameterKind.RequestBody && param.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)) || method.ReturnType.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase))),
|
||||
AbstractionsPackageName, KiotaBuilder.UntypedNodeName, "createUntypedNodeFromDiscriminatorValue"),
|
||||
};
|
||||
private const string MultipartBodyClassName = "MultipartBody";
|
||||
|
|
|
@ -1195,6 +1195,37 @@ components:
|
|||
Assert.Equal("github.com/OrgName/RepoName.apisdk.models", models.Name);
|
||||
Assert.Equal("github.com/OrgName/RepoName.apisdk.models.submodels.camelcase", camelCaseModel.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddsUsingForUntypedNodeInMethodParameterAsync()
|
||||
{
|
||||
var requestBuilderClass = root.AddClass(new CodeClass() { Name = "NodeRequestBuilder" }).First();
|
||||
var method = new CodeMethod
|
||||
{
|
||||
Name = "getAsync",
|
||||
ReturnType = new CodeType
|
||||
{
|
||||
Name = "string",
|
||||
IsExternal = true
|
||||
},
|
||||
Kind = CodeMethodKind.RequestExecutor
|
||||
};
|
||||
method.AddParameter(new CodeParameter()
|
||||
{
|
||||
Name = "jsonData",
|
||||
Type = new CodeType()
|
||||
{
|
||||
Name = KiotaBuilder.UntypedNodeName,
|
||||
IsExternal = true
|
||||
},
|
||||
Kind = CodeParameterKind.RequestBody
|
||||
});
|
||||
requestBuilderClass.AddMethod(method);
|
||||
await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.Go }, root);
|
||||
Assert.Equal(GoRefiner.UntypedNodeName, method.Parameters.First().Type.Name);// type is renamed
|
||||
Assert.NotEmpty(requestBuilderClass.StartBlock.Usings);
|
||||
var nodeUsing = requestBuilderClass.StartBlock.Usings.Where(static declaredUsing => declaredUsing.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
Assert.Single(nodeUsing);
|
||||
Assert.Equal("github.com/microsoft/kiota-abstractions-go/serialization", nodeUsing[0].Declaration.Name);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -729,5 +729,37 @@ public class JavaLanguageRefinerTests
|
|||
Assert.Equal(2, nodeUsing.Length); // one for the getter and another for setter. Writer will unionise
|
||||
Assert.Equal("com.microsoft.kiota.serialization", nodeUsing[0].Declaration.Name);
|
||||
}
|
||||
[Fact]
|
||||
public async Task AddsUsingForUntypedNodeInMethodParameterAsync()
|
||||
{
|
||||
var requestBuilderClass = root.AddClass(new CodeClass() { Name = "NodeRequestBuilder" }).First();
|
||||
var method = new CodeMethod
|
||||
{
|
||||
Name = "getAsync",
|
||||
ReturnType = new CodeType
|
||||
{
|
||||
Name = "string",
|
||||
IsExternal = true
|
||||
},
|
||||
Kind = CodeMethodKind.RequestExecutor
|
||||
};
|
||||
method.AddParameter(new CodeParameter()
|
||||
{
|
||||
Name = "jsonData",
|
||||
Type = new CodeType()
|
||||
{
|
||||
Name = KiotaBuilder.UntypedNodeName,
|
||||
IsExternal = true
|
||||
},
|
||||
Kind = CodeParameterKind.RequestBody
|
||||
});
|
||||
requestBuilderClass.AddMethod(method);
|
||||
await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.Java }, root);
|
||||
Assert.Equal(KiotaBuilder.UntypedNodeName, method.Parameters.First().Type.Name);// type is renamed
|
||||
Assert.NotEmpty(requestBuilderClass.StartBlock.Usings);
|
||||
var nodeUsing = requestBuilderClass.StartBlock.Usings.Where(static declaredUsing => declaredUsing.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
Assert.Single(nodeUsing);
|
||||
Assert.Equal("com.microsoft.kiota.serialization", nodeUsing[0].Declaration.Name);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -1014,7 +1014,8 @@ public sealed class TypeScriptLanguageRefinerTests : IDisposable
|
|||
{
|
||||
Name = KiotaBuilder.UntypedNodeName,
|
||||
IsExternal = true
|
||||
}
|
||||
},
|
||||
Kind = CodeParameterKind.RequestBody
|
||||
});
|
||||
requestBuilderClass.AddMethod(method);
|
||||
await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.TypeScript }, root);
|
||||
|
|
Загрузка…
Ссылка в новой задаче