[TT-11954/TT-12115]fix location of contextVariables#6285
Conversation
|
API Changes --- prev.txt 2024-05-16 13:12:55.416408503 +0000
+++ current.txt 2024-05-16 13:12:51.484401249 +0000
@@ -3154,6 +3154,9 @@
// TransformResponseHeaders contains the configurations related to API level response header transformation.
// Tyk classic API definition: `global_response_headers`/`global_response_headers_remove`.
TransformResponseHeaders *TransformHeaders `bson:"transformResponseHeaders,omitempty" json:"transformResponseHeaders,omitempty"`
+
+ // ContextVariables contains the configuration related to Tyk context variables.
+ ContextVariables *ContextVariables `bson:"contextVariables,omitempty" json:"contextVariables,omitempty"`
}
Global contains configuration that affects the whole API (all endpoints).
@@ -3987,9 +3990,6 @@
//
// Tyk classic API definition: `event_handlers`
EventHandlers EventHandlers `bson:"eventHandlers,omitempty" json:"eventHandlers,omitempty"`
-
- // ContextVariables contains the configuration related to Tyk context variables.
- ContextVariables *ContextVariables `bson:"contextVariables,omitempty" json:"contextVariables,omitempty"`
}
Server contains the configuration that sets Tyk up to receive requests from
the client applications. |
|
PR Description updated to latest commit (80dd15c) |
PR Review 🔍(Review updated until commit e7c5f69)
Code feedback:
|
PR Code Suggestions ✨
|
💥 CI tests failed 🙈git-stateall okPlease look at the run or in the Checks tab. |
|
PR Description updated to latest commit (e7c5f69) |
|
Persistent review updated to latest commit e7c5f69 |
PR Code Suggestions ✨
|
e7c5f69 to
a8696bc
Compare
|
1 similar comment
|
|
/release to release-5.3 |
|
Working on it! Note that it can take a few minutes. |
<!-- Provide a general summary of your changes in the Title above --> fix context variables location Parent: https://tyktech.atlassian.net/browse/TT-11954 Subtask: https://tyktech.atlassian.net/browse/TT-12115 <!-- Why is this change required? What problem does it solve? --> <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> <!-- 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) <!-- 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 ___ Bug fix, Enhancement ___ - Enhanced handling of `ContextVariables` in middleware to prevent their loss when global settings are omitted. - Added and updated tests for the new handling methods of `ContextVariables`. - Modified OAS migration logic to not enable `ContextVariables` by default, providing more control. - Implemented a new method `SetContextVariablesIfEmpty` to conditionally set `ContextVariables` if they are not already set. - Updated API creation logic to utilize the new method for setting `ContextVariables`, ensuring consistency and control. ___ <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Enhance handling and lifecycle of ContextVariables in middleware</code></dd></summary> <hr> apidef/oas/middleware.go <li>Added handling to preserve <code>ContextVariables</code> when <code>Global</code> middleware <br>settings are omitted.<br> <li> Implemented <code>Fill</code> and <code>ExtractTo</code> methods for <code>ContextVariables</code> to manage <br>their lifecycle in API definitions.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Modify default ContextVariables behavior on OAS migration</code></dd></summary> <hr> apidef/oas/oas.go <li>Removed default enabling of <code>ContextVariables</code> during OAS migration to <br>allow more controlled management.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Implement conditional setting of ContextVariables</code> </dd></summary> <hr> apidef/oas/root.go <li>Added <code>SetContextVariablesIfEmpty</code> to ensure <code>ContextVariables</code> are set <br>only if they are not already configured.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+23/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Adjust API creation logic to use new ContextVariables setting method</code></dd></summary> <hr> gateway/api.go <li>Adjusted logic to use <code>SetContextVariablesIfEmpty</code> for setting context <br>variables during API creation.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+3/-3</a> </td> </tr> </table></td></tr><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for ContextVariables handling in middleware</code> </dd></summary> <hr> apidef/oas/middleware_test.go <li>Added tests for <code>ContextVariables</code> to ensure correct behavior of <code>Fill</code> <br>and <code>ExtractTo</code> methods.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Test new conditional ContextVariables setting method</code> </dd></summary> <hr> apidef/oas/root_test.go <li>Added extensive testing for the new <code>SetContextVariablesIfEmpty</code> method <br>to verify its conditional logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+124/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update API tests to accommodate new ContextVariables logic</code></dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect new handling of <code>ContextVariables</code> in API <br>creation and migration scenarios.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+4/-4</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions (cherry picked from commit 6396372)
|
@titpetric Succesfully merged PR |
…iables (#6285) (#6304) ### **User description** [TT-11954/TT-12115]fix location of contextVariables (#6285) ### **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description fix context variables location ## Related Issue Parent: https://tyktech.atlassian.net/browse/TT-11954 Subtask: https://tyktech.atlassian.net/browse/TT-12115 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## 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, Enhancement ___ ### **Description** - Enhanced handling of `ContextVariables` in middleware to prevent their loss when global settings are omitted. - Added and updated tests for the new handling methods of `ContextVariables`. - Modified OAS migration logic to not enable `ContextVariables` by default, providing more control. - Implemented a new method `SetContextVariablesIfEmpty` to conditionally set `ContextVariables` if they are not already set. - Updated API creation logic to utilize the new method for setting `ContextVariables`, ensuring consistency and control. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Enhance handling and lifecycle of ContextVariables in middleware</code></dd></summary> <hr> apidef/oas/middleware.go <li>Added handling to preserve <code>ContextVariables</code> when <code>Global</code> middleware <br>settings are omitted.<br> <li> Implemented <code>Fill</code> and <code>ExtractTo</code> methods for <code>ContextVariables</code> to manage <br>their lifecycle in API definitions.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Modify default ContextVariables behavior on OAS migration</code></dd></summary> <hr> apidef/oas/oas.go <li>Removed default enabling of <code>ContextVariables</code> during OAS migration to <br>allow more controlled management.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Implement conditional setting of ContextVariables</code> </dd></summary> <hr> apidef/oas/root.go <li>Added <code>SetContextVariablesIfEmpty</code> to ensure <code>ContextVariables</code> are set <br>only if they are not already configured.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+23/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Adjust API creation logic to use new ContextVariables setting method</code></dd></summary> <hr> gateway/api.go <li>Adjusted logic to use <code>SetContextVariablesIfEmpty</code> for setting context <br>variables during API creation.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+3/-3</a> </td> </tr> </table></td></tr><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for ContextVariables handling in middleware</code> </dd></summary> <hr> apidef/oas/middleware_test.go <li>Added tests for <code>ContextVariables</code> to ensure correct behavior of <code>Fill</code> <br>and <code>ExtractTo</code> methods.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Test new conditional ContextVariables setting method</code> </dd></summary> <hr> apidef/oas/root_test.go <li>Added extensive testing for the new <code>SetContextVariablesIfEmpty</code> method <br>to verify its conditional logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+124/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update API tests to accommodate new ContextVariables logic</code></dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect new handling of <code>ContextVariables</code> in API <br>creation and migration scenarios.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+4/-4</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions ___ ### **PR Type** Bug fix, Enhancement ___ ### **Description** - Added `enableContextVariablesIfEmpty` method to ensure context variables are enabled during import. - Added and updated tests to verify context variables are enabled by default. - Added `ContextVariables` field to `Global` struct and implemented methods to handle them. - Removed redundant code and assertions related to context variables enabling. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>default.go</strong><dd><code>Ensure context variables are enabled during import.</code> </dd></summary> <hr> apidef/oas/default.go <li>Added <code>enableContextVariablesIfEmpty</code> method call to ensure context <br>variables are enabled during import.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-83c3a85bdd05785178ee519b05b1fe2008435dc4ae9448d72b080b5f67c491ad">+1/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Add context variables handling in middleware.</code> </dd></summary> <hr> apidef/oas/middleware.go <li>Added <code>ContextVariables</code> field to <code>Global</code> struct.<br> <li> Implemented methods to fill and extract context variables.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Add method to enable context variables if not set.</code> </dd></summary> <hr> apidef/oas/root.go - Added `enableContextVariablesIfEmpty` method to `XTykAPIGateway`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+18/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests </strong></td><td><details><summary>5 files</summary><table> <tr> <td> <details> <summary><strong>default_test.go</strong><dd><code>Add tests for default context variables enabling.</code> </dd></summary> <hr> apidef/oas/default_test.go - Added tests to verify context variables are enabled by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-ab6848f71731083885a9d7d7970faa68a6783a98477c78413ae3979cb5add7db">+66/-3</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for middleware context variables handling.</code> </dd></summary> <hr> apidef/oas/middleware_test.go - Added tests for context variables handling in middleware. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas_test.go</strong><dd><code>Update tests to reflect removal of redundant context variables </code><br><code>enabling.</code></dd></summary> <hr> apidef/oas/oas_test.go <li>Removed assertions related to redundant context variables enabling.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-74029ee88132d30d6478c96a35f8bb2200e0c8e6f42f2c9b147dc6bb7ce74644">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Add tests for enabling context variables if not set.</code> </dd></summary> <hr> apidef/oas/root_test.go - Added tests for `enableContextVariablesIfEmpty` method. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+94/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update tests for context variables enabling logic.</code> </dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect changes in context variables enabling logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+1/-20</a> </td> </tr> </table></details></td></tr><tr><td><strong>Bug fix </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Remove redundant context variables enabling.</code> </dd></summary> <hr> apidef/oas/oas.go <li>Removed redundant enabling of context variables in <br><code>newOASFromClassicAPIDefinition</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Remove redundant context variables enabling code.</code> </dd></summary> <hr> gateway/api.go - Removed redundant code for enabling context variables by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct placement of context variables definition.</code> </dd></summary> <hr> apidef/oas/schema/x-tyk-api-gateway.json - Moved `contextVariables` definition to the correct section. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-78828969c0c04cc1a776dfc93a8bad3c499a8c83e6169f83e96d090bed3e7dd0">+3/-3</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Jeffy Mathew <[email protected]> Co-authored-by: Tit Petric <[email protected]>
### **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description fix context variables location ## Related Issue Parent: https://tyktech.atlassian.net/browse/TT-11954 Subtask: https://tyktech.atlassian.net/browse/TT-12115 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## 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, Enhancement ___ ### **Description** - Enhanced handling of `ContextVariables` in middleware to prevent their loss when global settings are omitted. - Added and updated tests for the new handling methods of `ContextVariables`. - Modified OAS migration logic to not enable `ContextVariables` by default, providing more control. - Implemented a new method `SetContextVariablesIfEmpty` to conditionally set `ContextVariables` if they are not already set. - Updated API creation logic to utilize the new method for setting `ContextVariables`, ensuring consistency and control. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Enhance handling and lifecycle of ContextVariables in middleware</code></dd></summary> <hr> apidef/oas/middleware.go <li>Added handling to preserve <code>ContextVariables</code> when <code>Global</code> middleware <br>settings are omitted.<br> <li> Implemented <code>Fill</code> and <code>ExtractTo</code> methods for <code>ContextVariables</code> to manage <br>their lifecycle in API definitions.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Modify default ContextVariables behavior on OAS migration</code></dd></summary> <hr> apidef/oas/oas.go <li>Removed default enabling of <code>ContextVariables</code> during OAS migration to <br>allow more controlled management.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Implement conditional setting of ContextVariables</code> </dd></summary> <hr> apidef/oas/root.go <li>Added <code>SetContextVariablesIfEmpty</code> to ensure <code>ContextVariables</code> are set <br>only if they are not already configured.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+23/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Adjust API creation logic to use new ContextVariables setting method</code></dd></summary> <hr> gateway/api.go <li>Adjusted logic to use <code>SetContextVariablesIfEmpty</code> for setting context <br>variables during API creation.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+3/-3</a> </td> </tr> </table></td></tr><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for ContextVariables handling in middleware</code> </dd></summary> <hr> apidef/oas/middleware_test.go <li>Added tests for <code>ContextVariables</code> to ensure correct behavior of <code>Fill</code> <br>and <code>ExtractTo</code> methods.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Test new conditional ContextVariables setting method</code> </dd></summary> <hr> apidef/oas/root_test.go <li>Added extensive testing for the new <code>SetContextVariablesIfEmpty</code> method <br>to verify its conditional logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+124/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update API tests to accommodate new ContextVariables logic</code></dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect new handling of <code>ContextVariables</code> in API <br>creation and migration scenarios.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+4/-4</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions
…iables (#6285) (#6304) ### **User description** [TT-11954/TT-12115]fix location of contextVariables (#6285) ### **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description fix context variables location ## Related Issue Parent: https://tyktech.atlassian.net/browse/TT-11954 Subtask: https://tyktech.atlassian.net/browse/TT-12115 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## 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, Enhancement ___ ### **Description** - Enhanced handling of `ContextVariables` in middleware to prevent their loss when global settings are omitted. - Added and updated tests for the new handling methods of `ContextVariables`. - Modified OAS migration logic to not enable `ContextVariables` by default, providing more control. - Implemented a new method `SetContextVariablesIfEmpty` to conditionally set `ContextVariables` if they are not already set. - Updated API creation logic to utilize the new method for setting `ContextVariables`, ensuring consistency and control. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Enhance handling and lifecycle of ContextVariables in middleware</code></dd></summary> <hr> apidef/oas/middleware.go <li>Added handling to preserve <code>ContextVariables</code> when <code>Global</code> middleware <br>settings are omitted.<br> <li> Implemented <code>Fill</code> and <code>ExtractTo</code> methods for <code>ContextVariables</code> to manage <br>their lifecycle in API definitions.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Modify default ContextVariables behavior on OAS migration</code></dd></summary> <hr> apidef/oas/oas.go <li>Removed default enabling of <code>ContextVariables</code> during OAS migration to <br>allow more controlled management.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Implement conditional setting of ContextVariables</code> </dd></summary> <hr> apidef/oas/root.go <li>Added <code>SetContextVariablesIfEmpty</code> to ensure <code>ContextVariables</code> are set <br>only if they are not already configured.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+23/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Adjust API creation logic to use new ContextVariables setting method</code></dd></summary> <hr> gateway/api.go <li>Adjusted logic to use <code>SetContextVariablesIfEmpty</code> for setting context <br>variables during API creation.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+3/-3</a> </td> </tr> </table></td></tr><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for ContextVariables handling in middleware</code> </dd></summary> <hr> apidef/oas/middleware_test.go <li>Added tests for <code>ContextVariables</code> to ensure correct behavior of <code>Fill</code> <br>and <code>ExtractTo</code> methods.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Test new conditional ContextVariables setting method</code> </dd></summary> <hr> apidef/oas/root_test.go <li>Added extensive testing for the new <code>SetContextVariablesIfEmpty</code> method <br>to verify its conditional logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+124/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update API tests to accommodate new ContextVariables logic</code></dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect new handling of <code>ContextVariables</code> in API <br>creation and migration scenarios.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+4/-4</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions ___ ### **PR Type** Bug fix, Enhancement ___ ### **Description** - Added `enableContextVariablesIfEmpty` method to ensure context variables are enabled during import. - Added and updated tests to verify context variables are enabled by default. - Added `ContextVariables` field to `Global` struct and implemented methods to handle them. - Removed redundant code and assertions related to context variables enabling. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>default.go</strong><dd><code>Ensure context variables are enabled during import.</code> </dd></summary> <hr> apidef/oas/default.go <li>Added <code>enableContextVariablesIfEmpty</code> method call to ensure context <br>variables are enabled during import.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-83c3a85bdd05785178ee519b05b1fe2008435dc4ae9448d72b080b5f67c491ad">+1/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Add context variables handling in middleware.</code> </dd></summary> <hr> apidef/oas/middleware.go <li>Added <code>ContextVariables</code> field to <code>Global</code> struct.<br> <li> Implemented methods to fill and extract context variables.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Add method to enable context variables if not set.</code> </dd></summary> <hr> apidef/oas/root.go - Added `enableContextVariablesIfEmpty` method to `XTykAPIGateway`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+18/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests </strong></td><td><details><summary>5 files</summary><table> <tr> <td> <details> <summary><strong>default_test.go</strong><dd><code>Add tests for default context variables enabling.</code> </dd></summary> <hr> apidef/oas/default_test.go - Added tests to verify context variables are enabled by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-ab6848f71731083885a9d7d7970faa68a6783a98477c78413ae3979cb5add7db">+66/-3</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for middleware context variables handling.</code> </dd></summary> <hr> apidef/oas/middleware_test.go - Added tests for context variables handling in middleware. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas_test.go</strong><dd><code>Update tests to reflect removal of redundant context variables </code><br><code>enabling.</code></dd></summary> <hr> apidef/oas/oas_test.go <li>Removed assertions related to redundant context variables enabling.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-74029ee88132d30d6478c96a35f8bb2200e0c8e6f42f2c9b147dc6bb7ce74644">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Add tests for enabling context variables if not set.</code> </dd></summary> <hr> apidef/oas/root_test.go - Added tests for `enableContextVariablesIfEmpty` method. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+94/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update tests for context variables enabling logic.</code> </dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect changes in context variables enabling logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+1/-20</a> </td> </tr> </table></details></td></tr><tr><td><strong>Bug fix </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Remove redundant context variables enabling.</code> </dd></summary> <hr> apidef/oas/oas.go <li>Removed redundant enabling of context variables in <br><code>newOASFromClassicAPIDefinition</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Remove redundant context variables enabling code.</code> </dd></summary> <hr> gateway/api.go - Removed redundant code for enabling context variables by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct placement of context variables definition.</code> </dd></summary> <hr> apidef/oas/schema/x-tyk-api-gateway.json - Moved `contextVariables` definition to the correct section. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-78828969c0c04cc1a776dfc93a8bad3c499a8c83e6169f83e96d090bed3e7dd0">+3/-3</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Jeffy Mathew <[email protected]> Co-authored-by: Tit Petric <[email protected]>
…iables (#6285) (#6304) ### **User description** [TT-11954/TT-12115]fix location of contextVariables (#6285) ### **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description fix context variables location ## Related Issue Parent: https://tyktech.atlassian.net/browse/TT-11954 Subtask: https://tyktech.atlassian.net/browse/TT-12115 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## 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, Enhancement ___ ### **Description** - Enhanced handling of `ContextVariables` in middleware to prevent their loss when global settings are omitted. - Added and updated tests for the new handling methods of `ContextVariables`. - Modified OAS migration logic to not enable `ContextVariables` by default, providing more control. - Implemented a new method `SetContextVariablesIfEmpty` to conditionally set `ContextVariables` if they are not already set. - Updated API creation logic to utilize the new method for setting `ContextVariables`, ensuring consistency and control. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Enhance handling and lifecycle of ContextVariables in middleware</code></dd></summary> <hr> apidef/oas/middleware.go <li>Added handling to preserve <code>ContextVariables</code> when <code>Global</code> middleware <br>settings are omitted.<br> <li> Implemented <code>Fill</code> and <code>ExtractTo</code> methods for <code>ContextVariables</code> to manage <br>their lifecycle in API definitions.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Modify default ContextVariables behavior on OAS migration</code></dd></summary> <hr> apidef/oas/oas.go <li>Removed default enabling of <code>ContextVariables</code> during OAS migration to <br>allow more controlled management.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Implement conditional setting of ContextVariables</code> </dd></summary> <hr> apidef/oas/root.go <li>Added <code>SetContextVariablesIfEmpty</code> to ensure <code>ContextVariables</code> are set <br>only if they are not already configured.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+23/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Adjust API creation logic to use new ContextVariables setting method</code></dd></summary> <hr> gateway/api.go <li>Adjusted logic to use <code>SetContextVariablesIfEmpty</code> for setting context <br>variables during API creation.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+3/-3</a> </td> </tr> </table></td></tr><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for ContextVariables handling in middleware</code> </dd></summary> <hr> apidef/oas/middleware_test.go <li>Added tests for <code>ContextVariables</code> to ensure correct behavior of <code>Fill</code> <br>and <code>ExtractTo</code> methods.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Test new conditional ContextVariables setting method</code> </dd></summary> <hr> apidef/oas/root_test.go <li>Added extensive testing for the new <code>SetContextVariablesIfEmpty</code> method <br>to verify its conditional logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+124/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update API tests to accommodate new ContextVariables logic</code></dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect new handling of <code>ContextVariables</code> in API <br>creation and migration scenarios.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+4/-4</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions ___ ### **PR Type** Bug fix, Enhancement ___ ### **Description** - Added `enableContextVariablesIfEmpty` method to ensure context variables are enabled during import. - Added and updated tests to verify context variables are enabled by default. - Added `ContextVariables` field to `Global` struct and implemented methods to handle them. - Removed redundant code and assertions related to context variables enabling. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>default.go</strong><dd><code>Ensure context variables are enabled during import.</code> </dd></summary> <hr> apidef/oas/default.go <li>Added <code>enableContextVariablesIfEmpty</code> method call to ensure context <br>variables are enabled during import.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-83c3a85bdd05785178ee519b05b1fe2008435dc4ae9448d72b080b5f67c491ad">+1/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Add context variables handling in middleware.</code> </dd></summary> <hr> apidef/oas/middleware.go <li>Added <code>ContextVariables</code> field to <code>Global</code> struct.<br> <li> Implemented methods to fill and extract context variables.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Add method to enable context variables if not set.</code> </dd></summary> <hr> apidef/oas/root.go - Added `enableContextVariablesIfEmpty` method to `XTykAPIGateway`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+18/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests </strong></td><td><details><summary>5 files</summary><table> <tr> <td> <details> <summary><strong>default_test.go</strong><dd><code>Add tests for default context variables enabling.</code> </dd></summary> <hr> apidef/oas/default_test.go - Added tests to verify context variables are enabled by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-ab6848f71731083885a9d7d7970faa68a6783a98477c78413ae3979cb5add7db">+66/-3</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for middleware context variables handling.</code> </dd></summary> <hr> apidef/oas/middleware_test.go - Added tests for context variables handling in middleware. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas_test.go</strong><dd><code>Update tests to reflect removal of redundant context variables </code><br><code>enabling.</code></dd></summary> <hr> apidef/oas/oas_test.go <li>Removed assertions related to redundant context variables enabling.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-74029ee88132d30d6478c96a35f8bb2200e0c8e6f42f2c9b147dc6bb7ce74644">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Add tests for enabling context variables if not set.</code> </dd></summary> <hr> apidef/oas/root_test.go - Added tests for `enableContextVariablesIfEmpty` method. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+94/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update tests for context variables enabling logic.</code> </dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect changes in context variables enabling logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+1/-20</a> </td> </tr> </table></details></td></tr><tr><td><strong>Bug fix </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Remove redundant context variables enabling.</code> </dd></summary> <hr> apidef/oas/oas.go <li>Removed redundant enabling of context variables in <br><code>newOASFromClassicAPIDefinition</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Remove redundant context variables enabling code.</code> </dd></summary> <hr> gateway/api.go - Removed redundant code for enabling context variables by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct placement of context variables definition.</code> </dd></summary> <hr> apidef/oas/schema/x-tyk-api-gateway.json - Moved `contextVariables` definition to the correct section. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-78828969c0c04cc1a776dfc93a8bad3c499a8c83e6169f83e96d090bed3e7dd0">+3/-3</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Jeffy Mathew <[email protected]> Co-authored-by: Tit Petric <[email protected]>
…iables (TykTechnologies#6285) (TykTechnologies#6304) ### **User description** [TT-11954/TT-12115]fix location of contextVariables (TykTechnologies#6285) ### **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description fix context variables location ## Related Issue Parent: https://tyktech.atlassian.net/browse/TT-11954 Subtask: https://tyktech.atlassian.net/browse/TT-12115 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## 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, Enhancement ___ ### **Description** - Enhanced handling of `ContextVariables` in middleware to prevent their loss when global settings are omitted. - Added and updated tests for the new handling methods of `ContextVariables`. - Modified OAS migration logic to not enable `ContextVariables` by default, providing more control. - Implemented a new method `SetContextVariablesIfEmpty` to conditionally set `ContextVariables` if they are not already set. - Updated API creation logic to utilize the new method for setting `ContextVariables`, ensuring consistency and control. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Enhance handling and lifecycle of ContextVariables in middleware</code></dd></summary> <hr> apidef/oas/middleware.go <li>Added handling to preserve <code>ContextVariables</code> when <code>Global</code> middleware <br>settings are omitted.<br> <li> Implemented <code>Fill</code> and <code>ExtractTo</code> methods for <code>ContextVariables</code> to manage <br>their lifecycle in API definitions.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Modify default ContextVariables behavior on OAS migration</code></dd></summary> <hr> apidef/oas/oas.go <li>Removed default enabling of <code>ContextVariables</code> during OAS migration to <br>allow more controlled management.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Implement conditional setting of ContextVariables</code> </dd></summary> <hr> apidef/oas/root.go <li>Added <code>SetContextVariablesIfEmpty</code> to ensure <code>ContextVariables</code> are set <br>only if they are not already configured.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+23/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Adjust API creation logic to use new ContextVariables setting method</code></dd></summary> <hr> gateway/api.go <li>Adjusted logic to use <code>SetContextVariablesIfEmpty</code> for setting context <br>variables during API creation.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+3/-3</a> </td> </tr> </table></td></tr><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for ContextVariables handling in middleware</code> </dd></summary> <hr> apidef/oas/middleware_test.go <li>Added tests for <code>ContextVariables</code> to ensure correct behavior of <code>Fill</code> <br>and <code>ExtractTo</code> methods.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Test new conditional ContextVariables setting method</code> </dd></summary> <hr> apidef/oas/root_test.go <li>Added extensive testing for the new <code>SetContextVariablesIfEmpty</code> method <br>to verify its conditional logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+124/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update API tests to accommodate new ContextVariables logic</code></dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect new handling of <code>ContextVariables</code> in API <br>creation and migration scenarios.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6285/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+4/-4</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions ___ ### **PR Type** Bug fix, Enhancement ___ ### **Description** - Added `enableContextVariablesIfEmpty` method to ensure context variables are enabled during import. - Added and updated tests to verify context variables are enabled by default. - Added `ContextVariables` field to `Global` struct and implemented methods to handle them. - Removed redundant code and assertions related to context variables enabling. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>default.go</strong><dd><code>Ensure context variables are enabled during import.</code> </dd></summary> <hr> apidef/oas/default.go <li>Added <code>enableContextVariablesIfEmpty</code> method call to ensure context <br>variables are enabled during import.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-83c3a85bdd05785178ee519b05b1fe2008435dc4ae9448d72b080b5f67c491ad">+1/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Add context variables handling in middleware.</code> </dd></summary> <hr> apidef/oas/middleware.go <li>Added <code>ContextVariables</code> field to <code>Global</code> struct.<br> <li> Implemented methods to fill and extract context variables.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+46/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>root.go</strong><dd><code>Add method to enable context variables if not set.</code> </dd></summary> <hr> apidef/oas/root.go - Added `enableContextVariablesIfEmpty` method to `XTykAPIGateway`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-9c56b2bdb992e0a7db76809d4c516e1cd61c9486c7f0437b344c0032476af80f">+18/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests </strong></td><td><details><summary>5 files</summary><table> <tr> <td> <details> <summary><strong>default_test.go</strong><dd><code>Add tests for default context variables enabling.</code> </dd></summary> <hr> apidef/oas/default_test.go - Added tests to verify context variables are enabled by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-ab6848f71731083885a9d7d7970faa68a6783a98477c78413ae3979cb5add7db">+66/-3</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for middleware context variables handling.</code> </dd></summary> <hr> apidef/oas/middleware_test.go - Added tests for context variables handling in middleware. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+71/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>oas_test.go</strong><dd><code>Update tests to reflect removal of redundant context variables </code><br><code>enabling.</code></dd></summary> <hr> apidef/oas/oas_test.go <li>Removed assertions related to redundant context variables enabling.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-74029ee88132d30d6478c96a35f8bb2200e0c8e6f42f2c9b147dc6bb7ce74644">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>root_test.go</strong><dd><code>Add tests for enabling context variables if not set.</code> </dd></summary> <hr> apidef/oas/root_test.go - Added tests for `enableContextVariablesIfEmpty` method. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-4d144465b7fabaf2db8915de1ce3b6ff8c91a93c62d614c38fa38bdae28e23a2">+94/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_test.go</strong><dd><code>Update tests for context variables enabling logic.</code> </dd></summary> <hr> gateway/api_test.go <li>Updated tests to reflect changes in context variables enabling logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+1/-20</a> </td> </tr> </table></details></td></tr><tr><td><strong>Bug fix </strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>oas.go</strong><dd><code>Remove redundant context variables enabling.</code> </dd></summary> <hr> apidef/oas/oas.go <li>Removed redundant enabling of context variables in <br><code>newOASFromClassicAPIDefinition</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+0/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Remove redundant context variables enabling code.</code> </dd></summary> <hr> gateway/api.go - Removed redundant code for enabling context variables by default. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+0/-5</a> </td> </tr> <tr> <td> <details> <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct placement of context variables definition.</code> </dd></summary> <hr> apidef/oas/schema/x-tyk-api-gateway.json - Moved `contextVariables` definition to the correct section. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6304/files#diff-78828969c0c04cc1a776dfc93a8bad3c499a8c83e6169f83e96d090bed3e7dd0">+3/-3</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Jeffy Mathew <[email protected]> Co-authored-by: Tit Petric <[email protected]>



User description
Description
fix context variables location
Related Issue
Parent: https://tyktech.atlassian.net/browse/TT-11954
Subtask: https://tyktech.atlassian.net/browse/TT-12115
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Bug fix, Enhancement
Description
ContextVariablesin middleware to prevent their loss when global settings are omitted.ContextVariables.ContextVariablesby default, providing more control.SetContextVariablesIfEmptyto conditionally setContextVariablesif they are not already set.ContextVariables, ensuring consistency and control.Changes walkthrough 📝
middleware.go
Enhance handling and lifecycle of ContextVariables in middlewareapidef/oas/middleware.go
ContextVariableswhenGlobalmiddlewaresettings are omitted.
FillandExtractTomethods forContextVariablesto managetheir lifecycle in API definitions.
oas.go
Modify default ContextVariables behavior on OAS migrationapidef/oas/oas.go
ContextVariablesduring OAS migration toallow more controlled management.
root.go
Implement conditional setting of ContextVariablesapidef/oas/root.go
SetContextVariablesIfEmptyto ensureContextVariablesare setonly if they are not already configured.
api.go
Adjust API creation logic to use new ContextVariables setting methodgateway/api.go
SetContextVariablesIfEmptyfor setting contextvariables during API creation.
middleware_test.go
Add tests for ContextVariables handling in middlewareapidef/oas/middleware_test.go
ContextVariablesto ensure correct behavior ofFilland
ExtractTomethods.root_test.go
Test new conditional ContextVariables setting methodapidef/oas/root_test.go
SetContextVariablesIfEmptymethodto verify its conditional logic.
api_test.go
Update API tests to accommodate new ContextVariables logicgateway/api_test.go
ContextVariablesin APIcreation and migration scenarios.