Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit gateway tags if empty #4127

Merged
merged 17 commits into from Jun 15, 2022
Merged

Conversation

titpetric
Copy link
Contributor

@titpetric titpetric commented Jun 14, 2022

Description

The gateway provided segmentation tags behavior as an always-enabled option. In order to implement a config flag that wouldn't change existing behavior, "tags_disabled" was implemented. When converting between OAS and the Tyk API Definition, this means that the configuration flag for the tags is copied between the two API definitions. This means what is disabled=false for tags in the tyk apidef becomes enabled=true in the OAS document.

This adds a cleanup for the OAS document that removes the gatewayTags entry if either the tags are disabled, or if they are enabled and no tags are defined (length=0).

Related Issue

https://tyktech.atlassian.net/browse/TT-5718

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • 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

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
    • If new config option added, ensure that it can be set via ENV variable
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • When updating library version must provide reason/explanation for this update.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

@@ -60,6 +60,11 @@ func (s *Server) ExtractTo(api *apidef.APIDefinition) {
}
if s.GatewayTags != nil {
s.GatewayTags.ExtractTo(api)

// Omit gateway tags if empty or disabled
if !s.GatewayTags.Enabled || len(s.GatewayTags.Tags) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ShouldOmit function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, nil set should be done after fill function, not extract.

Copy link
Contributor Author

@titpetric titpetric Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed a case, because it doesn't work for this structure. I think it doesn't handle the case where the GatewayTags are allocated (Tags field). As we do a nil check, this is type-safe and doesn't use reflection.

Correction: it didn't handle {Enabled: true}...

I added tags validation to require at least 1 array item, verified validation in validation tests. Also removed this from extract and left only in fill as suggested.

@TykTechnologies TykTechnologies deleted a comment from github-actions bot Jun 14, 2022
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit:
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: d0a32c9
Triggered by: pull_request (@titpetric)
Execution page

@TykTechnologies TykTechnologies deleted a comment from github-actions bot Jun 14, 2022
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: b6d2d8e
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: a42b23b
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 3dcb182
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: b1cc9cf
Triggered by: pull_request (@titpetric)
Execution page

@github-actions
Copy link

💥 CI tests failed 🙈

CI test log

all ok

gofmt

all ok

goimports

all ok

gogenerate

:100644 100644 2cf51f5d8c2a45fd6f87883dcf58b4084eb9a19a de2bc36c1eb6a5fc662f8cac1d508b8076b72aae M apidef/oas/schema/schema.gen.go

If the above are ok, please look at the run or in the Checks tab.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 20d5a35
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: cd31343
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 1503e13
Triggered by: pull_request (@titpetric)
Execution page

@github-actions
Copy link

💥 CI tests failed 🙈

CI test log

all ok

gofmt

all ok

goimports

all ok

gogenerate

:100644 100644 2cf51f5d8c2a45fd6f87883dcf58b4084eb9a19a de2bc36c1eb6a5fc662f8cac1d508b8076b72aae M apidef/oas/schema/schema.gen.go

If the above are ok, please look at the run or in the Checks tab.

@titpetric titpetric force-pushed the fix/tt-5718/omit-gateway-tags-if-empty branch from bfaed2f to 58c1aea Compare June 14, 2022 18:48
@github-actions
Copy link

💥 CI tests failed 🙈

CI test log

all ok

gofmt

all ok

goimports

all ok

gogenerate

:100644 100644 2cf51f5d8c2a45fd6f87883dcf58b4084eb9a19a de2bc36c1eb6a5fc662f8cac1d508b8076b72aae M apidef/oas/schema/schema.gen.go

If the above are ok, please look at the run or in the Checks tab.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: bfaed2f
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 58c1aea
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 14, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 1e24359
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 5503b32
Triggered by: pull_request (@titpetric)
Execution page

@@ -42,7 +42,7 @@ func (s *Server) Fill(api apidef.APIDefinition) {
s.GatewayTags = &GatewayTags{}
}
s.GatewayTags.Fill(api)
if ShouldOmit(s.GatewayTags) {
if len(s.GatewayTags.Tags) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain why we change it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think that the object will have more fields in future. That’s why we should continue with shouldomit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldOmit won't omit s.GatewayTags when s.GatewayTags.Enabled is true and len(s.GatewayTags.Tags) is 0. I think this is required in such cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a valid case why would you omit if enabled true. If you don't want 0 length tags with enabled, you would handle it in schema.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 92ac66f
Triggered by: pull_request (@titpetric)
Execution page

@@ -42,7 +42,7 @@ func (s *Server) Fill(api apidef.APIDefinition) {
s.GatewayTags = &GatewayTags{}
}
s.GatewayTags.Fill(api)
if ShouldOmit(s.GatewayTags) {
if ShouldOmit(s.GatewayTags.Tags) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should stay as it is. ShouldOmit(s.GatewayTags). I wouldn't push ShouldOmit if it was just and array length check.

@titpetric titpetric force-pushed the fix/tt-5718/omit-gateway-tags-if-empty branch from edb9b67 to 9668e64 Compare June 15, 2022 08:22
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 493ec32
Triggered by: pull_request (@titpetric)
Execution page

apidef/oas/server_test.go Outdated Show resolved Hide resolved
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 9c0a1df
Triggered by: pull_request (@titpetric)
Execution page

@titpetric titpetric force-pushed the fix/tt-5718/omit-gateway-tags-if-empty branch from e5f8922 to 24218f8 Compare June 15, 2022 09:42
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: e5f8922
Triggered by: pull_request (@titpetric)
Execution page

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 24218f8
Triggered by: pull_request (@titpetric)
Execution page

@titpetric titpetric force-pushed the fix/tt-5718/omit-gateway-tags-if-empty branch from 43dbef2 to c093096 Compare June 15, 2022 11:36
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Jun 15, 2022
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Jun 15, 2022
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Jun 15, 2022
@sonarcloud
Copy link

sonarcloud bot commented Jun 15, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: 43dbef2
Triggered by: pull_request (@titpetric)
Execution page

@TykTechnologies TykTechnologies deleted a comment from github-actions bot Jun 15, 2022
@TykTechnologies TykTechnologies deleted a comment from github-actions bot Jun 15, 2022
@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/pull/4127/merge
Commit: c093096
Triggered by: pull_request (@titpetric)
Execution page

@titpetric titpetric merged commit f86f019 into master Jun 15, 2022
@titpetric titpetric deleted the fix/tt-5718/omit-gateway-tags-if-empty branch June 15, 2022 14:12
@titpetric
Copy link
Contributor Author

/release to release-4

@tykbot
Copy link

tykbot bot commented Jun 15, 2022

Working on it! Note that it can take a few minutes.

tykbot bot pushed a commit that referenced this pull request Jun 15, 2022
* Omit gateway tags if empty

* Fix existing omit tags case in Fill

* Remove some gatewayTags invalid values in tests

* Remove second omitEmpty case for gateway tags

* Remove allocation of Tags, not required

* Disable duplicate test for gatewayTags disabled

* Verify gatewayTags array count with schema

* Implement furkans suggestions as per PR #4129

* Add test case for Fill/ExtractTo behaviour

* Update API schema (go generate)

* Add test to validate GatewayTags in Tyk extension

* Return enabled:false in oas document, don't omit

* Adjust gatewayTags tests to account for ShouldOmit

* Remove test, we test for gwtags fill in apidef

* Remove duplicate tests for gatewaytags

* Remove duplicate tests for gatewaytags

* Remove gatewayTags.Tags minItems=1 from validation, pass along as-is, fix tests

(cherry picked from commit f86f019)
@tykbot
Copy link

tykbot bot commented Jun 15, 2022

@titpetric Succesfully merged f86f01955daebde421b09387eb30446fe4667fcd to release-4 branch.

@Tyk-ITS
Copy link
Contributor

Tyk-ITS commented Jun 15, 2022

API tests result: success
Branch used: refs/heads/master
Commit: f86f019 Omit gateway tags if empty (#4127)

  • Omit gateway tags if empty

  • Fix existing omit tags case in Fill

  • Remove some gatewayTags invalid values in tests

  • Remove second omitEmpty case for gateway tags

  • Remove allocation of Tags, not required

  • Disable duplicate test for gatewayTags disabled

  • Verify gatewayTags array count with schema

  • Implement furkans suggestions as per PR Cleanup oas gateway tags #4129

  • Add test case for Fill/ExtractTo behaviour

  • Update API schema (go generate)

  • Add test to validate GatewayTags in Tyk extension

  • Return enabled:false in oas document, don't omit

  • Adjust gatewayTags tests to account for ShouldOmit

  • Remove test, we test for gwtags fill in apidef

  • Remove duplicate tests for gatewaytags

  • Remove duplicate tests for gatewaytags

  • Remove gatewayTags.Tags minItems=1 from validation, pass along as-is, fix tests
    Triggered by: push (@titpetric)
    Execution page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants