Skip to content

Commit

Permalink
fix omitempty on some fields for LoadBalancing (TT-881) (#6837)
Browse files Browse the repository at this point in the history
### **User description**
<details open>
<summary><a href="https://tyktech.atlassian.net/browse/TT-881"
title="TT-881" target="_blank">TT-881</a></summary>
  <br />
  <table>
    <tr>
      <th>Summary</th>
      <td>[OAS] Upstream load balancing</td>
    </tr>
    <tr>
      <th>Type</th>
      <td>
<img alt="Story"
src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10315?size=medium"
/>
        Story
      </td>
    </tr>
    <tr>
      <th>Status</th>
      <td>Ready for Testing</td>
    </tr>
    <tr>
      <th>Points</th>
      <td>N/A</td>
    </tr>
    <tr>
      <th>Labels</th>
<td><a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20A%20ORDER%20BY%20created%20DESC"
title="A">A</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20CSE%20ORDER%20BY%20created%20DESC"
title="CSE">CSE</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20EMEA%20ORDER%20BY%20created%20DESC"
title="EMEA">EMEA</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Gold%20ORDER%20BY%20created%20DESC"
title="Gold">Gold</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20customer_request%20ORDER%20BY%20created%20DESC"
title="customer_request">customer_request</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20jira_escalated%20ORDER%20BY%20created%20DESC"
title="jira_escalated">jira_escalated</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20updated%20ORDER%20BY%20created%20DESC"
title="updated">updated</a></td>
    </tr>
  </table>
</details>
<!--
  do not remove this marker as it will break jira-lint's functionality.
  added_by_jira_lint
-->

---

This PR fixes `omitempty` on required fields for LoadBalancing.

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why


___

### **PR Type**
Bug fix


___

### **Description**
- Removed `omitempty` from `LoadBalancing` fields to enforce required
properties.

- Updated JSON schema to align with new `LoadBalancing` requirements.


___



### **Changes walkthrough** 📝
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Bug
fix</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>upstream.go</strong><dd><code>Enforce required fields
in LoadBalancing struct</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

apidef/oas/upstream.go

<li>Removed <code>omitempty</code> from <code>Enabled</code>,
<code>URL</code>, and <code>Weight</code> fields.<br> <li> Marked these
fields as required in comments.


</details>


  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6837/files#diff-7b0941c7f37fe5a2a23047e0822a65519ca11c371660f36555b59a60f000e3f4">+3/-3</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
  <td>
    <details>
<summary><strong>x-tyk-api-gateway.json</strong><dd><code>Update JSON
schema for LoadBalancing requirements</code>&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

apidef/oas/schema/x-tyk-api-gateway.json

<li>Removed <code>targets</code> from the <code>required</code> list in
JSON schema.<br> <li> Ensured schema consistency with updated
<code>LoadBalancing</code> struct.


</details>


  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6837/files#diff-78828969c0c04cc1a776dfc93a8bad3c499a8c83e6169f83e96d090bed3e7dd0">+1/-2</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>
</table></td></tr></tr></tbody></table>

___

> 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull
request to receive relevant information
  • Loading branch information
pvormste authored Jan 20, 2025
1 parent 4070fe0 commit 270b0e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions apidef/oas/schema/x-tyk-api-gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -2257,8 +2257,7 @@
}
},
"required": [
"enabled",
"targets"
"enabled"
]
},
"X-Tyk-LoadBalancingTarget": {
Expand Down
6 changes: 3 additions & 3 deletions apidef/oas/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,17 +838,17 @@ func (u *UpstreamOAuth) ExtractTo(api *apidef.UpstreamOAuth) {
// LoadBalancing represents the configuration for load balancing between multiple upstream targets.
type LoadBalancing struct {
// Enabled determines if load balancing is active.
Enabled bool `json:"enabled,omitempty" bson:"enabled,omitempty"`
Enabled bool `json:"enabled" bson:"enabled"` // required
// Targets defines the list of targets with their respective weights for load balancing.
Targets []LoadBalancingTarget `json:"targets,omitempty" bson:"targets,omitempty"`
}

// LoadBalancingTarget represents a single upstream target for load balancing with a URL and an associated weight.
type LoadBalancingTarget struct {
// URL specifies the upstream target URL for load balancing, represented as a string.
URL string `json:"url,omitempty" bson:"url,omitempty"`
URL string `json:"url" bson:"url"` // required
// Weight specifies the relative distribution factor for load balancing, determining the importance of this target.
Weight int `json:"weight,omitempty" bson:"weight,omitempty"`
Weight int `json:"weight" bson:"weight"` // required
}

// Fill populates the LoadBalancing structure based on the provided APIDefinition, including targets and their weights.
Expand Down

0 comments on commit 270b0e2

Please sign in to comment.