Skip to content

Commit

Permalink
introduce function to detecting versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianczech committed Mar 22, 2024
1 parent ee53918 commit d836de2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
25 changes: 25 additions & 0 deletions pkg/properties/normalized.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,28 @@ func (spec *Normalization) Validate() []error {

return checks
}

// SupportedVersions provides list of all supported versions
func (spec *Normalization) SupportedVersions() []string {
if spec.Spec != nil {
versions := supportedVersions(spec.Spec.Params, []string{""})
versions = supportedVersions(spec.Spec.OneOf, versions)
return versions
}
return nil
}

func supportedVersions(params map[string]*SpecParam, versions []string) []string {
for _, param := range params {
for _, profile := range param.Profiles {
if profile.FromVersion != "" {
versions = append(versions, profile.FromVersion)
}
}
if param.Spec != nil {
versions = supportedVersions(param.Spec.Params, versions)
versions = supportedVersions(param.Spec.OneOf, versions)
}
}
return versions
}
18 changes: 16 additions & 2 deletions pkg/properties/normalized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ spec:
profiles:
-
xpath: ["description"]
from_version: "10.1.1"
tags:
description: 'The administrative tags.'
type: 'list'
Expand Down Expand Up @@ -123,6 +124,7 @@ spec:
profiles:
-
xpath: ["ip-wildcard"]
from_version: "11.1.2"
`

func TestUnmarshallAddressSpecFile(t *testing.T) {
Expand Down Expand Up @@ -266,7 +268,7 @@ spec:
- xpath:
- description
not_present: false
from_version: ""
from_version: 10.1.1
spec: null
tags:
name:
Expand Down Expand Up @@ -346,7 +348,7 @@ spec:
- xpath:
- ip-wildcard
not_present: false
from_version: ""
from_version: 11.1.2
spec: null
`

Expand Down Expand Up @@ -412,3 +414,15 @@ xpath_suffix:
// then
assert.Len(t, problems, 2, "Not all expected validation checks failed")
}

func TestNamesOfStructsForVersioning(t *testing.T) {
// given
yamlParsedData, _ := ParseSpec([]byte(sampleSpec))

// when
versions := yamlParsedData.SupportedVersions()

// then
assert.NotNilf(t, yamlParsedData, "Unmarshalled data cannot be nil")
assert.Contains(t, versions, "10.1.1")
}
4 changes: 0 additions & 4 deletions templates/sdk/entry.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ func (c *entryXmlContainer) Normalize() ([]Entry, error) {

entry.Misc["Entry"] = o.Misc

// TODO: start thinking about versioning e.g:
// 1 approach: entryXml1, entryXml2, entryXml3, ...
// 2 approach: entryXml_10_0_0, entryXml_10_1_0, entryXml_11_0_0, ...

entryList = append(entryList, entry)
}

Expand Down

0 comments on commit d836de2

Please sign in to comment.