Commit 1572bf9
🐛 Fix link followers generation to avoid duplicate query params (#149)
<!--
Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors.
All rights reserved.
SPDX-License-Identifier: Proprietary
-->
### Description
<!--
Please add any detail or context that would be useful to a reviewer.
-->
Since we patch the link follower functions that are generated by OpenAPI
Generator by changing the behaviour from following a hard-coded link to
following a link argument, there was a recent patch by the generator
that added default param values to `limit`, `offset` and `embed` if it
was missing in the request, but the way we follow link, we follow
already constructed links already with the params set up.
Since we already have a link with the correct params, we don't need to
add these params to the request, and the generator now appends default
value params, which results in a duplication of these params.
Since the behaviour is patched by us to follow generic links, we have to
patch this behavior as well.
This patch adds these statements at the beginning of follower functions
```go
linkHasOffsetParam := false
linkHasLimitParam := false
linkHasEmbedParam := false
if parsedLink, err := url.Parse(link); err == nil {
linkQuery := parsedLink.Query()
linkHasOffsetParam = linkQuery.Has("offset")
linkHasLimitParam = linkQuery.Has("limit")
linkHasEmbedParam = linkQuery.Has("embed")
}
```
Then our generator searches for param checks
```go
if r.limit != nil
// or
if r.offset != nil
// or
if r.embed != nil
```
and wraps these blocks with our injected guard:
```go
if !linkHasLimitParam
if r.limit != nil
// or
if !linkHasOffsetParam
if r.offset != nil
// or
if !linkHasEmbedParam
if r.embed != nil
```
### Test Coverage
<!--
Please put an `x` in the correct box e.g. `[x]` to indicate the testing
coverage of this change.
-->
- [X] This change is covered by existing or additional automated tests.
- [ ] Manual testing has been performed (and evidence provided) as
automated testing was not feasible.
- [ ] Additional tests are not required for this change (e.g.
documentation update).
---------
Co-authored-by: aorabdel <[email protected]>
Co-authored-by: Adrien CABARBAYE <[email protected]>
Co-authored-by: acabarbaye <[email protected]>
Co-authored-by: acabarbaye <[email protected]>1 parent 1cd0b6d commit 1572bf9
File tree
22 files changed
+3122
-1355
lines changed- changes
- client
- extensions
- generator/codegen
- snippets
- testdata
- collections
- jobs
- linkfollowers
22 files changed
+3122
-1355
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments