Skip to content

Commit

Permalink
Do not validate xTyk missing OAS APIs on gateway load
Browse files Browse the repository at this point in the history
  • Loading branch information
furkansenharputlu committed Jul 26, 2023
1 parent 808df11 commit 577c104
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions apidef/api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var (
ErrPayloadWithoutTykExtension = errors.New("the payload should contain x-tyk-api-gateway")
ErrAPINotFound = errors.New("API not found")
ErrMissingAPIID = errors.New("missing API ID")
ErrOASNoTykExt = errors.New("OAS API does not include tyk extension")
)

type EndpointMethodMeta struct {
Expand Down
4 changes: 4 additions & 0 deletions gateway/api_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ func (s *APISpec) Release() {
// Validate returns nil if s is a valid spec and an error stating why the spec is not valid.
func (s *APISpec) Validate() error {
if s.IsOAS {
if s.OAS.GetTykExtension() == nil {
return apidef.ErrOASNoTykExt
}

err := s.OAS.Validate(context.Background())
if err != nil {
return err
Expand Down
14 changes: 14 additions & 0 deletions gateway/api_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"text/template"
"time"

"github.com/TykTechnologies/tyk/apidef/oas"

"github.com/TykTechnologies/storage/persistent/model"
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/rpc"
Expand Down Expand Up @@ -1489,3 +1491,15 @@ func Test_LoadAPIsFromRPC(t *testing.T) {
assert.Equal(t, 1, len(apisMap), "expected 0 APIs to be loaded from RPC backup")
})
}

func TestAPISpec_Validate(t *testing.T) {
s := APISpec{APIDefinition: &apidef.APIDefinition{}}

t.Run("oas and xTyk=nil", func(t *testing.T) {
s.IsOAS = true
s.OAS = oas.OAS{}

err := s.Validate()
assert.ErrorIs(t, apidef.ErrOASNoTykExt, err)
})
}

0 comments on commit 577c104

Please sign in to comment.