You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The build time of the service SDKs can take a while for the initial build/dependencies upgrade on some machines.
This is caused by the breadth of our API but we might have opportunities to improve that aspect by reducing the amount of code we generate.
The goal here is to look into these patterns, identify and share the examples of what could be improved, so we can feed the information back to the kiota generation process.
If application calls the accessor on a nil object, it actually should get an error/panic since it's probably in an invalid state at this point and this is what we'd do in other languages.
Same for setters
func (m *Message) SetCcRecipients(value []Recipientable)() {
- if m != nil {
m.ccRecipients = value
- }
}
Serializers
Since writing scalars and objects writing only returns an error, we can probably reduce the block by doing
For collections of objects, we might be able to do away with the casting like so
if m.GetBccRecipients() != nil {
- cast := make([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable, len(m.GetBccRecipients()))- for i, v := range m.GetBccRecipients() {- cast[i] = v.(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable)- }- err = writer.WriteCollectionOfObjectValues("bccRecipients", cast)+ err = writer.WriteCollectionOfObjectValues("bccRecipients", m.GetBccRecipients())
if err != nil {
return err
}
}
Checking for nil remains important since a nil collection and an empty collection have different semantic meanings.
And regardless, we should implement the error assignment shorthand mentioned above for scalars/objects.
Deserializers
After looking into that further, I don't believe we can achieve significant reductions in deserializers without using generics which is outside of this scope.
Thanks for looking into that. I'm assuming you're getting an error like []Recipientable is not []Parsable correct? seems like covariance could improved in Go...
I'm a bit reluctant to introduce this convert method right now since we're planning to take advantage of generics. Hopefully we can make the WriteCollectionOfObjectValues covariant in microsoft/kiota#1404 but let's keep this as a backup plan if we can't.
So ignore the collections change for the scope of this issue and proceed with the other ones, we'll close this when the other ones are implemented.
Activity
baywet commentedon Aug 15, 2022
Accessors
Currently accessors are generated this way which is unnecessarily verbose:
func (m *Message) GetCcRecipients()([]Recipientable) { - if m == nil { - return nil - } else { return m.ccRecipients - } }If application calls the accessor on a nil object, it actually should get an error/panic since it's probably in an invalid state at this point and this is what we'd do in other languages.
Same for setters
func (m *Message) SetCcRecipients(value []Recipientable)() { - if m != nil { m.ccRecipients = value - } }Serializers
Since writing scalars and objects writing only returns an error, we can probably reduce the block by doing
For collections of objects, we might be able to do away with the casting like so
if m.GetBccRecipients() != nil { - cast := make([]i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable, len(m.GetBccRecipients())) - for i, v := range m.GetBccRecipients() { - cast[i] = v.(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable) - } - err = writer.WriteCollectionOfObjectValues("bccRecipients", cast) + err = writer.WriteCollectionOfObjectValues("bccRecipients", m.GetBccRecipients()) if err != nil { return err } }Checking for nil remains important since a nil collection and an empty collection have different semantic meanings.
And regardless, we should implement the error assignment shorthand mentioned above for scalars/objects.
Deserializers
After looking into that further, I don't believe we can achieve significant reductions in deserializers without using generics which is outside of this scope.
[-]build time improvements[/-][+]reduce the amount of code being generated[/+]rkodev commentedon Aug 16, 2022
Vincent Biret (@baywet) For the collections its not possible to directly type case then as this is failing to comply
However, we can use generics to convert this function as well
baywet commentedon Aug 16, 2022
Thanks for looking into that. I'm assuming you're getting an error like
[]Recipientable is not []Parsablecorrect? seems like covariance could improved in Go...I'm a bit reluctant to introduce this convert method right now since we're planning to take advantage of generics. Hopefully we can make the WriteCollectionOfObjectValues covariant in microsoft/kiota#1404 but let's keep this as a backup plan if we can't.
So ignore the collections change for the scope of this issue and proceed with the other ones, we'll close this when the other ones are implemented.
rkodev commentedon Aug 16, 2022
Vincent Biret (@baywet) Yes, that was the error. Skipped it for now, we can consider it for the generics refactor.