Skip to content

[TT-12339] Rename OAS enforceTimeout field timeout to duration#8278

Merged
jay-deshmukh merged 6 commits into
masterfrom
TT-12339
Jun 10, 2026
Merged

[TT-12339] Rename OAS enforceTimeout field timeout to duration#8278
jay-deshmukh merged 6 commits into
masterfrom
TT-12339

Conversation

@jay-deshmukh

@jay-deshmukh jay-deshmukh commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

The sub-second enforced-timeout field added for TT-12339 was serialized as timeout. Rename it to duration to match the intended API contract:

x-tyk-api-gateway:
  middleware:
    operations:
      <operationId>:
        enforceTimeout:
          enabled: true
          duration: 100ms

Changes:

  • apidef/oas/middleware.go: rename EnforceTimeout.Timeout -> Duration and its json/bson tags timeout -> duration; update the Value deprecation note and the Fill/ExtractTo mappings.
  • apidef/oas/schema/x-tyk-api-gateway.json and .strict.json: rename the X-Tyk-EnforceTimeout timeout property to duration.
  • Update references in middleware_test.go, linter_test.go and operation_test.go.

Ticket Details

TT-12339
Status Ready for Testing
Summary [BE] Implement sub-second timeout for the Enforced Timeout middleware

Generated at: 2026-06-05 10:07:56

The sub-second enforced-timeout field added for TT-12339 was serialized as
`timeout`. Rename it to `duration` to match the intended API contract:

    x-tyk-api-gateway:
      middleware:
        operations:
          <operationId>:
            enforceTimeout:
              enabled: true
              duration: 100ms

Changes:
- apidef/oas/middleware.go: rename EnforceTimeout.Timeout -> Duration and its
  json/bson tags `timeout` -> `duration`; update the Value deprecation note
  and the Fill/ExtractTo mappings.
- apidef/oas/schema/x-tyk-api-gateway.json and .strict.json: rename the
  X-Tyk-EnforceTimeout `timeout` property to `duration`.
- Update references in middleware_test.go, linter_test.go and operation_test.go.
@probelabs

probelabs Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This pull request renames the timeout field to duration within the enforceTimeout middleware configuration for OpenAPI (OAS) definitions. This change improves the clarity of the API contract, as the field supports sub-second values (e.g., "100ms"), and duration is a more descriptive name.

Files Changed Analysis

The changes are a consistent rename operation across 5 files within the apidef/oas package, with an equal number of additions and deletions (19).

  • apidef/oas/middleware.go: The core change is here. The EnforceTimeout.Timeout struct field is renamed to Duration, and its json and bson serialization tags are updated accordingly. The Fill and ExtractTo methods, which handle mapping to the classic API definition, are also adjusted.
  • apidef/oas/schema/*.json: Both the standard and strict JSON schemas for the x-tyk-api-gateway extension are updated, renaming the timeout property to duration.
  • apidef/oas/*_test.go: References in linter_test.go and middleware_test.go are updated to use the new Duration field, ensuring continued test coverage.

Architecture & Impact Assessment

  • What this PR accomplishes: It enhances API clarity and developer experience by using a more intuitive field name for a value that accepts time duration strings.
  • Key technical changes introduced: A Go struct field and its serialization tags were renamed, which in turn modifies the public-facing JSON schema for the x-tyk-api-gateway extension.
  • Affected system components: This is a breaking change for users who define APIs via OAS and utilize the enforceTimeout middleware. They will be required to update their API definition files to use the new duration field. The impact is confined to the OAS definition processing layer.

Data Transformation Flow

graph TD
    subgraph "OAS API Definition (User Input)"
        A["x-tyk-api-gateway:<br/>  enforceTimeout:<br/>    duration: 100ms"]
    end

    subgraph "Tyk Gateway (Go Code)"
        B[&quot;struct EnforceTimeout &#123;<br/>  Duration tyktime.ReadableDuration json:&quot;duration&quot;<br/>&#125;&quot;r/>&#125;&quot;]
    end

    subgraph "Tyk Classic API Definition (Internal)"
        C["apidef.HardTimeoutMeta &#123;<br/>  TimeoutDuration: 100ms<br/>&#125;"]
    end

    A --|JSON Unmarshal|--> B
    B --|ExtractTo|--> C

Loading

Scope Discovery & Context Expansion

The scope of this change is well-contained within the apidef/oas package. However, the impact is external, as it introduces a breaking change to the x-tyk-api-gateway extension's API contract. This will require updates to user-facing documentation and must be clearly communicated in release notes to avoid disruption for users of this feature.

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

Powered by Visor from Probelabs

Last updated: 2026-06-10T04:11:01.735Z | Triggered by: pr_updated | Commit: 1aebfa8

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs

probelabs Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
\n\n

Architecture Issues (1)

Severity Location Issue
🟡 Warning apidef/oas/middleware.go:1321
The deprecated `Value` field lacks an `omitempty` tag, which could lead to it being serialized even when it's zero and `Duration` is the primary field being used. This can create unnecessary noise in the serialized output.
💡 SuggestionAdd an `omitempty` tag to the `Value` field's JSON and BSON struct tags to prevent it from being serialized when its value is zero. This aligns it with the behavior of the new `Duration` field and keeps the serialized output cleaner, especially when the deprecated field is not in use.

✅ Performance Check Passed

No performance issues found – changes LGTM.

✅ Quality Check Passed

No quality issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2026-06-10T04:10:49.317Z | Triggered by: pr_updated | Commit: 1aebfa8

💡 TIP: You can chat with Visor using /visor ask <your question>

@vladzabolotnyi vladzabolotnyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the TT-12339 is included to 5.14.0 so we don't have any backward compat problems. Well done 💪

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🎯 Recommended Merge Targets

Based on JIRA ticket TT-12339: [BE] Implement sub-second timeout for the Enforced Timeout middleware

Fix Version: Tyk 5.14.0

⚠️ Warning: Expected release branches not found in repository

Required:

  • master - No matching release branches found. Fix will be included in future releases.

📋 Workflow

  1. Merge this PR to master first

@bojank93

bojank93 commented Jun 9, 2026

Copy link
Copy Markdown

LGTM.

@jay-deshmukh can you please fix the CI and then proceed with merging this PR?

@jay-deshmukh
jay-deshmukh enabled auto-merge (squash) June 9, 2026 12:20
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Jira Linter Failed

Commit: 1aebfa8
Failed at: 2026-06-10 04:09:46 UTC

The Jira linter failed to validate your PR. Please check the error details below:

🔍 Click to view error details
failed to get Jira issue: failed to fetch Jira issue TT-12339: Issue does not exist or you do not have permission to see it.: request failed. Please analyze the request body for more details. Status code: 404

Next Steps

  • Ensure your branch name contains a valid Jira ticket ID (e.g., ABC-123)
  • Verify your PR title matches the branch's Jira ticket ID
  • Check that the Jira ticket exists and is accessible

This comment will be automatically deleted once the linter passes.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@jay-deshmukh
jay-deshmukh merged commit dc6ce10 into master Jun 10, 2026
52 of 55 checks passed
@jay-deshmukh
jay-deshmukh deleted the TT-12339 branch June 10, 2026 05:31
mativm02 added a commit that referenced this pull request Jun 19, 2026
## Summary

Renames the granular enforced-timeout field on the **Tyk Classic** API
definition from `timeout_duration` to `duration`, so it matches the Tyk
OAS field name (`enforceTimeout.duration`). Closes the Classic half of
the `duration` rename agreed during TT-12339 (OAS was done in #8278).

Ticket: **TT-17515** (parent TT-12339).

## What changed

Minimal **wire-tag rename only** — the Go field name
`HardTimeoutMeta.TimeoutDuration` is unchanged, so the enforcement path
(`gateway/reverse_proxy.go`) and the negative-value validator
(`apidef/validator.go`) are untouched.

- `apidef/api_definitions.go` — `HardTimeoutMeta.TimeoutDuration`
json/bson tag `timeout_duration` → `duration`
- `apidef/schema.json` — `hard_timeouts[]` item property renamed (format
pattern preserved)
- `apidef/oas/middleware.go` — doc-comment reference updated
- `apidef/api_definitions_test.go` — new
`TestHardTimeoutMeta_DurationWireTag` (marshal/unmarshal/omitempty)

## Out of scope (by product decision)

- **No round-up for Classic.** Setting only `duration` is *not* folded
into the legacy whole-second `timeout` field. This was a deliberate
omission (agreed with product) — a Classic API created with only
`duration` has no enforced timeout on an older Gateway unless `timeout`
is also set. This is an accepted, documented limitation; users wanting
sub-second precision are steered to Tyk OAS.
- **No new backend validation.** Negatives still rejected (existing
behaviour); empty/`0`/`0ms` remain valid (no timeout).

## Compatibility

- **Backwards compatible:** the legacy whole-second `timeout` field is
untouched; existing APIs keep working on upgrade and downgrade.
- **No JSON alias for the old key.** The pre-release `timeout_duration`
name was **never released**, so there is nothing to migrate — any
definition still carrying that key would deserialize the granular value
as zero. This rename is safe on that premise.

## Testing

- `go test ./apidef/ -run 'TestSchema$|HardTimeoutMeta_DurationWireTag'
-count=1` ✅ (incl. struct-vs-embedded-schema validation)
- `go test ./gateway/ -run TestTimeoutPrioritization -count=1` ✅
(sub-second + legacy enforcement)

## Downstream

Dashboard support is in tyk-analytics-ui (Classic designer note) + a
`tyk` dependency bump in tyk-analytics that lands after this merges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants