From 09876b7ae012608f6abba1d9d75c2b6706255e34 Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Sat, 7 Sep 2024 23:38:14 +0300 Subject: [PATCH] noun -> object --- checker/generator/data.go | 44 +++++++++++++++++----------------- checker/generator/generator.go | 12 +++++----- checker/generator/value_set.go | 14 +++++------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/checker/generator/data.go b/checker/generator/data.go index f1601879..c72c871a 100644 --- a/checker/generator/data.go +++ b/checker/generator/data.go @@ -44,62 +44,62 @@ 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"}, }, } @@ -107,55 +107,55 @@ var operationValueSets = ValueSets{ 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"}, }, } diff --git a/checker/generator/generator.go b/checker/generator/generator.go index d606a6ce..2933bb82 100644 --- a/checker/generator/generator.go +++ b/checker/generator/generator.go @@ -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 { @@ -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}, " ") } diff --git a/checker/generator/value_set.go b/checker/generator/value_set.go index bb780235..a5731e6e 100644 --- a/checker/generator/value_set.go +++ b/checker/generator/value_set.go @@ -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 } @@ -58,8 +58,8 @@ 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 } @@ -67,16 +67,16 @@ func (v ValueSetA) generate(out io.Writer) { 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) } } @@ -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)) }