diff --git a/pkg/properties/normalized.go b/pkg/properties/normalized.go index 8c28354e..a6ccece8 100644 --- a/pkg/properties/normalized.go +++ b/pkg/properties/normalized.go @@ -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 +} diff --git a/pkg/properties/normalized_test.go b/pkg/properties/normalized_test.go index e722344a..f5a1091e 100644 --- a/pkg/properties/normalized_test.go +++ b/pkg/properties/normalized_test.go @@ -85,6 +85,7 @@ spec: profiles: - xpath: ["description"] + from_version: "10.1.1" tags: description: 'The administrative tags.' type: 'list' @@ -123,6 +124,7 @@ spec: profiles: - xpath: ["ip-wildcard"] + from_version: "11.1.2" ` func TestUnmarshallAddressSpecFile(t *testing.T) { @@ -266,7 +268,7 @@ spec: - xpath: - description not_present: false - from_version: "" + from_version: 10.1.1 spec: null tags: name: @@ -346,7 +348,7 @@ spec: - xpath: - ip-wildcard not_present: false - from_version: "" + from_version: 11.1.2 spec: null ` @@ -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") +} diff --git a/templates/sdk/entry.tmpl b/templates/sdk/entry.tmpl index b8a14be0..67e414e0 100644 --- a/templates/sdk/entry.tmpl +++ b/templates/sdk/entry.tmpl @@ -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) }