Skip to content

Commit

Permalink
Reflect OAS contract change of MethodTransform to TransformRequestMet…
Browse files Browse the repository at this point in the history
…hod (TykTechnologies#3835)

(cherry picked from commit d4fd2c6)
  • Loading branch information
furkansenharputlu authored and Tyk Bot committed Jan 11, 2022
1 parent fc4e9ea commit 58d523b
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions apidef/oas/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (ps Paths) Fill(ep apidef.ExtendedPathsSet) {
ps.fillAllowance(ep.BlackList, block)
ps.fillAllowance(ep.Ignored, ignoreAuthentication)
ps.fillMockResponse(ep.MockResponse)
ps.fillMethodTransform(ep.MethodTransforms)
ps.fillTransformRequestMethod(ep.MethodTransforms)
ps.fillCache(ep.AdvanceCacheConfig)
}

Expand Down Expand Up @@ -238,20 +238,20 @@ func (ps Paths) fillMockResponse(mockMetas []apidef.MockResponseMeta) {
}
}

func (ps Paths) fillMethodTransform(metas []apidef.MethodTransformMeta) {
func (ps Paths) fillTransformRequestMethod(metas []apidef.MethodTransformMeta) {
for _, meta := range metas {
if _, ok := ps[meta.Path]; !ok {
ps[meta.Path] = &Path{}
}

plugins := ps[meta.Path].getMethod(meta.Method)
if plugins.MethodTransform == nil {
plugins.MethodTransform = &MethodTransform{}
if plugins.TransformRequestMethod == nil {
plugins.TransformRequestMethod = &TransformRequestMethod{}
}

plugins.MethodTransform.Fill(meta)
if ShouldOmit(plugins.MethodTransform) {
plugins.MethodTransform = nil
plugins.TransformRequestMethod.Fill(meta)
if ShouldOmit(plugins.TransformRequestMethod) {
plugins.TransformRequestMethod = nil
}
}
}
Expand Down Expand Up @@ -416,17 +416,17 @@ type Plugins struct {
IgnoreAuthentication *Allowance `bson:"ignoreAuthentication,omitempty" json:"ignoreAuthentication,omitempty"`
// MockResponse allows you to mock responses for an API endpoint.
MockResponse *MockResponse `bson:"mockResponse,omitempty" json:"mockResponse,omitempty"`
// MethodTransform allows you to transform the method of a request.
MethodTransform *MethodTransform `bson:"methodTransform,omitempty" json:"methodTransform,omitempty"`
Cache *CachePlugin `bson:"cache,omitempty" json:"cache,omitempty"`
// TransformRequestMethod allows you to transform the method of a request.
TransformRequestMethod *TransformRequestMethod `bson:"transformRequestMethod,omitempty" json:"transformRequestMethod,omitempty"`
Cache *CachePlugin `bson:"cache,omitempty" json:"cache,omitempty"`
}

func (p *Plugins) ExtractTo(ep *apidef.ExtendedPathsSet, path string, method string) {
p.extractAllowanceTo(ep, path, method, allow)
p.extractAllowanceTo(ep, path, method, block)
p.extractAllowanceTo(ep, path, method, ignoreAuthentication)
p.extractMockResponseTo(ep, path, method)
p.extractMethodTransformTo(ep, path, method)
p.extractTransformRequestMethodTo(ep, path, method)
p.extractCacheTo(ep, path, method)
}

Expand Down Expand Up @@ -462,13 +462,13 @@ func (p *Plugins) extractMockResponseTo(ep *apidef.ExtendedPathsSet, path string
ep.MockResponse = append(ep.MockResponse, mockMeta)
}

func (p *Plugins) extractMethodTransformTo(ep *apidef.ExtendedPathsSet, path string, method string) {
if p.MethodTransform == nil {
func (p *Plugins) extractTransformRequestMethodTo(ep *apidef.ExtendedPathsSet, path string, method string) {
if p.TransformRequestMethod == nil {
return
}

meta := apidef.MethodTransformMeta{Path: path, Method: method}
p.MethodTransform.ExtractTo(&meta)
p.TransformRequestMethod.ExtractTo(&meta)
ep.MethodTransforms = append(ep.MethodTransforms, meta)
}

Expand Down Expand Up @@ -548,21 +548,21 @@ type Header struct {
Value string `bson:"value" json:"value"`
}

type MethodTransform struct {
type TransformRequestMethod struct {
// Enabled enables Method Transform for the given path and method.
Enabled bool `bson:"enabled" json:"enabled"`
// ToMethod is the http method value to which the method of an incoming request will be transformed.
ToMethod string `bson:"toMethod" json:"toMethod"`
}

func (mt *MethodTransform) Fill(meta apidef.MethodTransformMeta) {
mt.Enabled = !meta.Disabled
mt.ToMethod = meta.ToMethod
func (tm *TransformRequestMethod) Fill(meta apidef.MethodTransformMeta) {
tm.Enabled = !meta.Disabled
tm.ToMethod = meta.ToMethod
}

func (mt *MethodTransform) ExtractTo(meta *apidef.MethodTransformMeta) {
meta.Disabled = !mt.Enabled
meta.ToMethod = mt.ToMethod
func (tm *TransformRequestMethod) ExtractTo(meta *apidef.MethodTransformMeta) {
meta.Disabled = !tm.Enabled
meta.ToMethod = tm.ToMethod
}

type CachePlugin struct {
Expand Down

0 comments on commit 58d523b

Please sign in to comment.