-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add code generation for Dart #5966
base: main
Are you sure you want to change the base?
Conversation
This code is not nearly finished, but was pushed to work simultaneously on this code base. Using a DartRefiner that is created from scratch. In the end this will be our actual refiner, and we will update ILanguage to reflect this.
Also added imprts for properties and methods. Tjose imports are not correct yet.
Imports in other files are still incorrect.
No idea if it actually works, but at least it compiles.
Added more Dart syntax to creating methods.
createFromDiscriminatorValue also looks correct.
…hods and properties
Ricardo's suggestion has been applied and the test has been updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you all for the great work! And special thanks to @ricardoboss for ensuring we cross the finish line on this project!
@andrueastman @Ndiritu I'm going to ask that both of you review this PR. I've already reviewed it on the fork, and I was coaching the team as well. So getting additional pair of eyes will be paramount here.
The idea is to try and make it for the minor release on the 9th, no rush though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the current failures in the integration tests expected for now and to be resolved in a separate PR?
writer.StartBlock($"class {codeElement.Name}{derivation}{implements} {{"); | ||
} | ||
|
||
private String getAlias(string alias) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private String getAlias(string alias) | |
private static string getAlias(string alias) |
{ | ||
if (parentClass.IsOfKind(CodeClassKind.Model) && codeElement.IsOfKind(CodeMethodKind.Constructor) && !parentClass.IsErrorDefinition) | ||
{ | ||
return !parentClass.Properties.Where(prop => !string.IsNullOrEmpty(prop.DefaultValue)).Any(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return !parentClass.Properties.Where(prop => !string.IsNullOrEmpty(prop.DefaultValue)).Any(); | |
return parentClass.Properties.All(prop => string.IsNullOrEmpty(prop.DefaultValue)); |
{ | ||
if (property.Type is CodeType propertyType) | ||
{ | ||
var typeName = conventions.GetTypeString(propertyType, codeElement, true, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused var
var typeName = conventions.GetTypeString(propertyType, codeElement, true, false); |
} | ||
} | ||
|
||
private string DefaultDeserializerReturnType => $"Map<String, void Function({conventions.ParseNodeInterfaceName})>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused property
private string DefaultDeserializerReturnType => $"Map<String, void Function({conventions.ParseNodeInterfaceName})>"; |
} | ||
} | ||
|
||
protected virtual void WriteCommandBuilderBody(CodeMethod codeElement, CodeClass parentClass, RequestParams requestParams, bool isVoid, string returnType, LanguageWriter writer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably remove this function. Then throw exception in the caller directly in the switch case on line 123(and remove the irrelevant code there.)
{ | ||
writer.WriteLine("@override"); | ||
} | ||
var genericTypePrefix = isVoid ? string.Empty : "<"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused var
var genericTypePrefix = isVoid ? string.Empty : "<"; |
private static IEnumerable<CodeNamespace> GetAllNamespaces(CodeNamespace ns) | ||
{ | ||
foreach (var childNs in ns.Namespaces) | ||
{ | ||
yield return childNs; | ||
foreach (var childNsSegment in GetAllNamespaces(childNs)) | ||
yield return childNsSegment; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused function
private static IEnumerable<CodeNamespace> GetAllNamespaces(CodeNamespace ns) | |
{ | |
foreach (var childNs in ns.Namespaces) | |
{ | |
yield return childNs; | |
foreach (var childNsSegment in GetAllNamespaces(childNs)) | |
yield return childNsSegment; | |
} | |
} |
var parentElementsHash = targetElement.Parent is CodeClass parentClass ? | ||
parentClass.Methods.Select(static x => x.Name) | ||
.Union(parentClass.Properties.Select(static x => x.Name)) | ||
.Distinct(StringComparer.OrdinalIgnoreCase) | ||
.ToHashSet(StringComparer.OrdinalIgnoreCase) : | ||
new HashSet<string>(0, StringComparer.OrdinalIgnoreCase); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused function. (We can then also remove the second parameter of the function)
var parentElementsHash = targetElement.Parent is CodeClass parentClass ? | |
parentClass.Methods.Select(static x => x.Name) | |
.Union(parentClass.Properties.Select(static x => x.Name)) | |
.Distinct(StringComparer.OrdinalIgnoreCase) | |
.ToHashSet(StringComparer.OrdinalIgnoreCase) : | |
new HashSet<string>(0, StringComparer.OrdinalIgnoreCase); |
Not really, they are a side-effect of recent changes in the Dart packages. I've created a separate PR to fix this: kiota-community#4 Additionally, I discovered a bug that also has a separate PR to fix it: kiota-community#3 |
also updated the min environment version and dependencies
…event version resolution
The name used for the URL template needs to match the serialized name of the custom parameter.
@andrueastman I applied all your suggestions. Thanks for reviewing! |
Adds code generation for the Dart programming language.
This PR was a joint effort and contains lots of good work by @joanne-ter-maat and @Kees-Schotanus and is the result of lots of iterations and review over at kiota-community#1 by @baywet and @andreaTP.
Fixes #3745.