Skip to content

Commit

Permalink
move helper code
Browse files Browse the repository at this point in the history
  • Loading branch information
pvormste committed Jan 13, 2025
1 parent 89134e6 commit 1ccf637
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
18 changes: 0 additions & 18 deletions apidef/oas/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -1649,21 +1649,3 @@ func (c *ContextVariables) Fill(api apidef.APIDefinition) {
func (c *ContextVariables) ExtractTo(api *apidef.APIDefinition) {
api.EnableContextVars = c.Enabled
}

func requireMainVersion(api *apidef.APIDefinition) apidef.VersionInfo {
if len(api.VersionData.Versions) == 0 {
api.VersionData.Versions = map[string]apidef.VersionInfo{
Main: {},
}
}

if _, ok := api.VersionData.Versions[Main]; !ok {
api.VersionData.Versions[Main] = apidef.VersionInfo{}
}

return api.VersionData.Versions[Main]
}

func updateMainVersion(api *apidef.APIDefinition, updatedMainVersion apidef.VersionInfo) {
api.VersionData.Versions[Main] = updatedMainVersion
}
19 changes: 19 additions & 0 deletions apidef/oas/oasutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package oas
import (
"encoding/json"

"github.com/TykTechnologies/tyk/apidef"
internalreflect "github.com/TykTechnologies/tyk/internal/reflect"
)

Expand All @@ -27,3 +28,21 @@ func toStructIfMap(input interface{}, val interface{}) bool {

// ShouldOmit is a compatibility alias. It may be removed in the future.
var ShouldOmit = internalreflect.IsEmpty

func requireMainVersion(api *apidef.APIDefinition) apidef.VersionInfo {
if len(api.VersionData.Versions) == 0 {
api.VersionData.Versions = map[string]apidef.VersionInfo{
Main: {},
}
}

if _, ok := api.VersionData.Versions[Main]; !ok {
api.VersionData.Versions[Main] = apidef.VersionInfo{}
}

return api.VersionData.Versions[Main]
}

func updateMainVersion(api *apidef.APIDefinition, updatedMainVersion apidef.VersionInfo) {
api.VersionData.Versions[Main] = updatedMainVersion
}

0 comments on commit 1ccf637

Please sign in to comment.