Azure / Azure/typespec-azure

Allow specification of dynamic query keyvalue pairs

Open
#4,951 1 comment 0 reactions 1 assignee Claimed by @jhendrixMSFT View on GitHub
emitter:go feature
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

> Migrated from https://github.com/Azure/autorest.go/issues/1383

---

My use case is that I want to generate a client that can add arbitrary key-value pairs to the query-string of a request. I think it is possible to define this in OpenAPI 3 (not 2), but I don't think that autorest.go supports it yet.

For example, I can specify the following:

```json

{

"openapi": "3.0.0",

...

"paths": {

"/api/invoke": {

"post": {

"parameters": [

{

"name": "query",

"in": "query",

"schema": {

"type": "array",

"items": {

"type": "string"

}

},

"explode": true,

"style": "form"

}

]

}

}

}

}

```

And that will generate a Go client that contains this snippet:

```go

reqQP := req.Raw().URL.Query()

if options != nil && options.Query != nil {

for _, qv := range options.Query {

reqQP.Add("query", qv)

}

}

req.Raw().URL.RawQuery = reqQP.Encode()

```

This is really close, but I end up with a dynamic querystring `?query=a&query=b`, and I want to express a dynamic querystring `?foo=a&bar=b`, etc.

What I want to be able to do is instead of specifying an array of type string, specify an object with additionalProperties string.

Reading https://swagger.io/docs/specification/serialization/, I think this is a legitimate thing to be able to express in OpenAPI 3.

However when I do that, I get the error `Error: unexpected type map[string]*string for QueryCollectionParameter Query`.

Would it be possible to make this work? Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.