Coder Social home page Coder Social logo

microsoft / kiota-abstractions-go Goto Github PK

View Code? Open in Web Editor NEW
11.0 16.0 9.0 371 KB

Abstractions library for the Kiota generated SDKs in go

Home Page: https://aka.ms/kiota/docs

License: MIT License

Go 99.39% Dockerfile 0.61%
kiota go golang openapi sdk sdk-go

kiota-abstractions-go's Introduction

Kiota Abstractions Library for go

Go

The Kiota abstractions Library for go is the go library defining the basic constructs Kiota projects need once an SDK has been generated from an OpenAPI definition.

A Kiota generated project will need a reference to the abstraction package to build and run.

Read more about Kiota here.

Using the Abstractions Library

go get github.com/microsoft/kiota-abstractions-go

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

kiota-abstractions-go's People

Contributors

andreatp avatar andrueastman avatar baywet avatar dependabot[bot] avatar fabiante avatar ffawkes avatar github-actions[bot] avatar mattn avatar microsoft-github-operations[bot] avatar microsoftopensource avatar nerdjeremia avatar papegaaij avatar rkodev avatar xdpcs avatar yseto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiota-abstractions-go's Issues

The factory type should be corrected

var BackingStoreFactoryInstance = NewInMemoryBackingStore

  • the type of the variable should be BackingStoreFactory and not InMemoryBacking store
  • the generation needs to be corrected to call the factory (add () )

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.

Clarification on ParseNode Usage

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 )

concurrent map writes in github.com/microsoft/kiota-abstractions-go/api_client_builder.go:70

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

Updating a slice or a map from the in-memory backing store results in a panic

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.

Setting fields to `nil` now causes `null` in resulting serialized data

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:

  1. create some graph SDK model, for this example we'll use an event
  2. create a body for the event
  3. update the event body with body.SetOdataType(nil)
  4. POST the event to microsoft's graph endpoint like you're making a new event instance
  5. get above error response back

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

Guid uri template path/query parameter values should be normalized to string

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

Exploded query parameters are not working

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.