Description
openedon Mar 21, 2024
Hey team 👋
Hope this is the right place to open Golang generation issues, today I faced a weird issue that I will try to describe below.
It seems that the generator produces a broken Golang code when trying to parse a body
made by an array of scalars.
paths:
/posts:
post:
description: 'Create post'
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
format: int32
type: integer
responses:
'201':
description: Created
content:
application/json:
schema:
type: array
items:
format: int32
type: integer
The generated ToPostRequestInformation
is something like:
// ToPostRequestInformation create post
// returns a *RequestInformation when successful
func (m *PostsRequestBuilder) ToPostRequestInformation(ctx context.Context, body []int32, requestConfiguration *PostsRequestBuilderPostRequestConfiguration)(*i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestInformation, error) {
requestInfo := i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewRequestInformationWithMethodAndUrlTemplateAndPathParameters(i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.POST, "{+baseurl}/posts", m.BaseRequestBuilder.PathParameters)
if requestConfiguration != nil {
requestInfo.Headers.AddAll(requestConfiguration.Headers)
requestInfo.AddRequestOptions(requestConfiguration.Options)
}
requestInfo.Headers.TryAdd("Accept", "application/json")
requestInfo.SetContentFromScalarCollection(ctx, m.BaseRequestBuilder.RequestAdapter, "application/json", body)
return requestInfo, nil
}
The issue is that requestInfo.SetContentFromScalarCollection(ctx, m.BaseRequestBuilder.RequestAdapter, "application/json", body)
cannot receive body
(which is a []int32
) as it is expecting a []interface{}
type which is not allowed [1].
Maybe I missed something or I am doing something wrong (in that case, please let me know) but I think that the openapi is a valid one, therefore I am expecting a valid generated code.
Version
kiota --version [17:54:51]
1.12.0+1735a2ff916ebec661974d9560f1dd00d3dc349b
go version [17:55:22]
go version go1.21.8 linux/amd64
How to reproduce the issue
To reproduce the issue I took the posts
quickstart from the doc and I simply modified it to have a body made by a list of scalars.
- Clone my sample repo: https://github.com/lampajr/kiota_posts
- Run
kiota generate -l go -c PostsClient -n kiota_posts/client -d ./posts-api.yaml -o ./client
Metadata
Assignees
Type
Projects
Status
Done ✔️