-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd1ba93
commit b42c0b2
Showing
6 changed files
with
247 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package generator | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type ChangeMap map[string]Changes | ||
|
||
type Changes struct { | ||
ExcludeFromHierarchy bool `yaml:"excludeFromHierarchy"` | ||
Actions map[string]Objects `yaml:"actions"` | ||
NextLevel ChangeMap `yaml:"nextLevel"` | ||
} | ||
|
||
type Objects []*Object | ||
|
||
type Object struct { | ||
Hierarchy []string `yaml:"hierarchy"` | ||
Object string `yaml:"object"` | ||
Adverbs []string `yaml:"adverbs"` | ||
StartWith string `yaml:"startWith"` | ||
PredicativeAdjective string `yaml:"predicativeAdjective"` | ||
AttributiveAdjective string `yaml:"attributiveAdjective"` | ||
} | ||
|
||
func GetTree() (MessageGenerator, error) { | ||
yamlFile, err := os.ReadFile("tree.yaml") | ||
if err != nil { | ||
return nil, fmt.Errorf("yamlFile.Get err #%v ", err) | ||
} | ||
|
||
var changeMap ChangeMap | ||
err = yaml.Unmarshal(yamlFile, &changeMap) | ||
if err != nil { | ||
return nil, fmt.Errorf("unmarshal: %v", err) | ||
} | ||
|
||
return changeMap, nil | ||
} | ||
|
||
func (changeMap ChangeMap) generate(out io.Writer) { | ||
fillHierarchy(changeMap, nil) | ||
|
||
for _, change := range changeMap { | ||
for action, objects := range change.Actions { | ||
for _, object := range objects { | ||
getValueSet(object, action).generate(out) | ||
} | ||
} | ||
change.NextLevel.generate(out) | ||
} | ||
} | ||
|
||
func fillHierarchy(changeMap ChangeMap, hierarchy []string) { | ||
for container, change := range changeMap { | ||
if !change.ExcludeFromHierarchy { | ||
hierarchy = append([]string{container}, hierarchy...) | ||
} | ||
for _, objects := range change.Actions { | ||
for _, object := range objects { | ||
object.Hierarchy = hierarchy | ||
} | ||
} | ||
fillHierarchy(change.NextLevel, hierarchy) | ||
} | ||
} | ||
|
||
func getValueSet(object *Object, action string) IValueSet { | ||
valueSet := ValueSet{ | ||
AttributiveAdjective: object.AttributiveAdjective, | ||
PredicativeAdjective: object.PredicativeAdjective, | ||
Hierarchy: object.Hierarchy, | ||
Names: []string{object.Object}, | ||
Actions: []string{action}, | ||
Adverbs: object.Adverbs, | ||
} | ||
|
||
if object.StartWith == "object" { | ||
return ValueSetA(valueSet) | ||
} | ||
return ValueSetB(valueSet) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
paths: | ||
excludeFromHierarchy: true | ||
actions: | ||
remove: | ||
- object: path | ||
adverbs: | ||
- without deprecation | ||
- before sunset | ||
startWith: object | ||
nextLevel: | ||
operations: | ||
excludeFromHierarchy: true | ||
actions: | ||
remove: | ||
- object: endpoint | ||
adverbs: | ||
- without deprecation | ||
- before sunset | ||
startWith: object | ||
- object: endpoint | ||
startWith: action | ||
add: | ||
- object: endpoint | ||
startWith: action | ||
deprecate: | ||
- object: endpoint | ||
startWith: action | ||
reactivate: | ||
- object: endpoint | ||
startWith: action | ||
nextLevel: | ||
endpoint: | ||
excludeFromHierarchy: true | ||
actions: | ||
change: | ||
- object: operation id | ||
startWith: object | ||
decrease: | ||
- object: stability | ||
startWith: object | ||
nextLevel: | ||
responses: | ||
excludeFromHierarchy: true | ||
actions: | ||
add: | ||
- object: success response | ||
predicativeAdjective: "status %s" | ||
startWith: action | ||
- object: non-success response | ||
predicativeAdjective: "status %s" | ||
startWith: action | ||
remove: | ||
- object: success response | ||
predicativeAdjective: "status %s" | ||
startWith: action | ||
- object: non-success response | ||
predicativeAdjective: "status %s" | ||
startWith: action | ||
|
||
|
Oops, something went wrong.