Skip to content

Conversation

buger
Copy link
Member

@buger buger commented Oct 13, 2025

User description

Refactor error messages in OAS security validation for consistency (#7440)

User description

Updated error messages in the OAS security validation logic to ensure
consistent capitalization. The changes include modifying the error
message for missing components and security schemes, as well as the
error message for missing required security schemes in the components.
This enhances clarity and maintains a uniform style across the error
outputs.


PR Type

Bug fix, Tests


Description

  • Capitalize OAS security error messages

  • Align tests with updated messages


Diagram Walkthrough

flowchart LR
  src["oas.go: security validation errors"] -- "capitalize messages" --> behavior["Runtime error outputs"]
  tests["oas_test.go: expected messages"] -- "update to match" --> behavior
Loading

File Walkthrough

Relevant files
Bug fix
oas.go
Capitalize security validation error messages                       

apidef/oas/oas.go

  • Capitalized error for missing components/security schemes.
  • Capitalized error for missing required security scheme.
+2/-2     
Tests
oas_test.go
Sync tests with capitalized error messages                             

apidef/oas/oas_test.go

  • Update expected error strings to capitalized versions.
  • Keep message format consistent with implementation.
+2/-2     


PR Type

Bug fix, Tests


Description

  • Capitalize OAS security error messages

  • Update tests to match capitalization


Diagram Walkthrough

flowchart LR
  src["oas.go: security validation errors"]
  tests["oas_test.go: expected messages"]
  runtime["Runtime error outputs"]

  src -- "capitalize messages" --> runtime
  tests -- "update expectations" --> runtime
Loading

File Walkthrough

Relevant files
Bug fix
oas.go
Capitalize security validation error strings                         

apidef/oas/oas.go

  • Capitalize missing components/security schemes error.
  • Capitalize missing required security scheme error.
+2/-2     
Tests
oas_test.go
Sync tests with capitalized error messages                             

apidef/oas/oas_test.go

  • Update expected error strings to capitalized.
  • Keep format aligned with implementation.
+2/-2     

…7440)

### **User description**
Updated error messages in the OAS security validation logic to ensure
consistent capitalization. The changes include modifying the error
message for missing components and security schemes, as well as the
error message for missing required security schemes in the components.
This enhances clarity and maintains a uniform style across the error
outputs.


___

### **PR Type**
Bug fix, Tests


___

### **Description**
- Capitalize OAS security error messages

- Align tests with updated messages


___

### Diagram Walkthrough


```mermaid
flowchart LR
  src["oas.go: security validation errors"] -- "capitalize messages" --> behavior["Runtime error outputs"]
  tests["oas_test.go: expected messages"] -- "update to match" --> behavior
```



<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>oas.go</strong><dd><code>Capitalize security validation
error messages</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

apidef/oas/oas.go

<ul><li>Capitalized error for missing components/security schemes.<br>
<li> Capitalized error for missing required security scheme.</ul>


</details>


  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/7440/files#diff-80279b1d59499a41a77ff7a16a6e2c9b9b785a4fd1326c351da6884c867658d7">+2/-2</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>
</table></td></tr><tr><td><strong>Tests</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>oas_test.go</strong><dd><code>Sync tests with
capitalized error messages</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</dd></summary>
<hr>

apidef/oas/oas_test.go

<ul><li>Update expected error strings to capitalized versions.<br> <li>
Keep message format consistent with implementation.</ul>


</details>


  </td>
<td><a
href="https://github.com/TykTechnologies/tyk/pull/7440/files#diff-74029ee88132d30d6478c96a35f8bb2200e0c8e6f42f2c9b147dc6bb7ce74644">+2/-2</a>&nbsp;
&nbsp; &nbsp; </td>

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

</details>

___

(cherry picked from commit fcd1319)
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Consolidate split error string

Avoid splitting a single formatted string literal across lines with concatenation as
it risks unintended spaces/newlines and is harder to maintain. Use a single format
string with explicit space and keep the URL intact. This ensures consistent error
messages and avoids formatting glitches.

apidef/oas/oas.go [507-509]

-errorMsg := fmt.Sprintf("Missing required Security Scheme '%s' in Components.SecuritySchemes. "+
-					"For more information please visit https://swagger.io/specification/#security-requirement-object",
-					key)
+errorMsg := fmt.Sprintf("Missing required Security Scheme '%s' in Components.SecuritySchemes. For more information please visit https://swagger.io/specification/#security-requirement-object", key)
Suggestion importance[1-10]: 5

__

Why: The suggestion improves readability and avoids potential formatting issues by consolidating the split format string, matching the code context accurately. It's a minor improvement with low risk and modest impact.

Low

Copy link
Contributor

API Changes

no api changes detected

Copy link

probelabs bot commented Oct 13, 2025

🔍 Code Analysis Results

This pull request introduces minor but important consistency changes to error messages within the OpenAPI Specification (OAS) security validation logic. The primary goal is to standardize the capitalization of error messages for better clarity and uniformity in system outputs.

Files Changed Analysis

  • apidef/oas/oas.go: (+2, -2) The core logic change is here, where two error message strings in the validateSecurity function have been capitalized.
  • apidef/oas/oas_test.go: (+2, -2) The corresponding unit tests have been updated to expect the new capitalized error messages, ensuring the test suite remains aligned with the code changes.

The changes are minimal and highly localized, affecting only error string formatting.

Architecture & Impact Assessment

  • Accomplishment: This PR standardizes error message formatting for OAS security validation, improving the consistency of user-facing errors and logs.
  • Key Technical Changes: Two errors.New() calls within the validateSecurity function in apidef/oas/oas.go now use capitalized strings.
  • Affected System Components: The change affects the OAS API definition validation component. Any system or user interacting with this validation logic will now see the capitalized error messages upon failure. This primarily impacts developers and API administrators during API definition import or validation.

The following diagram illustrates the relationship between the code and test changes:

flowchart LR
  subgraph "Code"
    oas["oas.go: validateSecurity()"]
  end
  subgraph "Tests"
    oas_test["oas_test.go: TestOAS_ValidateSecurity()"]
  end
  subgraph "Output"
    behavior["Runtime Error Messages"]
  end

  oas -- "Capitalizes error messages" --> behavior
  oas_test -- "Updates expected messages" --> behavior
Loading

Scope Discovery & Context Expansion

The changes are confined to the apidef/oas package. The validateSecurity function is an internal method of the OAS struct, called by the public Validate() method within the same file. The Validate() method is a comprehensive validator for the entire OAS definition.

This means any part of the system that validates an OAS API definition will now exhibit this new error message format for security validation failures. This could include API import processes, CLI tools, or management APIs that accept OAS definitions. The change, while small, will be visible wherever these specific validation errors surface.

Metadata
  • Review Effort: 1 / 5
  • Primary Label: chore

Powered by Visor from Probelabs

Last updated: 2025-10-13T14:22:29.261Z | Triggered by: opened | Commit: 5f14ad2

Copy link

probelabs bot commented Oct 13, 2025

🔍 Code Analysis Results

✅ Security Check Passed

No security issues found – changes LGTM.

✅ Performance Check Passed

No performance issues found – changes LGTM.

✅ Quality Check Passed

No quality issues found – changes LGTM.

Style Issues (2)

Severity Location Issue
🟢 Info apidef/oas/oas.go:502
💡 SuggestionConsider reverting to a lowercase starting letter for the error message to align with common Go style guidelines: ```go return errors.New("no components or security schemes present in OAS") ```
🟢 Info apidef/oas/oas.go:507
💡 SuggestionConsider reverting to a lowercase starting letter for the error message to align with common Go style guidelines: ```go errorMsg := fmt.Sprintf("missing required Security Scheme '%s' in Components.SecuritySchemes. "+ ```

Dependency Issues (1)

Severity Location Issue
🟡 Warning apidef/oas/oas.go:502
Changing the capitalization of an error string can be a breaking change for consumers that programmatically parse error messages. While this change improves consistency, it should be verified that no downstream systems rely on the exact previous (lowercase) error message for their logic.
💡 SuggestionTo create a more stable contract for error handling, consider using sentinel errors (e.g., `var ErrNoSecuritySchemes = errors.New(...)`) that can be checked with `errors.Is()` instead of relying on string comparison. For this change, ensure downstream consumers like `tyk-operator` or UI components are not affected.

✅ Connectivity Check Passed

No connectivity issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2025-10-13T14:22:30.270Z | Triggered by: opened | Commit: 5f14ad2

Copy link

@ilijabojanovic ilijabojanovic merged commit f81d3b8 into release-5.10.0 Oct 13, 2025
44 of 48 checks passed
@ilijabojanovic ilijabojanovic deleted the merge/release-5.10.0/fcd1319ecc1387e8544f127354e2b9b4cab9edd6 branch October 13, 2025 14:44
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