Skip to content

Commit

Permalink
Merging to release-5.2: [TT-10358] Add fallback to default version OA…
Browse files Browse the repository at this point in the history
…S support (#5679)

[TT-10358] Add fallback to default version OAS support (#5679)

parent ticket: https://tyktech.atlassian.net/browse/TT-9901
subticket: https://tyktech.atlassian.net/browse/TT-10358
  • Loading branch information
buger authored Oct 30, 2023
1 parent 3df352b commit d11a5c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion apidef/oas/oas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ func TestOAS_ExtractTo_ResetAPIDefinition(t *testing.T) {
"APIDefinition.RequestSigning.HeaderList[0]",
"APIDefinition.RequestSigning.CertificateId",
"APIDefinition.RequestSigning.SignatureHeader",
"APIDefinition.VersionDefinition.FallbackToDefault",
"APIDefinition.VersionData.Versions[0].ExtendedPaths.TransformJQ[0].Filter",
"APIDefinition.VersionData.Versions[0].ExtendedPaths.TransformJQ[0].Path",
"APIDefinition.VersionData.Versions[0].ExtendedPaths.TransformJQ[0].Method",
Expand Down
6 changes: 6 additions & 0 deletions apidef/oas/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ type Versioning struct {
Versions []VersionToID `bson:"versions" json:"versions"` // required
// StripVersioningData is a boolean flag, if set to `true`, the API responses will be stripped of versioning data.
StripVersioningData bool `bson:"stripVersioningData,omitempty" json:"stripVersioningData,omitempty"`
// FallbackToDefault controls the behaviour of Tyk when a versioned API is called with a nonexistent version name.
// If set to `true` then the default API version will be invoked; if set to `false` Tyk will return an HTTP 404
// `This API version does not seem to exist` error in this scenario.
FallbackToDefault bool `bson:"fallbackToDefault,omitempty" json:"fallbackToDefault,omitempty"`
}

// Fill fills *Versioning from apidef.APIDefinition.
Expand All @@ -190,6 +194,7 @@ func (v *Versioning) Fill(api apidef.APIDefinition) {
}

v.StripVersioningData = api.VersionDefinition.StripVersioningData
v.FallbackToDefault = api.VersionDefinition.FallbackToDefault
}

// ExtractTo extracts *Versioning into *apidef.APIDefinition.
Expand All @@ -210,6 +215,7 @@ func (v *Versioning) ExtractTo(api *apidef.APIDefinition) {
}

api.VersionDefinition.StripVersioningData = v.StripVersioningData
api.VersionDefinition.FallbackToDefault = v.FallbackToDefault
}

// VersionToID contains a single mapping from a version name into an API ID.
Expand Down
4 changes: 4 additions & 0 deletions apidef/oas/schema/x-tyk-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Versions contains a list of versions that map to individual API IDs.
**Field: `stripVersioningData` (`boolean`)**
StripVersioningData is a boolean flag, if set to `true`, the API responses will be stripped of versioning data.

**Field: `fallbackToDefault` (`boolean`)**
FallbackToDefault controls the behaviour of Tyk when a versioned API is called with a nonexistent version name.
If set to `true` then the default API version will be invoked; if set to `false` Tyk will return an HTTP 404 `This API version does not seem to exist` error in this scenario.


### **VersionToID**

Expand Down

0 comments on commit d11a5c5

Please sign in to comment.