Skip to content

Commit

Permalink
request-parameter added/removed
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison committed Sep 5, 2024
1 parent 1d3733d commit f310c61
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 74 deletions.
7 changes: 2 additions & 5 deletions checker/generator/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ func getPreposition(action string) string {
return "from"
}

func addAttribute(noun, adjective string, adjectiveType AdjectiveType) string {
if adjectiveType == ATTRIBUTIVE {
return adjective + " " + noun
}
return noun + " " + adjective
func addAttribute(noun, attributiveAdjective, predicativeAdjective string) string {
return strings.Join([]string{attributiveAdjective + " " + noun + " " + predicativeAdjective}, " ")
}
96 changes: 46 additions & 50 deletions checker/generator/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,31 @@ func getSecurity() ValueSets {

var securityValueSets = ValueSets{
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
nouns: []string{"endpoint scheme security"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
nouns: []string{"endpoint scheme security"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: []string{"global security scheme"},
attributed: []bool{false},
nouns: []string{"security scope"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
hierarchy: []string{"global security scheme"},
attributed: []bool{false},
nouns: []string{"security scope"},
actions: []string{"add", "remove"},
},
}

var pathsValueSets = ValueSets{
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
nouns: []string{"success response status", "non-success response status"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
nouns: []string{"success response status", "non-success response status"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: []string{"endpoint security scheme"},
attributed: []bool{false},
nouns: []string{"security scope"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
hierarchy: []string{"endpoint security scheme"},
attributed: []bool{false},
nouns: []string{"security scope"},
actions: []string{"add", "remove"},
},
}

Expand All @@ -80,14 +76,19 @@ var operationValueSets = ValueSets{
nouns: []string{"required request body", "optional request body"},
actions: []string{"add", "remove"},
},
ValueSetB{
predicativeAdjective: "%s",
attributiveAdjective: "%s",
nouns: []string{"request parameter"},
actions: []string{"add", "remove"},
},
}

var schemaValueSets = ValueSets{
ValueSetA{
adjective: "value",
adjectiveType: PREDICATIVE,
nouns: []string{"max", "maxLength", "min", "minLength", "minItems", "maxItems"},
actions: []string{"set", "increase", "decrease"},
predicativeAdjective: "value",
nouns: []string{"max", "maxLength", "min", "minLength", "minItems", "maxItems"},
actions: []string{"set", "increase", "decrease"},
},
ValueSetA{
nouns: []string{"type/format"},
Expand All @@ -106,43 +107,38 @@ var schemaValueSets = ValueSets{
actions: []string{"change"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
nouns: []string{"pattern"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
nouns: []string{"pattern"},
actions: []string{"add", "remove"},
},
ValueSetB{
nouns: []string{"default value"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: []string{"anyOf list"},
attributed: []bool{false},
nouns: []string{"schema"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
hierarchy: []string{"anyOf list"},
attributed: []bool{false},
nouns: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: []string{"anyOf list"},
attributed: []bool{false},
nouns: []string{"schema"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
hierarchy: []string{"anyOf list"},
attributed: []bool{false},
nouns: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: []string{"anyOf list"},
attributed: []bool{false},
nouns: []string{"schema"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
hierarchy: []string{"anyOf list"},
attributed: []bool{false},
nouns: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
nouns: []string{"discriminator", "mapping keys"},
actions: []string{"add", "remove"},
predicativeAdjective: "%s",
nouns: []string{"discriminator", "mapping keys"},
actions: []string{"add", "remove"},
},
}
2 changes: 2 additions & 0 deletions checker/generator/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ required-request-body-added: added required request body
required-request-body-removed: removed required request body
optional-request-body-added: added optional request body
optional-request-body-removed: removed optional request body
request-parameter-added: added %s request parameter %s
request-parameter-removed: removed %s request parameter %s
response-media-type-max-set: max value of media-type %s of response %s was set to %s
response-media-type-max-increased: max value of media-type %s of response %s was increased from %s to %s
response-media-type-max-decreased: max value of media-type %s of response %s was decreased from %s to %s
Expand Down
33 changes: 14 additions & 19 deletions checker/generator/value_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

type ValueSets []IValueSet

// NewValueSets creates a new ValueSets object
// attributed is a list of booleans that indicates if the level in the hierarchy should be preceded by a %s
func NewValueSets(hierarchy []string, attributed []bool, valueSets ValueSets) ValueSets {

result := make(ValueSets, len(valueSets))
Expand All @@ -34,20 +36,13 @@ type IValueSet interface {
setHierarchy(hierarchy []string, attributed []bool) IValueSet
}

type AdjectiveType bool

const (
PREDICATIVE AdjectiveType = false // PREDICATIVE adjectives are added after the noun (default)
ATTRIBUTIVE AdjectiveType = true // ATTRIBUTIVE adjectives are added before the noun
)

type ValueSet struct {
adjective string // adjective is added to the noun
adjectiveType AdjectiveType
hierarchy []string
attributed []bool // attributed levels in the hierarchy are preceded by a name (%s)
nouns []string
actions []string
attributiveAdjective string // attributive adjectives are added before the noun
predicativeAdjective string // predicative adjectives are added after the noun
hierarchy []string
attributed []bool // attributed levels in the hierarchy are preceded by a name (%s)
nouns []string
actions []string
}

func (v ValueSet) setHierarchy(hierarchy []string, attributed []bool) ValueSet {
Expand All @@ -69,13 +64,13 @@ func (v ValueSetA) setHierarchy(hierarchy []string, attributed []bool) IValueSet
}

func (v ValueSetA) generate(out io.Writer) {
generateMessage := func(hierarchy []string, atttibuted []bool, noun, adjective, action string) string {
return standardizeSpaces(fmt.Sprintf("%s of %s was %s", addAttribute(noun, adjective, v.adjectiveType), getHierarchyMessage(hierarchy, atttibuted), getActionMessage(action)))
generateMessage := func(hierarchy []string, atttibuted []bool, noun, attributiveAdjective, predicativeAdjective, action string) string {
return standardizeSpaces(fmt.Sprintf("%s of %s was %s", addAttribute(noun, attributiveAdjective, predicativeAdjective), getHierarchyMessage(hierarchy, atttibuted), getActionMessage(action)))
}

for _, noun := range v.nouns {
for _, action := range v.actions {
fmt.Fprintln(out, fmt.Sprintf("%s: %s", generateId(v.hierarchy, noun, action), generateMessage(v.hierarchy, v.attributed, noun, v.adjective, action)))
fmt.Fprintln(out, fmt.Sprintf("%s: %s", generateId(v.hierarchy, noun, action), generateMessage(v.hierarchy, v.attributed, noun, v.attributiveAdjective, v.predicativeAdjective, action)))

Check failure on line 73 in checker/generator/value_set.go

View workflow job for this annotation

GitHub Actions / lint

S1038: should use fmt.Fprintf instead of fmt.Fprintln(fmt.Sprintf(...)) (but don't forget the newline) (gosimple)

Check failure on line 73 in checker/generator/value_set.go

View workflow job for this annotation

GitHub Actions / lint

S1038: should use fmt.Fprintf instead of fmt.Fprintln(fmt.Sprintf(...)) (but don't forget the newline) (gosimple)
}
}
}
Expand All @@ -88,13 +83,13 @@ func (v ValueSetB) setHierarchy(hierarchy []string, attributed []bool) IValueSet
}

func (v ValueSetB) generate(out io.Writer) {
generateMessage := func(hierarchy []string, atttibuted []bool, noun, adjective, action string) string {
return standardizeSpaces(strings.Join([]string{conjugate(action), addAttribute(noun, adjective, v.adjectiveType), getHierarchyPostfix(action, hierarchy, atttibuted)}, " "))
generateMessage := func(hierarchy []string, atttibuted []bool, noun, attributiveAdjective, predicativeAdjective, action string) string {
return standardizeSpaces(strings.Join([]string{conjugate(action), addAttribute(noun, attributiveAdjective, predicativeAdjective), getHierarchyPostfix(action, hierarchy, atttibuted)}, " "))
}

for _, noun := range v.nouns {
for _, action := range v.actions {
fmt.Fprintln(out, fmt.Sprintf("%s: %s", generateId(v.hierarchy, noun, action), generateMessage(v.hierarchy, v.attributed, noun, v.adjective, action)))
fmt.Fprintln(out, fmt.Sprintf("%s: %s", generateId(v.hierarchy, noun, action), generateMessage(v.hierarchy, v.attributed, noun, v.attributiveAdjective, v.predicativeAdjective, action)))

Check failure on line 92 in checker/generator/value_set.go

View workflow job for this annotation

GitHub Actions / lint

S1038: should use fmt.Fprintf instead of fmt.Fprintln(fmt.Sprintf(...)) (but don't forget the newline) (gosimple)

Check failure on line 92 in checker/generator/value_set.go

View workflow job for this annotation

GitHub Actions / lint

S1038: should use fmt.Fprintf instead of fmt.Fprintln(fmt.Sprintf(...)) (but don't forget the newline) (gosimple)
}
}
}

0 comments on commit f310c61

Please sign in to comment.