Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[TT-7815] ensure path params are migrated to OAS #6966

Merged
merged 7 commits into from
Mar 19, 2025

Conversation

edsonmichaque
Copy link
Contributor

@edsonmichaque edsonmichaque commented Mar 18, 2025

User description

TT-7815
Summary Cannot migrate API with endpoints containing path parameter
Type Bug Bug
Status In Dev
Points N/A
Labels DoD_Fail, QA_Fail, Re_open

Description

This PR makes sure that path params are successfully migrated from Classic to OAS

Related Issue

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

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
  • Tests

Description

  • Refactored path splitting logic for OAS conversion.

  • Introduced helper functions for regex and mux template parsing.

  • Added unit tests covering various path parameter scenarios.

  • Provided test fixtures for classic to OAS migration.


Changes walkthrough 📝

Relevant files
Enhancement
operation.go
Enhance path parameter migration in OAS operations.           

apidef/oas/operation.go

  • Added import for regexp and httputil.
  • Refactored splitPath with empty path check.
  • Introduced parsePathSegment, parseMuxTemplate, and isIdentifier.
  • Improved regex detection and parameter naming.
  • +49/-18 
    Tests
    operation_test.go
    Add unit tests for splitPath functionality.                           

    apidef/oas/operation_test.go

  • Added TestSplitPath covering diverse scenarios.
  • Verified correct parsing for simple, regex, and mux templates.
  • Ensured empty and root paths are handled.
  • +72/-0   
    path_params.yml
    Add path params test fixture for OAS migration.                   

    apidef/oas/testdata/fixtures/path_params.yml

  • Created YAML fixtures for classic path parameter migration.
  • Defined multiple test cases with varied input patterns.
  • Mapped expected outputs for both simple and regex parameters.
  • +144/-0 

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @buger
    Copy link
    Member

    buger commented Mar 18, 2025

    Let's make that PR title a 💯 shall we? 💪

    Your PR title and story title look slightly different. Just checking in to know if it was intentional!

    Story Title Cannot migrate API with endpoints containing path parameter
    PR Title [TT-7815] ensure path params are migrated to OAS

    Check out this guide to learn more about PR best-practices.

    Copy link
    Contributor

    github-actions bot commented Mar 18, 2025

    API Changes

    no api changes detected

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Code Clarity

    The new functions (parsePathSegment, parseMuxTemplate, and isIdentifier) introduce additional routing logic. Please ensure that all edge cases (such as segments with mixed patterns or unusual characters) are handled correctly and consistently with the existing behavior.

    func hasMockResponse(methodActions map[string]apidef.EndpointMethodMeta) bool {
    	for _, action := range methodActions {
    		if action.Action == apidef.Reply {
    			return true
    		}
    	}
    
    	return false
    }
    
    // parsePathSegment parses a single path segment and determines if it contains a regex pattern.
    func parsePathSegment(segment string, regexCount int, hasRegex bool) (pathPart, int, bool) {
    	if httputil.IsMuxTemplate(segment) {
    		return parseMuxTemplate(segment, regexCount)
    	} else if isIdentifier(segment) {
    		return pathPart{name: segment, value: segment, isRegex: false}, regexCount, hasRegex
    	} else {
    		regexCount++
    		return pathPart{name: fmt.Sprintf("customRegex%d", regexCount), value: segment, isRegex: true}, regexCount, true
    	}
    }
    
    // parseMuxTemplate parses a segment that is a mux template and extracts the name or assigns a custom regex name.
    func parseMuxTemplate(segment string, regexCount int) (pathPart, int, bool) {
    	segment = strings.TrimPrefix(segment, "{")
    	segment = strings.TrimSuffix(segment, "}")
    
    	name, _, ok := strings.Cut(segment, ":")
    	if ok || isIdentifier(segment) {
    		return pathPart{name: name, isRegex: true}, regexCount, true
    	}
    
    	regexCount++
    	return pathPart{name: fmt.Sprintf("customRegex%d", regexCount), isRegex: true}, regexCount, true
    }
    
    func isIdentifier(value string) bool {
    	matched, _ := regexp.MatchString(`^[a-zA-Z0-9._-]+$`, value) //nolint
    	return matched
    }
    Test Coverage

    The TestSplitPath function covers a variety of cases, but double-check that all potential malformed or unexpected path formats (especially those involving mux templates and regex patterns) are adequately tested.

    		operation := s.GetTykExtension().getOperation(operationID)
    
    		assert.NotNil(t, operation.Allow)
    		assert.False(t, operation.Allow.Enabled)
    	})
    }
    
    func TestSplitPath(t *testing.T) {
    	tests := map[string]struct {
    		input     string
    		wantParts []pathPart
    		wantRegex bool
    	}{
    		"simple path": {
    			input: "/test/path",
    			wantParts: []pathPart{
    				{name: "test", value: "test", isRegex: false},
    				{name: "path", value: "path", isRegex: false},
    			},
    			wantRegex: false,
    		},
    		"path with regex": {
    			input: "/test/.*/end",
    			wantParts: []pathPart{
    				{name: "test", value: "test", isRegex: false},
    				{name: "customRegex1", value: ".*", isRegex: true},
    				{name: "end", value: "end", isRegex: false},
    			},
    			wantRegex: true,
    		},
    		"path with curly braces": {
    			input: "/users/{id}/profile",
    			wantParts: []pathPart{
    				{name: "users", value: "users", isRegex: false},
    				{name: "id", isRegex: true},
    				{name: "profile", value: "profile", isRegex: false},
    			},
    			wantRegex: true,
    		},
    		"path with named regex": {
    			input: "/users/{userId:[0-9]+}/posts",
    			wantParts: []pathPart{
    				{name: "users", value: "users", isRegex: false},
    				{name: "userId", isRegex: true},
    				{name: "posts", value: "posts", isRegex: false},
    			},
    			wantRegex: true,
    		},
    		"path with named direct regex": {
    			input: "/users/[0-9]+/posts",
    			wantParts: []pathPart{
    				{name: "users", value: "users", isRegex: false},
    				{name: "customRegex1", value: "[0-9]+", isRegex: true},
    				{name: "posts", value: "posts", isRegex: false},
    			},
    			wantRegex: true,
    		},
    		"empty path": {
    			input:     "",
    			wantParts: []pathPart{},
    			wantRegex: false,
    		},
    		"root path": {
    			input:     "/",
    			wantParts: []pathPart{},
    			wantRegex: false,
    		},
    	}
    
    	for name, tc := range tests {
    		t.Run(name, func(t *testing.T) {
    			gotParts, gotRegex := splitPath(tc.input)
    
    			assert.Equal(t, tc.wantRegex, gotRegex, "regex detection mismatch")
    			assert.Equal(t, tc.wantParts, gotParts, "parts mismatch")
    		})
    	}
    }

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Preserve mux template value

    Preserve the original segment value in mux template parsing to maintain consistency
    with non-mux segments.

    apidef/oas/operation.go [1069-1080]

     func parseMuxTemplate(segment string, regexCount int) (pathPart, int, bool) {
     	segment = strings.TrimPrefix(segment, "{")
     	segment = strings.TrimSuffix(segment, "}")
     
    -	name, _, ok := strings.Cut(segment, ":")
    +	name, remainder, ok := strings.Cut(segment, ":")
     	if ok || isIdentifier(segment) {
    -		return pathPart{name: name, isRegex: true}, regexCount, true
    +		// If there's a regex pattern specified after colon, use it as the value; otherwise, fallback to the name
    +		value := name
    +		if ok {
    +			value = remainder
    +		}
    +		return pathPart{name: name, value: value, isRegex: true}, regexCount, true
     	}
     
     	regexCount++
    -	return pathPart{name: fmt.Sprintf("customRegex%d", regexCount), isRegex: true}, regexCount, true
    +	return pathPart{name: fmt.Sprintf("customRegex%d", regexCount), value: segment, isRegex: true}, regexCount, true
     }
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion enhances consistency by preserving the original segment value when parsing mux templates, which aligns with the behavior for non-mux segments. While the improvement is sound and beneficial for clarity, it represents a moderate refinement rather than a critical fix.

    Medium

    @edsonmichaque
    Copy link
    Contributor Author

    This PR is replacing #6901 after the refinement of https://tyktech.atlassian.net/browse/TT-7815

    @edsonmichaque edsonmichaque merged commit 2deca99 into master Mar 19, 2025
    33 of 41 checks passed
    @edsonmichaque edsonmichaque deleted the fix/TT-7815/migrate-path-params branch March 19, 2025 09:08
    @edsonmichaque
    Copy link
    Contributor Author

    /release to 5.8.0

    Copy link

    tykbot bot commented Mar 19, 2025

    @edsonmichaque Release branch not found

    @edsonmichaque
    Copy link
    Contributor Author

    /release to release-5.8.0

    Copy link

    tykbot bot commented Mar 19, 2025

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

    tykbot bot pushed a commit that referenced this pull request Mar 19, 2025
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-7815"
    title="TT-7815" target="_blank">TT-7815</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
    <td>Cannot migrate API with endpoints containing path parameter </td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
    <td><a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20DoD_Fail%20ORDER%20BY%20created%20DESC"
    title="DoD_Fail">DoD_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20QA_Fail%20ORDER%20BY%20created%20DESC"
    title="QA_Fail">QA_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Re_open%20ORDER%20BY%20created%20DESC"
    title="Re_open">Re_open</a></td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    <!-- Describe your changes in detail -->
    This PR makes sure that path params are successfully migrated from
    Classic to OAS
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    https://tyktech.atlassian.net/browse/TT-7815
    
    ## 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: -->
    
    - [ ] 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
    - Tests
    
    
    
    ___
    
    ### **Description**
    - Refactored path splitting logic for OAS conversion.
    
    - Introduced helper functions for regex and mux template parsing.
    
    - Added unit tests covering various path parameter scenarios.
    
    - Provided test fixtures for classic to OAS migration.
    
    
    ___
    
    
    
    ### **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>operation.go</strong><dd><code>Enhance path parameter
    migration in OAS operations.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation.go
    
    <li>Added import for regexp and httputil.<br> <li> Refactored splitPath
    with empty path check.<br> <li> Introduced parsePathSegment,
    parseMuxTemplate, and isIdentifier.<br> <li> Improved regex detection
    and parameter naming.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-6d92d2d5b09a5fa7129609bb7cd0d383d015250ec07062b6a93a83257be51fb5">+49/-18</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>operation_test.go</strong><dd><code>Add unit tests for
    splitPath functionality.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation_test.go
    
    <li>Added TestSplitPath covering diverse scenarios.<br> <li> Verified
    correct parsing for simple, regex, and mux templates.<br> <li> Ensured
    empty and root paths are handled.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-cd234db716d6d2edc97c135ef546021c9ab4fa9282d63964bd155d41635cf964">+72/-0</a>&nbsp;
    &nbsp; </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>path_params.yml</strong><dd><code>Add path params test
    fixture for OAS migration.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/testdata/fixtures/path_params.yml
    
    <li>Created YAML fixtures for classic path parameter migration.<br> <li>
    Defined multiple test cases with varied input patterns.<br> <li> Mapped
    expected outputs for both simple and regex parameters.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-0368200f5970a6c4e9bbfa2bb67a2af7568412926cf37d42a65579ef9bea4570">+144/-0</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    (cherry picked from commit 2deca99)
    Copy link

    tykbot bot commented Mar 19, 2025

    @edsonmichaque Succesfully merged PR

    @edsonmichaque
    Copy link
    Contributor Author

    /release to release-5.8

    Copy link

    tykbot bot commented Mar 19, 2025

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

    tykbot bot pushed a commit that referenced this pull request Mar 19, 2025
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-7815"
    title="TT-7815" target="_blank">TT-7815</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
    <td>Cannot migrate API with endpoints containing path parameter </td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
    <td><a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20DoD_Fail%20ORDER%20BY%20created%20DESC"
    title="DoD_Fail">DoD_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20QA_Fail%20ORDER%20BY%20created%20DESC"
    title="QA_Fail">QA_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Re_open%20ORDER%20BY%20created%20DESC"
    title="Re_open">Re_open</a></td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    <!-- Describe your changes in detail -->
    This PR makes sure that path params are successfully migrated from
    Classic to OAS
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    https://tyktech.atlassian.net/browse/TT-7815
    
    ## 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: -->
    
    - [ ] 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
    - Tests
    
    
    
    ___
    
    ### **Description**
    - Refactored path splitting logic for OAS conversion.
    
    - Introduced helper functions for regex and mux template parsing.
    
    - Added unit tests covering various path parameter scenarios.
    
    - Provided test fixtures for classic to OAS migration.
    
    
    ___
    
    
    
    ### **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>operation.go</strong><dd><code>Enhance path parameter
    migration in OAS operations.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation.go
    
    <li>Added import for regexp and httputil.<br> <li> Refactored splitPath
    with empty path check.<br> <li> Introduced parsePathSegment,
    parseMuxTemplate, and isIdentifier.<br> <li> Improved regex detection
    and parameter naming.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-6d92d2d5b09a5fa7129609bb7cd0d383d015250ec07062b6a93a83257be51fb5">+49/-18</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>operation_test.go</strong><dd><code>Add unit tests for
    splitPath functionality.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation_test.go
    
    <li>Added TestSplitPath covering diverse scenarios.<br> <li> Verified
    correct parsing for simple, regex, and mux templates.<br> <li> Ensured
    empty and root paths are handled.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-cd234db716d6d2edc97c135ef546021c9ab4fa9282d63964bd155d41635cf964">+72/-0</a>&nbsp;
    &nbsp; </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>path_params.yml</strong><dd><code>Add path params test
    fixture for OAS migration.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/testdata/fixtures/path_params.yml
    
    <li>Created YAML fixtures for classic path parameter migration.<br> <li>
    Defined multiple test cases with varied input patterns.<br> <li> Mapped
    expected outputs for both simple and regex parameters.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-0368200f5970a6c4e9bbfa2bb67a2af7568412926cf37d42a65579ef9bea4570">+144/-0</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    
    (cherry picked from commit 2deca99)
    Copy link

    tykbot bot commented Mar 19, 2025

    @edsonmichaque Succesfully merged PR

    buger added a commit that referenced this pull request Mar 19, 2025
    …o OAS (#6966)
    
    [TT-7815] ensure path params are migrated to OAS (#6966)
    
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-7815"
    title="TT-7815" target="_blank">TT-7815</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
    <td>Cannot migrate API with endpoints containing path parameter </td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
    <td><a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20DoD_Fail%20ORDER%20BY%20created%20DESC"
    title="DoD_Fail">DoD_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20QA_Fail%20ORDER%20BY%20created%20DESC"
    title="QA_Fail">QA_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Re_open%20ORDER%20BY%20created%20DESC"
    title="Re_open">Re_open</a></td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    <!-- Describe your changes in detail -->
    This PR makes sure that path params are successfully migrated from
    Classic to OAS
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    https://tyktech.atlassian.net/browse/TT-7815
    
    ## 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: -->
    
    - [ ] 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
    - Tests
    
    
    
    ___
    
    ### **Description**
    - Refactored path splitting logic for OAS conversion.
    
    - Introduced helper functions for regex and mux template parsing.
    
    - Added unit tests covering various path parameter scenarios.
    
    - Provided test fixtures for classic to OAS migration.
    
    
    ___
    
    
    
    ### **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>operation.go</strong><dd><code>Enhance path parameter
    migration in OAS operations.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation.go
    
    <li>Added import for regexp and httputil.<br> <li> Refactored splitPath
    with empty path check.<br> <li> Introduced parsePathSegment,
    parseMuxTemplate, and isIdentifier.<br> <li> Improved regex detection
    and parameter naming.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-6d92d2d5b09a5fa7129609bb7cd0d383d015250ec07062b6a93a83257be51fb5">+49/-18</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>operation_test.go</strong><dd><code>Add unit tests for
    splitPath functionality.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation_test.go
    
    <li>Added TestSplitPath covering diverse scenarios.<br> <li> Verified
    correct parsing for simple, regex, and mux templates.<br> <li> Ensured
    empty and root paths are handled.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-cd234db716d6d2edc97c135ef546021c9ab4fa9282d63964bd155d41635cf964">+72/-0</a>&nbsp;
    &nbsp; </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>path_params.yml</strong><dd><code>Add path params test
    fixture for OAS migration.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/testdata/fixtures/path_params.yml
    
    <li>Created YAML fixtures for classic path parameter migration.<br> <li>
    Defined multiple test cases with varied input patterns.<br> <li> Mapped
    expected outputs for both simple and regex parameters.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-0368200f5970a6c4e9bbfa2bb67a2af7568412926cf37d42a65579ef9bea4570">+144/-0</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    buger added a commit that referenced this pull request Mar 19, 2025
    …OAS (#6966)
    
    [TT-7815] ensure path params are migrated to OAS (#6966)
    
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-7815"
    title="TT-7815" target="_blank">TT-7815</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
    <td>Cannot migrate API with endpoints containing path parameter </td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
    <td><a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20DoD_Fail%20ORDER%20BY%20created%20DESC"
    title="DoD_Fail">DoD_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20QA_Fail%20ORDER%20BY%20created%20DESC"
    title="QA_Fail">QA_Fail</a>, <a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Re_open%20ORDER%20BY%20created%20DESC"
    title="Re_open">Re_open</a></td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    <!-- Describe your changes in detail -->
    This PR makes sure that path params are successfully migrated from
    Classic to OAS
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    https://tyktech.atlassian.net/browse/TT-7815
    
    ## 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: -->
    
    - [ ] 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
    - Tests
    
    
    
    ___
    
    ### **Description**
    - Refactored path splitting logic for OAS conversion.
    
    - Introduced helper functions for regex and mux template parsing.
    
    - Added unit tests covering various path parameter scenarios.
    
    - Provided test fixtures for classic to OAS migration.
    
    
    ___
    
    
    
    ### **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>operation.go</strong><dd><code>Enhance path parameter
    migration in OAS operations.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation.go
    
    <li>Added import for regexp and httputil.<br> <li> Refactored splitPath
    with empty path check.<br> <li> Introduced parsePathSegment,
    parseMuxTemplate, and isIdentifier.<br> <li> Improved regex detection
    and parameter naming.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-6d92d2d5b09a5fa7129609bb7cd0d383d015250ec07062b6a93a83257be51fb5">+49/-18</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>operation_test.go</strong><dd><code>Add unit tests for
    splitPath functionality.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/operation_test.go
    
    <li>Added TestSplitPath covering diverse scenarios.<br> <li> Verified
    correct parsing for simple, regex, and mux templates.<br> <li> Ensured
    empty and root paths are handled.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-cd234db716d6d2edc97c135ef546021c9ab4fa9282d63964bd155d41635cf964">+72/-0</a>&nbsp;
    &nbsp; </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>path_params.yml</strong><dd><code>Add path params test
    fixture for OAS migration.</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    apidef/oas/testdata/fixtures/path_params.yml
    
    <li>Created YAML fixtures for classic path parameter migration.<br> <li>
    Defined multiple test cases with varied input patterns.<br> <li> Mapped
    expected outputs for both simple and regex parameters.
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6966/files#diff-0368200f5970a6c4e9bbfa2bb67a2af7568412926cf37d42a65579ef9bea4570">+144/-0</a>&nbsp;
    </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > <details> <summary> Need help?</summary><li>Type <code>/help how to
    ...</code> in the comments thread for any questions about PR-Agent
    usage.</li><li>Check out the <a
    href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a>
    for more information.</li></details>
    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