-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Merging to release-5.8: [TT-5588] [OAS] gateway apiKey import generates unnecessary object (#7270) #7291
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
Merging to release-5.8: [TT-5588] [OAS] gateway apiKey import generates unnecessary object (#7270) #7291
Conversation
…7270) ### **User description** <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-5588" title="TT-5588" target="_blank">TT-5588</a></summary> <br /> <table> <tr> <th>Summary</th> <td>[OAS] gateway apiKey import generates unnecessary object</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%20codilime_refined%20ORDER%20BY%20created%20DESC" title="codilime_refined">codilime_refined</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 The header object is unnecessarily generated during creation of a Tyk OAS API by importing an OpenAPI description with security scheme defined. ## 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: --> - [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, Tests ___ ### **Description** - Prevent `AuthSources` from being serialized in `Token` struct - Update JSON serialization tags to exclude `AuthSources` - Add test to verify `AuthSources` are not serialized - Ensure unmarshalled `Token` omits `AuthSources` fields ___ ### Diagram Walkthrough ```mermaid flowchart LR TokenStruct["Token struct"] Serialization["JSON Serialization"] TestCase["Test: AuthSources not serialized"] TokenStruct -- "exclude AuthSources from JSON" --> Serialization Serialization -- "verify exclusion" --> TestCase ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>security.go</strong><dd><code>Exclude AuthSources from Token JSON serialization</code> </dd></summary> <hr> apidef/oas/security.go <ul><li>Changed JSON struct tag for <code>AuthSources</code> to exclude from serialization<br> <li> Prevents <code>AuthSources</code> from appearing in serialized JSON output</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7270/files#diff-15e7d47137452ca4f3f6139aa8c007cdb426152c41846f712f8bf5dfb607afcc">+1/-1</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>security_test.go</strong><dd><code>Add test for non-serialization of AuthSources in Token</code> </dd></summary> <hr> apidef/oas/security_test.go <ul><li>Added test to ensure <code>AuthSources</code> fields are not serialized<br> <li> Verifies that <code>Query</code>, <code>Header</code>, and <code>Cookie</code> are nil after serialization <br>round-trip</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7270/files#diff-5184167309db0462243e424baca87b5bb668962d8cc1076629fdcf11f00487e5">+15/-0</a> </td> </tr> </table></td></tr></tr></tbody></table> </details> ___ (cherry picked from commit 8b4fa8e)
API Changes --- prev.txt 2025-08-11 09:23:36.540342635 +0000
+++ current.txt 2025-08-11 09:23:32.046325981 +0000
@@ -4505,7 +4505,7 @@
Enabled bool `bson:"enabled" json:"enabled"` // required
// AuthSources contains the configuration for authentication sources.
- AuthSources `bson:",inline" json:",inline"`
+ AuthSources `bson:",inline" json:"-"`
// EnableClientCertificate allows to create dynamic keys based on certificates.
// |
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
… generates unnecessary object (#7270)" (#7298) ### **User description** <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-5588" title="TT-5588" target="_blank">TT-5588</a></summary> <br /> <table> <tr> <th>Summary</th> <td>[OAS] gateway apiKey import generates unnecessary object</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%20codilime_refined%20ORDER%20BY%20created%20DESC" title="codilime_refined">codilime_refined</a></td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- Reverts #7291 ___ ### **PR Type** Bug fix, Tests ___ ### **Description** Revert exclusion of `AuthSources` from JSON. Restore JSON inline serialization for `Token.AuthSources`. Remove test asserting non-serialization of `AuthSources`. Keep token fill logic and assertions intact. ___ ### Diagram Walkthrough ```mermaid flowchart LR Token["Token struct"] JSONTag["JSON tag for AuthSources"] Tests["Security tests"] Token -- "AuthSources json:',inline'" --> JSONTag Tests -- "remove non-serialization round-trip" --> JSONTag ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>security.go</strong><dd><code>Restore inline JSON serialization for AuthSources</code> </dd></summary> <hr> apidef/oas/security.go <ul><li>Change <code>Token.AuthSources</code> tag to <code>json:",inline"</code>.<br> <li> Re-enable JSON serialization of embedded <code>AuthSources</code>.</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7298/files#diff-15e7d47137452ca4f3f6139aa8c007cdb426152c41846f712f8bf5dfb607afcc">+1/-1</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>security_test.go</strong><dd><code>Remove test asserting AuthSources non-serialization</code> </dd></summary> <hr> apidef/oas/security_test.go <ul><li>Remove JSON round-trip test for <code>AuthSources</code>.<br> <li> Drop <code>encoding/json</code> import no longer used.</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7298/files#diff-5184167309db0462243e424baca87b5bb668962d8cc1076629fdcf11f00487e5">+0/-15</a> </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
User description
TT-5588 [OAS] gateway apiKey import generates unnecessary object (#7270)
User description
TT-5588
Description
The header object is unnecessarily generated during creation of a Tyk
OAS API by importing an OpenAPI description with security scheme
defined.
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
functionality to change)
coverage to functionality)
Checklist
why it's required
explained why
PR Type
Bug fix, Tests
Description
Prevent
AuthSources
from being serialized inToken
structUpdate JSON serialization tags to exclude
AuthSources
Add test to verify
AuthSources
are not serializedEnsure unmarshalled
Token
omitsAuthSources
fieldsDiagram Walkthrough
File Walkthrough
security.go
Exclude AuthSources from Token JSON serialization
apidef/oas/security.go
AuthSources
to exclude from serializationAuthSources
from appearing in serialized JSON outputsecurity_test.go
Add test for non-serialization of AuthSources in Token
apidef/oas/security_test.go
AuthSources
fields are not serializedQuery
,Header
, andCookie
are nil after serializationround-trip
PR Type
Bug fix, Tests
Description
Stop serializing Token.AuthSources to JSON
Update struct tag to json:"-"
Add test validating non-serialization
Ensure round-trip omits AuthSources fields
Diagram Walkthrough
File Walkthrough
security.go
Exclude AuthSources from Token JSON
apidef/oas/security.go
Token.AuthSources
JSON tag tojson:"-"
.security_test.go
Test non-serialization of AuthSources
apidef/oas/security_test.go
Token
.Query
,Header
,Cookie
remain nil after marshal/unmarshal.encoding/json
for serialization.