Skip to content

Commit

Permalink
noun -> object
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison committed Sep 7, 2024
1 parent 6f0de06 commit 09876b7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
44 changes: 22 additions & 22 deletions checker/generator/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,118 +44,118 @@ func getSecurity() ValueSets {
var securityValueSets = ValueSets{
ValueSetB{
predicativeAdjective: "%s",
nouns: []string{"endpoint scheme security"},
objects: []string{"endpoint scheme security"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
hierarchy: []string{"global security scheme"},
nouns: []string{"security scope"},
objects: []string{"security scope"},
actions: []string{"add", "remove"},
},
}

var endpointValueSets = ValueSets{
ValueSetA{
nouns: []string{"stability"}, // /Paths/PathItem/Operation
objects: []string{"stability"}, // /Paths/PathItem/Operation
actions: []string{"decrease"},
},
ValueSetA{
nouns: []string{"api path", "api"},
objects: []string{"api path", "api"},
actions: []string{"remove"},
adverb: []string{"without deprecation", "before sunset"},
},
ValueSetB{
nouns: []string{"endpoint"}, // /Paths/PathItem
objects: []string{"endpoint"}, // /Paths/PathItem
actions: []string{"add", "remove", "deprecate", "reactivate"},
},
ValueSetB{
predicativeAdjective: "%s",
nouns: []string{"success response status", "non-success response status"}, // /Paths/PathItem/Operation/Responses/Response/content/media-type/
objects: []string{"success response status", "non-success response status"}, // /Paths/PathItem/Operation/Responses/Response/content/media-type/
actions: []string{"add", "remove"},
},
ValueSetA{
nouns: []string{"operation id"},
objects: []string{"operation id"},
actions: []string{"change"},
},
ValueSetB{
predicativeAdjective: "%s",
nouns: []string{"operation id", "tag"},
objects: []string{"operation id", "tag"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
hierarchy: []string{"endpoint security scheme"},
nouns: []string{"security scope"},
objects: []string{"security scope"},
actions: []string{"add", "remove"},
},
}

var operationValueSets = ValueSets{
ValueSetB{
nouns: []string{"required request body", "optional request body"},
objects: []string{"required request body", "optional request body"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
attributiveAdjective: "%s",
nouns: []string{"request parameter"},
objects: []string{"request parameter"},
actions: []string{"add", "remove"},
},
}

var schemaValueSets = ValueSets{
ValueSetA{
predicativeAdjective: "value",
nouns: []string{"max", "maxLength", "min", "minLength", "minItems", "maxItems"},
objects: []string{"max", "maxLength", "min", "minLength", "minItems", "maxItems"},
actions: []string{"set", "increase", "decrease"},
},
ValueSetA{
nouns: []string{"type/format"},
objects: []string{"type/format"},
actions: []string{"change", "generalize"},
},
ValueSetA{
nouns: []string{"discriminator property name"},
objects: []string{"discriminator property name"},
actions: []string{"change"},
},
ValueSetA{
nouns: []string{"pattern"},
objects: []string{"pattern"},
actions: []string{"change", "generalize"},
},
ValueSetA{
nouns: []string{"required property", "optional property"},
objects: []string{"required property", "optional property"},
actions: []string{"change"},
},
ValueSetB{
predicativeAdjective: "%s",
nouns: []string{"pattern"},
objects: []string{"pattern"},
actions: []string{"add", "remove"},
},
ValueSetB{
nouns: []string{"default value"},
objects: []string{"default value"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
hierarchy: []string{"anyOf list"},
nouns: []string{"schema"},
objects: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
hierarchy: []string{"anyOf list"},
nouns: []string{"schema"},
objects: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
hierarchy: []string{"anyOf list"},
nouns: []string{"schema"},
objects: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
nouns: []string{"discriminator", "mapping keys"},
objects: []string{"discriminator", "mapping keys"},
actions: []string{"add", "remove"},
},
}
Expand Down
12 changes: 6 additions & 6 deletions checker/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func filterStrings(list []string, f func(string) bool) []string {
return result
}

func generateId(hierarchy []string, noun, action string) string {
if before, _, found := strings.Cut(noun, "/"); found {
noun = before
func generateId(hierarchy []string, object, action string) string {
if prefix, _, found := strings.Cut(object, "/"); found {
object = prefix
}

return strcase.ToKebab(strings.Join(filterStrings([]string{concat(hierarchy), noun, conjugate(action)}, isEmpty), "-"))
return strcase.ToKebab(strings.Join(filterStrings([]string{concat(hierarchy), object, conjugate(action)}, isEmpty), "-"))
}

func concat(list []string) string {
Expand Down Expand Up @@ -131,6 +131,6 @@ func getPreposition(action string) string {
return "from"
}

func addAttribute(noun, attributiveAdjective, predicativeAdjective string) string {
return strings.Join([]string{attributiveAdjective + " " + noun + " " + predicativeAdjective}, " ")
func addAttribute(object, attributiveAdjective, predicativeAdjective string) string {
return strings.Join([]string{attributiveAdjective + " " + object + " " + predicativeAdjective}, " ")
}
14 changes: 7 additions & 7 deletions checker/generator/value_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ValueSet struct {
attributiveAdjective string // attributive adjectives are added before the noun
predicativeAdjective string // predicative adjectives are added after the noun
hierarchy []string
nouns []string
objects []string
actions []string
adverb []string
}
Expand All @@ -58,25 +58,25 @@ func (v ValueSetA) setHierarchy(hierarchy []string) IValueSet {
}

func (v ValueSetA) generate(out io.Writer) {
generateMessage := func(hierarchy []string, noun, attributiveAdjective, predicativeAdjective, action, adverb string) string {
prefix := addAttribute(noun, attributiveAdjective, predicativeAdjective)
generateMessage := func(hierarchy []string, object, attributiveAdjective, predicativeAdjective, action, adverb string) string {
prefix := addAttribute(object, attributiveAdjective, predicativeAdjective)
if hierarchyMessage := getHierarchyMessage(hierarchy); hierarchyMessage != "" {
prefix += " of " + hierarchyMessage
}

return standardizeSpaces(fmt.Sprintf("%s was %s %s %s", prefix, conjugate(action), getActionMessage(action), adverb))
}

for _, noun := range v.nouns {
for _, object := range v.objects {
for _, action := range v.actions {
id := generateId(v.hierarchy, noun, action)
id := generateId(v.hierarchy, object, action)

adverbs := v.adverb
if v.adverb == nil {
adverbs = []string{""}
}
for _, adverb := range adverbs {
message := generateMessage(v.hierarchy, noun, v.attributiveAdjective, v.predicativeAdjective, action, adverb)
message := generateMessage(v.hierarchy, object, v.attributiveAdjective, v.predicativeAdjective, action, adverb)
fmt.Fprintf(out, "%s: %s\n", id, message)
}
}
Expand All @@ -95,7 +95,7 @@ func (v ValueSetB) generate(out io.Writer) {
return standardizeSpaces(strings.Join([]string{conjugate(action), addAttribute(noun, attributiveAdjective, predicativeAdjective), getHierarchyPostfix(action, hierarchy)}, " "))
}

for _, noun := range v.nouns {
for _, noun := range v.objects {
for _, action := range v.actions {
fmt.Fprintf(out, "%s: %s\n", generateId(v.hierarchy, noun, action), generateMessage(v.hierarchy, noun, v.attributiveAdjective, v.predicativeAdjective, action))
}
Expand Down

0 comments on commit 09876b7

Please sign in to comment.