Skip to content

[TT-11954/TT-12115]fix location of contextVariables#6285

Merged
jeffy-mathew merged 8 commits into
masterfrom
feat/TT-11954/TT-12115/enabled-context-vars-oas-2
May 16, 2024
Merged

[TT-11954/TT-12115]fix location of contextVariables#6285
jeffy-mathew merged 8 commits into
masterfrom
feat/TT-11954/TT-12115/enabled-context-vars-oas-2

Conversation

@jeffy-mathew

@jeffy-mathew jeffy-mathew commented May 16, 2024

Copy link
Copy Markdown
Contributor

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

  • 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, 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 📝

Relevant files
Enhancement
middleware.go
Enhance handling and lifecycle of ContextVariables in middleware

apidef/oas/middleware.go

  • Added handling to preserve ContextVariables when Global middleware
    settings are omitted.
  • Implemented Fill and ExtractTo methods for ContextVariables to manage
    their lifecycle in API definitions.
  • +46/-0   
    oas.go
    Modify default ContextVariables behavior on OAS migration

    apidef/oas/oas.go

  • Removed default enabling of ContextVariables during OAS migration to
    allow more controlled management.
  • +0/-1     
    root.go
    Implement conditional setting of ContextVariables               

    apidef/oas/root.go

  • Added SetContextVariablesIfEmpty to ensure ContextVariables are set
    only if they are not already configured.
  • +23/-0   
    api.go
    Adjust API creation logic to use new ContextVariables setting method

    gateway/api.go

  • Adjusted logic to use SetContextVariablesIfEmpty for setting context
    variables during API creation.
  • +3/-3     
    Tests
    middleware_test.go
    Add tests for ContextVariables handling in middleware       

    apidef/oas/middleware_test.go

  • Added tests for ContextVariables to ensure correct behavior of Fill
    and ExtractTo methods.
  • +71/-0   
    root_test.go
    Test new conditional ContextVariables setting method         

    apidef/oas/root_test.go

  • Added extensive testing for the new SetContextVariablesIfEmpty method
    to verify its conditional logic.
  • +124/-0 
    api_test.go
    Update API tests to accommodate new ContextVariables logic

    gateway/api_test.go

  • Updated tests to reflect new handling of ContextVariables in API
    creation and migration scenarios.
  • +4/-4     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions

    github-actions Bot commented May 16, 2024

    Copy link
    Copy Markdown
    Contributor

    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.

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Description updated to latest commit (80dd15c)

    @github-actions

    github-actions Bot commented May 16, 2024

    Copy link
    Copy Markdown
    Contributor

    PR Review 🔍

    (Review updated until commit e7c5f69)

    ⏱️ Estimated effort to review [1-5]

    3, because the PR involves multiple changes across several files with complex logic related to context variable handling. Understanding the impact on existing functionality and ensuring no regressions occur would require a moderate amount of effort.

    🧪 Relevant tests

    Yes

    ⚡ Possible issues

    Possible Bug: The logic in SetContextVariablesIfEmpty might unintentionally enable context variables even if they were explicitly set to false elsewhere in the code. This could lead to unexpected behavior where context variables are enabled against the user's configuration.

    🔒 Security concerns

    No

    Code feedback:
    relevant fileapidef/oas/middleware.go
    suggestion      

    Consider handling the case where ContextVariables is explicitly set to false. You might want to add a check to ensure that ContextVariables is only set to true if it was previously unset. This prevents overriding explicit user configurations. [important]

    relevant linem.Global = &Global{ContextVariables: m.Global.ContextVariables}

    relevant fileapidef/oas/root.go
    suggestion      

    To avoid potential null pointer exceptions, add a null check before accessing x.Middleware.Global.ContextVariables in the SetContextVariablesIfEmpty method. This ensures that the code is more robust and can handle cases where Global might be null. [important]

    relevant linex.Middleware.Global.ContextVariables = &ContextVariables{

    relevant fileapidef/oas/server.go
    suggestion      

    Since ContextVariables related code is removed from Server, ensure that all references and dependencies in other parts of the project are also updated to reflect this change. This helps in maintaining consistency and avoiding runtime errors. [medium]

    relevant line- ContextVariables *ContextVariables `bson:"contextVariables,omitempty" json:"contextVariables,omitempty"`

    relevant filegateway/api.go
    suggestion      

    Ensure that the method SetContextVariablesIfEmpty is thoroughly tested when integrating with the gateway logic, especially in scenarios where context variables might be explicitly disabled in the configuration. [important]

    relevant lineoasObj.GetTykExtension().SetContextVariablesIfEmpty()

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a nil check before calling a method on a pointer to prevent potential runtime errors

    Consider checking for nil before calling the Fill method on ContextVariables to prevent
    potential nil pointer dereference.

    apidef/oas/middleware.go [234]

    -g.ContextVariables.Fill(api)
    +if g.ContextVariables != nil {
    +    g.ContextVariables.Fill(api)
    +}
     
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a potential nil pointer dereference, which is a critical issue that could cause runtime crashes. The provided fix is accurate and aligns with best practices in Go.

    8
    Maintainability
    Encapsulate the initialization of ContextVariables into a method to enhance code maintainability

    Instead of setting ContextVariables to a new instance with Enabled: true directly,
    consider a method that encapsulates this logic to improve code reuse and maintainability.

    gateway/api.go [1068]

    -oasObj.GetTykMiddleware().Global.ContextVariables = &oas.ContextVariables{Enabled: true}
    +oasObj.GetTykMiddleware().Global.EnableContextVariables()
     
    Suggestion importance[1-10]: 7

    Why: This suggestion promotes better code reuse and maintainability by encapsulating repetitive logic into a method. This is a good practice, especially when the same logic appears in multiple places across the codebase.

    7
    Best practice
    Modify the defer pattern to direct assignment within the conditional block for clarity and potential thread safety

    To ensure thread safety, avoid using defer to set ContextVariables to nil after checking
    ShouldOmit. Instead, handle this logic within the conditional block.

    apidef/oas/middleware.go [227-230]

    -defer func() {
    -    if ShouldOmit(g.ContextVariables) {
    -        g.ContextVariables = nil
    -    }
    -}()
    +if ShouldOmit(g.ContextVariables) {
    +    g.ContextVariables = nil
    +}
     
    Suggestion importance[1-10]: 6

    Why: The suggestion improves clarity and may enhance thread safety by avoiding deferred execution, which can be unpredictable in complex functions. However, the original code does not necessarily introduce a thread safety issue, so the impact is moderate.

    6
    Enhancement
    Add handling for cases where ContextVariables might already be initialized to prevent unnecessary reinitialization

    Ensure that ContextVariables is only instantiated once by checking its current state
    before setting it to a new instance in multiple places.

    apidef/oas/middleware.go [225]

     if g.ContextVariables == nil {
         g.ContextVariables = &ContextVariables{}
    +} else {
    +    // Handle the case where ContextVariables is already initialized
     }
     
    Suggestion importance[1-10]: 5

    Why: The suggestion addresses a minor enhancement by checking if ContextVariables is already initialized. However, the impact of this change is limited since the existing code does not show any negative effects from reinitialization in the provided context.

    5

    @TykTechnologies TykTechnologies deleted a comment from github-actions Bot May 16, 2024
    @TykTechnologies TykTechnologies deleted a comment from github-actions Bot May 16, 2024
    @github-actions

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @jeffy-mathew
    jeffy-mathew marked this pull request as draft May 16, 2024 10:03
    @jeffy-mathew
    jeffy-mathew marked this pull request as ready for review May 16, 2024 10:26
    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Description updated to latest commit (e7c5f69)

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    Persistent review updated to latest commit e7c5f69

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add nil check for m.Global to prevent nil pointer dereference

    Consider checking if m.Global is nil before calling m.Global.Fill(api) and other
    operations on m.Global to avoid potential nil pointer dereference.

    apidef/oas/middleware.go [27]

    -m.Global.Fill(api)
    +if m.Global != nil {
    +    m.Global.Fill(api)
    +}
     
    Suggestion importance[1-10]: 8

    Why: Adding a nil check before accessing m.Global is crucial to prevent runtime errors due to nil pointer dereference, which is a significant improvement for robustness.

    8
    Maintainability
    Refactor conditional logic to improve code readability and maintainability

    Refactor the conditional logic to reduce duplication and improve readability by
    consolidating the checks for nil values and the assignment of new instances.

    apidef/oas/middleware.go [29-34]

    -if m.Global.ContextVariables != nil {
    -    m.Global = &Global{ContextVariables: m.Global.ContextVariables}
    -    return
    -}
    -m.Global = nil
    +m.Global = handleGlobalContextVariables(m.Global)
     
    Suggestion importance[1-10]: 7

    Why: The suggestion to refactor the code to reduce duplication and improve readability is valid and beneficial. However, it assumes the existence of a handleGlobalContextVariables function which is not defined in the PR, slightly reducing its applicability.

    7
    Improve handling of existing context variables to prevent data loss

    Use a more robust approach for handling context variables by ensuring that any existing
    settings are not overwritten unintentionally when m.Global.ContextVariables is not nil.

    apidef/oas/middleware.go [30]

    -m.Global = &Global{ContextVariables: m.Global.ContextVariables}
    +if m.Global.ContextVariables != nil {
    +    preservedContextVariables := m.Global.ContextVariables
    +    m.Global = new(Global)
    +    m.Global.ContextVariables = preservedContextVariables
    +}
     
    Suggestion importance[1-10]: 6

    Why: The suggestion correctly identifies the need to preserve existing context variables when reassigning m.Global. This enhances data integrity and maintainability.

    6

    @jeffy-mathew
    jeffy-mathew force-pushed the feat/TT-11954/TT-12115/enabled-context-vars-oas-2 branch from e7c5f69 to a8696bc Compare May 16, 2024 10:32
    @TykTechnologies TykTechnologies deleted a comment from github-actions Bot May 16, 2024
    @TykTechnologies TykTechnologies deleted a comment from github-actions Bot May 16, 2024
    @sonarqubecloud

    Copy link
    Copy Markdown

    1 similar comment
    @sonarqubecloud

    Copy link
    Copy Markdown

    @jeffy-mathew
    jeffy-mathew merged commit 6396372 into master May 16, 2024
    @jeffy-mathew
    jeffy-mathew deleted the feat/TT-11954/TT-12115/enabled-context-vars-oas-2 branch May 16, 2024 13:41
    @titpetric

    Copy link
    Copy Markdown
    Contributor

    /release to release-5.3

    @tykbot

    tykbot Bot commented May 23, 2024

    Copy link
    Copy Markdown

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

    tykbot Bot pushed a commit that referenced this pull request May 23, 2024
    <!-- 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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Implement conditional setting
    of ContextVariables</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Test new conditional
    ContextVariables setting method</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    </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>&nbsp;
    &nbsp; &nbsp; </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)
    @tykbot

    tykbot Bot commented May 23, 2024

    Copy link
    Copy Markdown

    @titpetric Succesfully merged PR

    titpetric pushed a commit that referenced this pull request May 23, 2024
    …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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Implement conditional setting
    of ContextVariables</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Test new conditional
    ContextVariables setting method</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware.go</strong><dd><code>Add context variables
    handling in middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Add method to enable context
    variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware_test.go</strong><dd><code>Add tests for
    middleware context variables handling.</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Add tests for enabling
    context variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Update tests for context
    variables enabling logic.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api.go</strong><dd><code>Remove redundant context
    variables enabling code.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct
    placement of context variables definition.</code>&nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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]>
    nerdydread pushed a commit that referenced this pull request Sep 6, 2024
    ### **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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Implement conditional setting
    of ContextVariables</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Test new conditional
    ContextVariables setting method</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    </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>&nbsp;
    &nbsp; &nbsp; </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
    edsonmichaque pushed a commit that referenced this pull request Feb 18, 2025
    …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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Implement conditional setting
    of ContextVariables</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Test new conditional
    ContextVariables setting method</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware.go</strong><dd><code>Add context variables
    handling in middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Add method to enable context
    variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware_test.go</strong><dd><code>Add tests for
    middleware context variables handling.</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Add tests for enabling
    context variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Update tests for context
    variables enabling logic.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api.go</strong><dd><code>Remove redundant context
    variables enabling code.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct
    placement of context variables definition.</code>&nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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]>
    edsonmichaque pushed a commit that referenced this pull request Feb 18, 2025
    …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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Implement conditional setting
    of ContextVariables</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Test new conditional
    ContextVariables setting method</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware.go</strong><dd><code>Add context variables
    handling in middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Add method to enable context
    variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware_test.go</strong><dd><code>Add tests for
    middleware context variables handling.</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Add tests for enabling
    context variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Update tests for context
    variables enabling logic.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api.go</strong><dd><code>Remove redundant context
    variables enabling code.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct
    placement of context variables definition.</code>&nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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]>
    edsonmichaque pushed a commit to edsonmichaque/tyk-1 that referenced this pull request Feb 18, 2025
    …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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Implement conditional setting
    of ContextVariables</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Test new conditional
    ContextVariables setting method</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    </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>&nbsp;
    &nbsp; &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware.go</strong><dd><code>Add context variables
    handling in middleware.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root.go</strong><dd><code>Add method to enable context
    variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>middleware_test.go</strong><dd><code>Add tests for
    middleware context variables handling.</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>root_test.go</strong><dd><code>Add tests for enabling
    context variables if not set.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </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>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Update tests for context
    variables enabling logic.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; </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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>api.go</strong><dd><code>Remove redundant context
    variables enabling code.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>x-tyk-api-gateway.json</strong><dd><code>Correct
    placement of context variables definition.</code>&nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </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>&nbsp;
    &nbsp; &nbsp; </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]>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants