Skip to content

Commit

Permalink
Render service.go for entry and config
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianczech committed Apr 2, 2024
1 parent 35a14d5 commit 3083d8d
Show file tree
Hide file tree
Showing 4 changed files with 597 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/generate/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (c *Creator) parseTemplate(templateName string) (*template.Template, error)
"nestedSpecs": translate.NestedSpecs,
"createGoSuffixFromVersion": translate.CreateGoSuffixFromVersion,
"paramSupportedInVersion": translate.ParamSupportedInVersion,
"xmlPathSuffix": translate.XmlPathSuffix,
}
return template.New(templateName).Funcs(funcMap).ParseFiles(templatePath)
}
11 changes: 11 additions & 0 deletions pkg/translate/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,14 @@ func argumentTypeForSpecMatchesFunction(parent []string, param *properties.SpecP
strings.Join(parent, ""), param.Name.CamelCase)
}
}

// XmlPathSuffix return XML path suffixes created from profiles.
func XmlPathSuffix(param *properties.SpecParam) []string {
xmlPathSuffixes := []string{}
if param.Profiles != nil {
for _, profile := range param.Profiles {
xmlPathSuffixes = append(xmlPathSuffixes, strings.Join(profile.Xpath, "/"))
}
}
return xmlPathSuffixes
}
24 changes: 24 additions & 0 deletions pkg/translate/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,27 @@ return true
// then
assert.Equal(t, expectedNestedSpec, renderedNestedSpecMatches)
}

func TestXmlPathSuffix(t *testing.T) {
// given
spec := properties.Spec{
Params: map[string]*properties.SpecParam{
"a": {
Profiles: []*properties.SpecParamProfile{{
Xpath: []string{"test", "a"},
}},
Name: &properties.NameVariant{
Underscore: "a",
CamelCase: "A",
},
},
},
}
expectedXpathSuffixes := []string{"test/a"}

// when
actualXpathSuffixes := XmlPathSuffix(spec.Params["a"])

// then
assert.Equal(t, expectedXpathSuffixes, actualXpathSuffixes)
}
Loading

0 comments on commit 3083d8d

Please sign in to comment.