Skip to content

[TT-11048] Regex on endpoint list issue poc #7266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apidef/oas/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func (i *Internal) ExtractTo(meta *apidef.InternalMeta) {
meta.Disabled = !i.Enabled
}

func (s *OAS) fillInternal(metas []apidef.InternalMeta) {
func (s *OAS) fillInternal(metas []apidef.InternalMeta, opt fillOptions) {
for _, meta := range metas {
operationID := s.getOperationID(meta.Path, meta.Method)
operationID := s.ensureOperationId(meta.Path, meta.Method, opt)
operation := s.GetTykExtension().getOperation(operationID)

if operation.Internal == nil {
Expand Down
38 changes: 36 additions & 2 deletions apidef/oas/oas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/TykTechnologies/tyk/common/option"
"github.com/samber/lo"
"strings"

Expand Down Expand Up @@ -69,15 +70,19 @@ func (s *OAS) MarshalJSON() ([]byte, error) {
}

// Fill fills *OAS definition from apidef.APIDefinition.
func (s *OAS) Fill(api apidef.APIDefinition) {
func (s *OAS) Fill(api apidef.APIDefinition, opts ...FillOption) {
opt := option.New(opts).Build(fillOptions{
strategy: regexTransform, // transform regex by default
})

xTykAPIGateway := s.GetTykExtension()
if xTykAPIGateway == nil {
xTykAPIGateway = &XTykAPIGateway{}
s.SetTykExtension(xTykAPIGateway)
}

xTykAPIGateway.Fill(api)
s.fillPathsAndOperations(api.VersionData.Versions[Main].ExtendedPaths)
s.fillPathsAndOperations(api.VersionData.Versions[Main].ExtendedPaths, *opt)
s.fillSecurity(api)

if ShouldOmit(xTykAPIGateway) {
Expand Down Expand Up @@ -595,3 +600,32 @@ func GetValidationOptionsFromConfig(oasConfig config.OASConfig) []openapi3.Valid

return opts
}

// classicToOasStrategy transform strategy
type classicToOasStrategy int

const (
unknownTransform classicToOasStrategy = iota
regexTransform
regexIgnoreTransform
)

type fillOptions struct {
strategy classicToOasStrategy
}

// FillOption optional parameter for Fill method.
type FillOption = option.Option[fillOptions]

func defaultFillOptions() fillOptions {
return fillOptions{
strategy: regexTransform,
}
}

// WithOmitTranslate omits regex-based endpoints translation during classic to oas translation.
func WithOmitTranslate() option.Option[fillOptions] {
return func(o *fillOptions) {
o.strategy = regexIgnoreTransform
}
}
Loading
Loading