From 270b0e231d6e3ea4b74fe6e52631e7d9aa557850 Mon Sep 17 00:00:00 2001 From: Patric Vormstein Date: Mon, 20 Jan 2025 11:18:28 +0100 Subject: [PATCH] fix omitempty on some fields for LoadBalancing (TT-881) (#6837) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### **User description**
TT-881
Summary [OAS] Upstream load balancing
Type Story Story
Status Ready for Testing
Points N/A
Labels A, CSE, EMEA, Gold, customer_request, jira_escalated, updated
--- This PR fixes `omitempty` on required fields for LoadBalancing. ## Types of changes - [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 - [ ] 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** 📝
Relevant files
Bug fix
upstream.go
Enforce required fields in LoadBalancing struct                   

apidef/oas/upstream.go
  • Removed omitempty from Enabled, URL, and Weight fields.
  • Marked these fields as required in comments.
  • +3/-3     
    x-tyk-api-gateway.json
    Update JSON schema for LoadBalancing requirements               

    apidef/oas/schema/x-tyk-api-gateway.json
  • Removed targets from the required list in JSON schema.
  • Ensured schema consistency with updated LoadBalancing struct.
  • +1/-2     
    ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information --- apidef/oas/schema/x-tyk-api-gateway.json | 3 +-- apidef/oas/upstream.go | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apidef/oas/schema/x-tyk-api-gateway.json b/apidef/oas/schema/x-tyk-api-gateway.json index 458394fff94..39eb108dcc8 100644 --- a/apidef/oas/schema/x-tyk-api-gateway.json +++ b/apidef/oas/schema/x-tyk-api-gateway.json @@ -2257,8 +2257,7 @@ } }, "required": [ - "enabled", - "targets" + "enabled" ] }, "X-Tyk-LoadBalancingTarget": { diff --git a/apidef/oas/upstream.go b/apidef/oas/upstream.go index 13e42910bf4..225562fa934 100644 --- a/apidef/oas/upstream.go +++ b/apidef/oas/upstream.go @@ -838,7 +838,7 @@ 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"` } @@ -846,9 +846,9 @@ type LoadBalancing struct { // 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.