-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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] Migrate API with endpoints containing path parameter #6901
base: master
Are you sure you want to change the base?
Conversation
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!
Check out this guide to learn more about PR best-practices. |
API Changes no api changes detected |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
… Definition (#6894) <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-7306" title="TT-7306" target="_blank">TT-7306</a></summary> <br /> <table> <tr> <th>Summary</th> <td>[OAS:migration] Migrate Mock Response from Classic API Definition to OAS API Definition</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>-</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 --> This PR adds support for converting `mock responses` between Tyk's classic API format and OAS format. <!-- Describe your changes in detail --> https://tyktech.atlassian.net/browse/TT-7306 <!-- 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. --> <!-- 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: --> - [ ] 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 ___ Enhancement, Tests ___ - Added support for migrating mock responses between Classic and OAS API definitions. - Implemented methods to fill and extract mock responses in OAS middleware. - Enhanced test coverage for mock response handling, including edge cases. - Introduced YAML fixtures for mock response scenarios in OAS and Classic formats. ___ <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 middleware to support mock responses</code> </dd></summary> <hr> apidef/oas/middleware.go <li>Added initialization for <code>Operations</code> in the <code>Fill</code> method.<br> <li> Enhanced <code>Fill</code> method to handle mock responses. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6894/files#diff-992ec7c28d25fd54f6491d295389757705cd114bc869a35cba50d42e548cdc6e">+4/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>operation.go</strong><dd><code>Add mock response handling in OAS operations</code> </dd></summary> <hr> apidef/oas/operation.go <li>Added logic to handle mock response paths and operations.<br> <li> Implemented methods to fill and extract mock responses.<br> <li> Introduced <code>generateOperationID</code> utility for mock responses. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6894/files#diff-6d92d2d5b09a5fa7129609bb7cd0d383d015250ec07062b6a93a83257be51fb5">+139/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>middleware_test.go</strong><dd><code>Add tests for middleware mock response handling</code> </dd></summary> <hr> apidef/oas/middleware_test.go <li>Added test case for mock response extraction and filling.<br> <li> Verified mock response consistency during migration. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6894/files#diff-0af31cb29ae298a6ac3e402b283ab364a6fd793fd04f253ef7c4983234c17bef">+26/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>operation_test.go</strong><dd><code>Add tests for OAS mock response operations</code> </dd></summary> <hr> apidef/oas/operation_test.go <li>Added comprehensive tests for mock response extraction and filling.<br> <li> Covered scenarios for basic, multiple, and disabled mock responses. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6894/files#diff-cd234db716d6d2edc97c135ef546021c9ab4fa9282d63964bd155d41635cf964">+345/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>mock_response.yml</strong><dd><code>Add YAML fixtures for mock response testing</code> </dd></summary> <hr> apidef/oas/testdata/fixtures/mock_response.yml <li>Added YAML fixtures for mock response scenarios.<br> <li> Included cases for OAS to Classic and vice versa.<br> <li> Covered enabled and disabled mock responses. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6894/files#diff-c7c72a9398d68abedf9238cc2a9606521069e13034f921e7a979d859e0559c8d">+121/-0</a> </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> --------- Co-authored-by: Jeffy Mathew <[email protected]>
…lt (#6905) ### **User description** <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-8876" title="TT-8876" target="_blank">TT-8876</a></summary> <br /> <table> <tr> <th>Summary</th> <td>[Operator-support] Change defaults for "allow explicit policy ID" and "duplicate slugs"</td> </tr> <tr> <th>Type</th> <td> <img alt="Story" src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10315?size=medium" /> Story </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%20R4_24_candidate%20ORDER%20BY%20created%20DESC" title="R4_24_candidate">R4_24_candidate</a></td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- Set "policies.allow_explicity_policy_id " to true to allow compatibility with tyk-operator and tyk-sync with the default config TASK: https://tyktech.atlassian.net/browse/TT-8876 <!-- Provide a general summary of your changes in the Title above --> ## Description <!-- Describe your changes in detail --> ## 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. --> ## 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** Enhancement ___ ### **Description** - Set `policies.allow_explicit_policy_id` to true by default. - Updated `tyk.conf.example` for compatibility with tyk-operator and tyk-sync. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Configuration changes</strong></td><td><table> <tr> <td> <details> <summary><strong>tyk.conf.example</strong><dd><code>Update default configuration for explicit policy ID</code> </dd></summary> <hr> tyk.conf.example <li>Added <code>allow_explicit_policy_id</code> with a default value of true.<br> <li> Ensured compatibility with tyk-operator and tyk-sync. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6905/files#diff-a6736b4b3cda1ee503675d7b725f6138f4eb83d7145f3afecf6087d219f2b23a">+2/-1</a> </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>
|
}, | ||
{ | ||
name: "path with direct regex", | ||
path: "/files/{.*}/download", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is invalid by mux; read through httputil/mux* ; i feel a significant part is already implemented in httputil, maybe needs extending (mux.go, we already have logic for /*
and /*/
which equals this patch matching case.
With {.*}
- this mux tag is not a valid input, while {_}
or {_:.*}
would be. Is this a case we need to cover? Technically it would "work" in mux because .*
would be treated as a name
, using the default parameter regex. customRegex in this case should ignore {} and be isRegex=false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@titpetric qq: IsMuxTemplate is checking only for existence of curly braces which are opened and closed. And if it is returning true, whatever is inside {}
is replaced with ([^/]+)
.
This means {id:[a-z]}
is also replaced with ([^/]+)
, is it expected?
}, | ||
{ | ||
name: "invalid path - unclosed brace", | ||
path: "/api/users/{id", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather you extend some existing tests for httputil.mux with these; that behavior is correct, and can extend the internal apis and existing tests for an overview.
User description
TT-7815
Description
Related Issue
https://tyktech.atlassian.net/browse/TT-7815
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Bug fix, Tests
Description
Enhanced path parameter handling in API definitions.
Added support for named and regex-based path parameters.
Refactored
splitPath
logic for improved clarity and functionality.Introduced comprehensive unit tests for path parsing and validation.
Changes walkthrough 📝
operation.go
Refactor path parsing and parameter handling logic
apidef/oas/operation.go
isParam
field topathPart
struct.splitPath
to handle named and regex-based parameters.isRegex
and introducedisParamName
for validation.buildPath
to support new parameter types.operation_test.go
Add unit tests for path parsing and validation
apidef/oas/operation_test.go
splitPath
andpathPart.String
.TestOAS_RegexPaths
to validate parameter extraction.