You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merging to release-5.8: [TT-11387] Unhelpful error messages in UI when creating APIs via OpenAPI import (#7067)
[TT-11387] Unhelpful error messages in UI when creating APIs via OpenAPI import (#7067)
### **User description**
<details open>
<summary><a href="https://tyktech.atlassian.net/browse/TT-11387"
title="TT-11387" target="_blank">TT-11387</a></summary>
<br />
<table>
<tr>
<th>Summary</th>
<td>Unhelpful error messages in UI when creating APIs via OpenAPI
import</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
When importing an OpenAPI Document into Tyk, users encounter cryptic
error messages that don't provide clear guidance on how to resolve the
issues. This is particularly problematic for the "servers object is
empty in OAS" error, which occurs when importing an OpenAPI Document
without a servers section. Users aren't informed that they can use the
Custom Upstream URL option as an alternative to modifying their OpenAPI
Document.
## 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**
- Improved error messages for OpenAPI import failures.
- Updated error constants to provide actionable guidance.
- Enhanced test cases to check for new error messages.
- Clarified user instructions for missing or invalid OAS fields.
___
### **Changes walkthrough** 📝
<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>default.go</strong><dd><code>Enhanced and clarified OAS
import error messages</code>
</dd></summary>
<hr>
apidef/oas/default.go
<li>Replaced vague error messages with detailed, user-friendly
<br>explanations.<br> <li> Updated error constants to suggest actionable
next steps.<br> <li> Clarified error context for missing or invalid OAS
fields.<br> <li> Adjusted invalid server URL format message for clarity.
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/7067/files#diff-83c3a85bdd05785178ee519b05b1fe2008435dc4ae9448d72b080b5f67c491ad">+5/-5</a>
</td>
</tr>
</table></td></tr><tr><td><strong>Tests</strong></td><td><table>
<tr>
<td>
<details>
<summary><strong>api_test.go</strong><dd><code>Updated tests for
improved OAS error messages</code>
</dd></summary>
<hr>
gateway/api_test.go
<li>Updated test assertions to match new, more informative error
messages.<br> <li> Ensured tests check for actionable guidance in error
responses.<br> <li> Improved test coverage for OAS import error
scenarios.
</details>
</td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/7067/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+7/-3</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>
errInvalidServerURL=errors.New("error validating servers entry in OAS")
25
+
errEmptyServersObject=errors.New("The ‘servers’ object is empty in your OAS. You can either add a ‘servers’ section to your OpenAPI description or provide a Custom Upstream URL in the manual configuration options below.")
26
+
errEmptySecurityObject=errors.New("The ‘security’ object is empty in your OAS. When enabling authentication, your OpenAPI description must include a ‘security’ object that defines the authentication schemes. You can either add a ‘security’ object or disable authentication in the API settings.")
27
+
errInvalidUpstreamURL=errors.New("The manually configured upstream URL is not valid. The URL must be absolute and properly formatted (e.g. https://example.com). Please check the URL format and try again.")
28
+
errInvalidServerURL=errors.New("The first entry in the ‘servers’ object of your OAS in not valid. The URL must be absolute and properly formatted (e.g. https://example.com).")
BodyMatch: `The manually configured upstream URL is not valid. The URL must be absolute and properly formatted \(e.g. https://example.com\). Please check the URL format and try again.`,
BodyMatch: `The manually configured upstream URL is not valid. The URL must be absolute and properly formatted \(e.g. https://example.com\). Please check the URL format and try again.`,
3523
3526
})
3524
3527
})
3525
3528
3526
3529
t.Run("missing upstream URL", func(t*testing.T) {
3527
3530
oasAPI:=oasCopy(false, func(t*openapi3.T) {
3528
3531
t.Servers= openapi3.Servers{}
3529
3532
})
3530
-
_=testImportOAS(t, ts, test.TestCase{Code: http.StatusBadRequest, Data: oasAPI, AdminAuth: true, BodyMatch: "servers object is empty in OAS"})
BodyMatch: "The ‘servers’ object is empty in your OAS. You can either add a ‘servers’ section to your OpenAPI description or provide a Custom Upstream URL in the manual configuration options below."})
3531
3535
})
3532
3536
3533
3537
t.Run("success without config query params, no tyk ext", func(t*testing.T) {
0 commit comments