Skip to content

Commit

Permalink
[TT-13535/TT-13566] Ease up required fields in classic API schema (#6717
Browse files Browse the repository at this point in the history
)

### **User description**
<!-- Provide a general summary of your changes in the Title above -->

* Ease up required fields on classic API definition schema
* Use go:embed for classic api definition schema
<!-- Describe your changes in detail -->

## Related Issue
https://tyktech.atlassian.net/browse/TT-13535
https://tyktech.atlassian.net/browse/TT-13566

## 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**
- Simplified test setup in `api_definitions_test.go` by removing
unnecessary `UpstreamAuth` configuration.
- Enhanced schema management by using `go:embed` to load the JSON schema
from an external file, improving maintainability.
- Added a new `schema.json` file to store the API definition schema
externally, which was previously embedded directly in the Go code.



___



### **Changes walkthrough** 📝
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Tests</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>api_definitions_test.go</strong><dd><code>Simplify test
setup by removing `UpstreamAuth` configuration</code></dd></summary>
<hr>

apidef/api_definitions_test.go

<li>Removed <code>UpstreamAuth</code> configuration from test setup.<br>
<li> Simplified test cases by removing unnecessary fields.<br>


</details>


  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6717/files#diff-6af57c2148f42dce2ee2b93b77d65412024a802ddbd26b63f1d8bd339f4ef760">+0/-22</a>&nbsp;
&nbsp; </td>

</tr>
</table></td></tr><tr><td><strong>Enhancement</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>schema.go</strong><dd><code>Use `go:embed` to load JSON
schema from file</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

apidef/schema.go

<li>Removed inline JSON schema definition.<br> <li> Added
<code>go:embed</code> directive to load schema from external file.<br>


</details>


  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6717/files#diff-f8a37bb370eb6fe20063786a5e6ea3d85a5c91d8e289f0b3e045830c4d322095">+4/-1124</a></td>

</tr>

<tr>
  <td>
    <details>
<summary><strong>schema.json</strong><dd><code>Add external JSON schema
file for API definitions</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; </dd></summary>
<hr>

apidef/schema.json

<li>Added external JSON schema file.<br> <li> Contains API definition
schema previously inlined in Go code.<br>


</details>


  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/6717/files#diff-32c8b876e77d1639afb2d20c37b74ed9e149b72cc7de429def13d3d454e075f3">+1118/-0</a></td>

</tr>
</table></td></tr></tr></tbody></table>

___

> 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull
request to receive relevant information

(cherry picked from commit 6eb5178)
  • Loading branch information
jeffy-mathew authored and Tyk Bot committed Nov 19, 2024
1 parent b318651 commit 70bf6b9
Show file tree
Hide file tree
Showing 3 changed files with 1,122 additions and 1,146 deletions.
22 changes: 0 additions & 22 deletions apidef/api_definitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ func TestSchema(t *testing.T) {
schemaLoader := schema.NewBytesLoader([]byte(Schema))

spec := DummyAPI()
spec.UpstreamAuth = UpstreamAuth{
Enabled: true,
OAuth: UpstreamOAuth{
Enabled: true,
ClientCredentials: ClientCredentials{
ClientAuthData: ClientAuthData{
ClientSecret: "dummy", // workaround to fix schema error
},
},
},
}
goLoader := schema.NewGoLoader(spec)
result, err := schema.Validate(schemaLoader, goLoader)
if err != nil {
Expand Down Expand Up @@ -111,17 +100,6 @@ func TestSchemaGraphqlConfig(t *testing.T) {
schemaLoader := schema.NewBytesLoader([]byte(Schema))

spec := DummyAPI()
spec.UpstreamAuth = UpstreamAuth{
Enabled: true,
OAuth: UpstreamOAuth{
Enabled: true,
ClientCredentials: ClientCredentials{
ClientAuthData: ClientAuthData{
ClientSecret: "dummy", // workaround to fix schema error
},
},
},
}
spec.GraphQL.ExecutionMode = ""

goLoader := schema.NewGoLoader(spec)
Expand Down
Loading

0 comments on commit 70bf6b9

Please sign in to comment.