microsoft / kiota-abstractions-go Goto Github PK
View Code? Open in Web Editor NEWAbstractions library for the Kiota generated SDKs in go
Home Page: https://aka.ms/kiota/docs
License: MIT License
Abstractions library for the Kiota generated SDKs in go
Home Page: https://aka.ms/kiota/docs
License: MIT License
reflection of microsoft/kiota-java#939
the std uri template library does not handle guids, and wont because it's not a standard API across languages and they don't want to bring on additional dependencies.
We should normalize the value to string (no curlies) before we pass it to the uri template engine.
Originally reported:
std-uritemplate/std-uritemplate#140
microsoft/kiota#4335
Example implementation https://github.com/microsoft/kiota-abstractions-dotnet/blob/5a93d126e9ce30ae332e65f30df7b941e7d7c265/src/RequestInformation.cs#L123
Hi there, I recently attempted to update to v1.5.5 and started getting server errors with the message were unable to deserialize
when posting a calendar event
This error is consistently reproducible if you do the following:
body.SetOdataType(nil)
Digging into this a bit more, I found a difference in the serialized data output that's sent to the graph servers. v1.5.4 doesn't add fields set to nil
to the request being made. v1.5.5 adds fields set to nil to null
(in our example you end up with "odataType": null
in the request for the body of the event). Setting other fields to nil
in the code also results in the request having them set to null
While I realize that setting the odata type in code is probably looked down on, it does make it more difficult to manage these objects as in some cases my team and I are taking an object, copying it's data to a new object, and then modifying some of the fields in the new object. It'd be preferable if the code didn't have to differentiate between what field it's copying over (i.e. explicitly avoid copying the odata type field since just not setting the odata field at all seems to avoid the server error)
As for how we got an object with a nil
odata type as the source of our copy: we were deserializing a previously serialized version of the object
Sending nulls is also a bit concerning because it requires additional data bytes to be transferred when sending a request. While not a huge issue for one or two requests, the amount of additional data required could add up over time
related to microsoft/kiota-abstractions-dotnet#172
@andreaTP as soon as you think you're ready, please go ahead and submit a PR here.
When a query parameter is defined with "style": "form", "explode": true
, it is supposed to be rendered as a multi-valued parameter that repeats for every value. For example, this parameter:
{ "name": "additional",
"in": "query",
"description": "Request additional information to be returned for every record.",
"style": "form",
"explode": true,
"schema": {
"type": "array",
"items": { "type": "string", "enum": ["audit", "markers", "status"] }
}
}
is supposed to be rendered like path?additional=audit&additional=markers
, however Kiota renders it like path?additional=audit,markers
. I've created a pull request that adds a test demonstrating the problem: #113
It seems std-uritemplate
does render the URI correctly if it is passed a []any
, but AddQueryParameters
converts everything to a string
to fit it in RequestInformation.QueryParameters
. I think the type of that field should be changed to map[string]any
and no conversion should be done. There's one caveat though: std-uritemplate
only accepts []any
as a list parameter, not any other slice type. So for example []string{"test1", "test2"}
doesn't work, while []any{"test1", "test2"}
does. This may need to be addressed in std-uritemplate
.
This happened only one time but i had a concurrent map write here:
https://github.com/microsoft/kiota-abstractions-go/blob/main/api_client_builder.go#L70
at that time i was using serviceClient.DirectoryObjects().GetByIds().Post(ctx, requestBody, nil)
from msgraph-sdk
goroutine 113 [running]:
github.com/microsoft/kiota-abstractions-go.enableBackingStoreForParseNodeRegistry(0x106986768)
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoft/kiota-abstractions-go/api_client_builder.go:70 +0xb0
github.com/microsoft/kiota-abstractions-go.EnableBackingStoreForParseNodeFactory({0x105d1bd90?, 0x106986768})
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoft/kiota-abstractions-go/api_client_builder.go:59 +0x44
github.com/microsoft/kiota-http-go.(*NetHttpRequestAdapter).EnableBackingStore(0x140002239f0, 0x105d12268)
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoft/kiota-http-go/nethttp_request_adapter.go:106 +0x34
github.com/microsoftgraph/msgraph-sdk-go.NewGraphBaseServiceClient({0x105d30370, 0x140002239f0}, 0x0?)
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoftgraph/msgraph-sdk-go/graph_base_service_client.go:246 +0x294
github.com/microsoftgraph/msgraph-sdk-go.NewGraphServiceClient(...)
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoftgraph/msgraph-sdk-go/graph_service_client.go:17
github.com/microsoftgraph/msgraph-sdk-go.NewGraphServiceClientWithCredentialsAndHosts({0x105d19140?, 0x14000124920?}, {0x140000a3698?, 0x1057e9ccc?, 0x0?}, {0x0?, 0x0?, 0x0?})
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoftgraph/msgraph-sdk-go/graph_service_client.go:52 +0x144
github.com/webdevops/go-common/msgraphsdk/msgraphclient.(*MsGraphClient).ServiceClient(0x14000172380)
[...]
goroutine 115 [runnable]:
github.com/microsoft/kiota-abstractions-go.(*RequestInformation).setRequestType(0x140004e6b00?, {0x105bfb000?, 0x1400060e660?}, {0x105d2f898, 0x1400072e6e0})
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoft/kiota-abstractions-go/request_information.go:197 +0xf0
github.com/microsoft/kiota-abstractions-go.(*RequestInformation).SetContentFromParsable(0x14000690810?, {0x105d2b040, 0x1400012a120}, {0x105d30370, 0x1400072e640}, {0x1057f46de, 0x10}, {0x13060b418?, 0x1400060e660?})
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoft/kiota-abstractions-go/request_information.go:214 +0x208
github.com/microsoftgraph/msgraph-sdk-go/directoryobjects.(*GetByIdsRequestBuilder).ToPostRequestInformation(0x140005e3848, {0x105d2b040, 0x1400012a120}, {0x105d2fa88?, 0x1400060e660}, 0x0)
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoftgraph/msgraph-sdk-go/directoryobjects/get_by_ids_request_builder.go:62 +0x1e8
github.com/microsoftgraph/msgraph-sdk-go/directoryobjects.(*GetByIdsRequestBuilder).Post(0x140000e9848, {0x105d2b040, 0x1400012a120}, {0x105d2fa88?, 0x1400060e660?}, 0x104da8b84?)
/Users/mblaschke/Projects/webdevops/azure-resourcemanager-exporter/vendor/github.com/microsoftgraph/msgraph-sdk-go/directoryobjects/get_by_ids_request_builder.go:38 +0x30
using go version go1.20.2 darwin/arm64
go.mod:
github.com/microsoftgraph/msgraph-sdk-go v0.60.0
github.com/microsoftgraph/msgraph-sdk-go-core v0.36.0
github.com/microsoft/kiota-abstractions-go v0.19.0
github.com/microsoft/kiota-authentication-azure-go v0.6.0 // indirect
github.com/microsoft/kiota-http-go v0.16.1 // indirect
github.com/microsoft/kiota-serialization-form-go v0.9.0 // indirect
github.com/microsoft/kiota-serialization-json-go v0.9.0 // indirect
github.com/microsoft/kiota-serialization-text-go v0.7.0 // indirect
Creating an issue because I do not see the discussion area.
Continuing the conversation on the ParseNodes. Object is Hydrated and all the content is within the Parsenode. Code recap:
parseNode, _ := js.NewJsonParseNodeFactory().GetRootParseNode("application/json", result)
deserializedValue, err := parseNode.GetObjectValue(models.CreateMessageFromDiscriminatorValue)
if err != nil{
t.Errorf("ERROR: %v\n", err)
}
I believe the previous conversations help us to understand that if we print the type and values of deserialized value we would retrieve something like this.
ParseNode: *models.Message &{{{map[@odata.context:0x14000281f40 value: [0x140002b0c60 0x140002b1950 0x140002d6650....
This is fine so far. The parsable interface gives us this deserializedValue.GetFieldDeserializers()
that returns as described -> GetFieldDeserializers() map[string]func(ParseNode) error
What is unclear is how to get the value that the func(ParseNode) holds for example:
values := deserializedValue.GetFieldDeserializers()
fmt.Printf("%v\n", values")
// map[attachments:0x100abf710 bccRecipients:0x100abf580 body:0x100abf4a0 bodyPreview:0x100abf3e0 categories:0x100ac2650 ccRecipients:0x100abf250 changeKey:0x100ac2590 conversationId:0x100abf190 ...
// How to get the value of bodyPreview?
bp := values["bodyPreview"]
fmt.Printf(%T \t %v\n", bodyPreview, bodyPreview )
With the current code, we're going to end up with one backing store for all objects in memory, and they'll end up overwriting each other, sorry I didn't catch that earlier.
While working with the Microsoft Graph SDK, I've noticed updating a slice or a map from the in-memory backing store results in a panic.
The issue should be easily reproducible with the following test case:
func TestReplaceSlice(t *testing.T) {
memoryStore := NewInMemoryBackingStore()
err := memoryStore.Set("key", []string{"a", "b"})
assert.Nil(t, err)
err = memoryStore.Set("key", []string{"b", "c"})
assert.Nil(t, err)
}
=== RUN TestReplaceSlice
--- FAIL: TestReplaceSlice (0.00s)
panic: runtime error: comparing uncomparable type []string [recovered]
panic: runtime error: comparing uncomparable type []string
goroutine 17 [running]:
testing.tRunner.func1.2({0x5e3360, 0xc000184d30})
C:/Program Files/Go/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
C:/Program Files/Go/src/testing/testing.go:1399 +0x39f
panic({0x5e3360, 0xc000184d30})
C:/Program Files/Go/src/runtime/panic.go:884 +0x212
github.com/microsoft/kiota-abstractions-go/store.(*InMemoryBackingStore).Set(0xc00008dc38, {0x615457?, 0x2?}, {0x5d58a0?, 0xc00018a258})
D:/git/kiota-abstractions-go/store/inmemory_backing_store.go:59 +0xc6
github.com/microsoft/kiota-abstractions-go/store.TestReplaceSlice(0x0?)
D:/git/kiota-abstractions-go/store/inmemory_backing_store_test.go:14 +0x26b
testing.tRunner(0xc0001a6ea0, 0x640820)
C:/Program Files/Go/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
C:/Program Files/Go/src/testing/testing.go:1493 +0x35f
The simplest fix I can think of is replacing the direct comparison with a call to reflect.DeepEqual
, but performance-wise it might be better to implement a custom-written function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.