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 55c1081 commit 9b2974c
Show file tree
Hide file tree
Showing 3 changed files with 18 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")
ErrOASAPINotHaveXTyk = 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.ErrOASAPINotHaveXTyk
}

err := s.OAS.Validate(context.Background())
if err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions gateway/api_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/TykTechnologies/tyk/apidef/oas"
"io"
"io/ioutil"
"net"
Expand Down Expand Up @@ -1489,3 +1490,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.ErrOASAPINotHaveXTyk, err)
})
}

0 comments on commit 9b2974c

Please sign in to comment.