Skip to content

Commit

Permalink
fix hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison committed Aug 30, 2024
1 parent e110598 commit 0b2cee7
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 116 deletions.
154 changes: 72 additions & 82 deletions checker/generator/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,99 +12,89 @@ func getAll() ValueSets {

func getRequest() ValueSets {
return slices.Concat(
schemaValueSets([]string{"media-type", "request body"}, nil),
schemaValueSets([]string{"property", "media-type", "request body"}, nil),
schemaValueSets([]string{"request parameter"}, []bool{true}),
NewValueSets([]string{"media-type", "request body"}, nil, schemaValueSets),
NewValueSets([]string{"property", "media-type", "request body"}, nil, schemaValueSets),
NewValueSets([]string{"request parameter"}, []bool{true}, schemaValueSets),
)
}

func getResponse() ValueSets {
return slices.Concat(
schemaValueSets([]string{"media-type", "response"}, nil),
schemaValueSets([]string{"property", "media-type", "response"}, nil),
NewValueSets([]string{"media-type", "response"}, nil, schemaValueSets),
NewValueSets([]string{"property", "media-type", "response"}, nil, schemaValueSets),
)
}

func getPaths() ValueSets {
return pathValueSets(nil, nil)
return NewValueSets(nil, nil, pathsValueSets)
}

func pathValueSets(hierarchy []string, attributed []bool) ValueSets {
return ValueSets{
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: hierarchy,
nouns: []string{"success response status", "non-success response status"},
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"},
},
}

func schemaValueSets(hierarchy []string, attributed []bool) ValueSets {
return ValueSets{
ValueSetA{
adjective: "value",
adjectiveType: PREDICATIVE,
hierarchy: hierarchy,
attributed: attributed,
nouns: []string{"max", "maxLength", "min", "minLength", "minItems", "maxItems"},
actions: []string{"set", "increase", "decrease"},
},
ValueSetA{
hierarchy: hierarchy,
nouns: []string{"type/format"},
actions: []string{"change", "generalize"},
},
ValueSetA{
hierarchy: hierarchy,
nouns: []string{"discriminator property name"},
actions: []string{"change"},
},
ValueSetA{
hierarchy: hierarchy,
nouns: []string{"pattern"},
actions: []string{"change"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: hierarchy,
nouns: []string{"pattern"},
actions: []string{"add", "remove"},
},
ValueSetB{
hierarchy: hierarchy,
nouns: []string{"default value"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: append([]string{"anyOf list"}, hierarchy...),
nouns: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: append([]string{"oneOf list"}, hierarchy...),
nouns: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: append([]string{"allOf list"}, hierarchy...),
nouns: []string{"schema"},
actions: []string{"add", "remove"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
hierarchy: hierarchy,
nouns: []string{"discriminator", "mapping keys"},
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"},
},
ValueSetA{
nouns: []string{"type/format"},
actions: []string{"change", "generalize"},
},
ValueSetA{
nouns: []string{"discriminator property name"},
actions: []string{"change"},
},
ValueSetA{
nouns: []string{"pattern"},
actions: []string{"change"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
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"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
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"},
},
ValueSetB{
adjective: "%s",
adjectiveType: PREDICATIVE,
nouns: []string{"discriminator", "mapping keys"},
actions: []string{"add", "remove"},
},
}
68 changes: 34 additions & 34 deletions checker/generator/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ request-body-media-type-default-value-added: added default value to media-type %
request-body-media-type-default-value-removed: removed default value from media-type %s of request body
request-body-media-type-any-of-list-schema-added: added schema %s to anyOf list %s of media-type %s of request body
request-body-media-type-any-of-list-schema-removed: removed schema %s from anyOf list %s of media-type %s of request body
request-body-media-type-one-of-list-schema-added: added schema %s to oneOf list %s of media-type %s of request body
request-body-media-type-one-of-list-schema-removed: removed schema %s from oneOf list %s of media-type %s of request body
request-body-media-type-all-of-list-schema-added: added schema %s to allOf list %s of media-type %s of request body
request-body-media-type-all-of-list-schema-removed: removed schema %s from allOf list %s of media-type %s of request body
request-body-media-type-any-of-list-schema-added: added schema %s to anyOf list %s of media-type %s of request body
request-body-media-type-any-of-list-schema-removed: removed schema %s from anyOf list %s of media-type %s of request body
request-body-media-type-any-of-list-schema-added: added schema %s to anyOf list %s of media-type %s of request body
request-body-media-type-any-of-list-schema-removed: removed schema %s from anyOf list %s of media-type %s of request body
request-body-media-type-discriminator-added: added discriminator %s to media-type %s of request body
request-body-media-type-discriminator-removed: removed discriminator %s from media-type %s of request body
request-body-media-type-mapping-keys-added: added mapping keys %s to media-type %s of request body
Expand Down Expand Up @@ -66,10 +66,10 @@ request-body-media-type-property-default-value-added: added default value to pro
request-body-media-type-property-default-value-removed: removed default value from property %s of media-type %s of request body
request-body-media-type-property-any-of-list-schema-added: added schema %s to anyOf list %s of property %s of media-type %s of request body
request-body-media-type-property-any-of-list-schema-removed: removed schema %s from anyOf list %s of property %s of media-type %s of request body
request-body-media-type-property-one-of-list-schema-added: added schema %s to oneOf list %s of property %s of media-type %s of request body
request-body-media-type-property-one-of-list-schema-removed: removed schema %s from oneOf list %s of property %s of media-type %s of request body
request-body-media-type-property-all-of-list-schema-added: added schema %s to allOf list %s of property %s of media-type %s of request body
request-body-media-type-property-all-of-list-schema-removed: removed schema %s from allOf list %s of property %s of media-type %s of request body
request-body-media-type-property-any-of-list-schema-added: added schema %s to anyOf list %s of property %s of media-type %s of request body
request-body-media-type-property-any-of-list-schema-removed: removed schema %s from anyOf list %s of property %s of media-type %s of request body
request-body-media-type-property-any-of-list-schema-added: added schema %s to anyOf list %s of property %s of media-type %s of request body
request-body-media-type-property-any-of-list-schema-removed: removed schema %s from anyOf list %s of property %s of media-type %s of request body
request-body-media-type-property-discriminator-added: added discriminator %s to property %s of media-type %s of request body
request-body-media-type-property-discriminator-removed: removed discriminator %s from property %s of media-type %s of request body
request-body-media-type-property-mapping-keys-added: added mapping keys %s to property %s of media-type %s of request body
Expand All @@ -92,24 +92,24 @@ request-parameter-min-items-decreased: minItems value of %s request parameter %s
request-parameter-max-items-set: maxItems value of %s request parameter %s was set to %s
request-parameter-max-items-increased: maxItems value of %s request parameter %s was increased from %s to %s
request-parameter-max-items-decreased: maxItems value of %s request parameter %s was decreased from %s to %s
request-parameter-type-changed: type/format of request parameter %s was changed from %s to %s
request-parameter-type-generalized: type/format of request parameter %s was generalized from %s to %s
request-parameter-discriminator-property-name-changed: discriminator property name of request parameter %s was changed from %s to %s
request-parameter-pattern-changed: pattern of request parameter %s was changed from %s to %s
request-parameter-pattern-added: added pattern %s to request parameter %s
request-parameter-pattern-removed: removed pattern %s from request parameter %s
request-parameter-default-value-added: added default value to request parameter %s
request-parameter-default-value-removed: removed default value from request parameter %s
request-parameter-any-of-list-schema-added: added schema %s to anyOf list %s of request parameter %s
request-parameter-any-of-list-schema-removed: removed schema %s from anyOf list %s of request parameter %s
request-parameter-one-of-list-schema-added: added schema %s to oneOf list %s of request parameter %s
request-parameter-one-of-list-schema-removed: removed schema %s from oneOf list %s of request parameter %s
request-parameter-all-of-list-schema-added: added schema %s to allOf list %s of request parameter %s
request-parameter-all-of-list-schema-removed: removed schema %s from allOf list %s of request parameter %s
request-parameter-discriminator-added: added discriminator %s to request parameter %s
request-parameter-discriminator-removed: removed discriminator %s from request parameter %s
request-parameter-mapping-keys-added: added mapping keys %s to request parameter %s
request-parameter-mapping-keys-removed: removed mapping keys %s from request parameter %s
request-parameter-type-changed: type/format of %s request parameter %s was changed from %s to %s
request-parameter-type-generalized: type/format of %s request parameter %s was generalized from %s to %s
request-parameter-discriminator-property-name-changed: discriminator property name of %s request parameter %s was changed from %s to %s
request-parameter-pattern-changed: pattern of %s request parameter %s was changed from %s to %s
request-parameter-pattern-added: added pattern %s to %s request parameter %s
request-parameter-pattern-removed: removed pattern %s from %s request parameter %s
request-parameter-default-value-added: added default value to %s request parameter %s
request-parameter-default-value-removed: removed default value from %s request parameter %s
request-parameter-any-of-list-schema-added: added schema %s to anyOf list %s of %s request parameter %s
request-parameter-any-of-list-schema-removed: removed schema %s from anyOf list %s of %s request parameter %s
request-parameter-any-of-list-schema-added: added schema %s to anyOf list %s of %s request parameter %s
request-parameter-any-of-list-schema-removed: removed schema %s from anyOf list %s of %s request parameter %s
request-parameter-any-of-list-schema-added: added schema %s to anyOf list %s of %s request parameter %s
request-parameter-any-of-list-schema-removed: removed schema %s from anyOf list %s of %s request parameter %s
request-parameter-discriminator-added: added discriminator %s to %s request parameter %s
request-parameter-discriminator-removed: removed discriminator %s from %s request parameter %s
request-parameter-mapping-keys-added: added mapping keys %s to %s request parameter %s
request-parameter-mapping-keys-removed: removed mapping keys %s from %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 Expand Up @@ -138,10 +138,10 @@ response-media-type-default-value-added: added default value to media-type %s of
response-media-type-default-value-removed: removed default value from media-type %s of response %s
response-media-type-any-of-list-schema-added: added schema %s to anyOf list %s of media-type %s of response %s
response-media-type-any-of-list-schema-removed: removed schema %s from anyOf list %s of media-type %s of response %s
response-media-type-one-of-list-schema-added: added schema %s to oneOf list %s of media-type %s of response %s
response-media-type-one-of-list-schema-removed: removed schema %s from oneOf list %s of media-type %s of response %s
response-media-type-all-of-list-schema-added: added schema %s to allOf list %s of media-type %s of response %s
response-media-type-all-of-list-schema-removed: removed schema %s from allOf list %s of media-type %s of response %s
response-media-type-any-of-list-schema-added: added schema %s to anyOf list %s of media-type %s of response %s
response-media-type-any-of-list-schema-removed: removed schema %s from anyOf list %s of media-type %s of response %s
response-media-type-any-of-list-schema-added: added schema %s to anyOf list %s of media-type %s of response %s
response-media-type-any-of-list-schema-removed: removed schema %s from anyOf list %s of media-type %s of response %s
response-media-type-discriminator-added: added discriminator %s to media-type %s of response %s
response-media-type-discriminator-removed: removed discriminator %s from media-type %s of response %s
response-media-type-mapping-keys-added: added mapping keys %s to media-type %s of response %s
Expand Down Expand Up @@ -174,10 +174,10 @@ response-media-type-property-default-value-added: added default value to propert
response-media-type-property-default-value-removed: removed default value from property %s of media-type %s of response %s
response-media-type-property-any-of-list-schema-added: added schema %s to anyOf list %s of property %s of media-type %s of response %s
response-media-type-property-any-of-list-schema-removed: removed schema %s from anyOf list %s of property %s of media-type %s of response %s
response-media-type-property-one-of-list-schema-added: added schema %s to oneOf list %s of property %s of media-type %s of response %s
response-media-type-property-one-of-list-schema-removed: removed schema %s from oneOf list %s of property %s of media-type %s of response %s
response-media-type-property-all-of-list-schema-added: added schema %s to allOf list %s of property %s of media-type %s of response %s
response-media-type-property-all-of-list-schema-removed: removed schema %s from allOf list %s of property %s of media-type %s of response %s
response-media-type-property-any-of-list-schema-added: added schema %s to anyOf list %s of property %s of media-type %s of response %s
response-media-type-property-any-of-list-schema-removed: removed schema %s from anyOf list %s of property %s of media-type %s of response %s
response-media-type-property-any-of-list-schema-added: added schema %s to anyOf list %s of property %s of media-type %s of response %s
response-media-type-property-any-of-list-schema-removed: removed schema %s from anyOf list %s of property %s of media-type %s of response %s
response-media-type-property-discriminator-added: added discriminator %s to property %s of media-type %s of response %s
response-media-type-property-discriminator-removed: removed discriminator %s from property %s of media-type %s of response %s
response-media-type-property-mapping-keys-added: added mapping keys %s to property %s of media-type %s of response %s
Expand Down
38 changes: 38 additions & 0 deletions checker/generator/value_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import (

type ValueSets []IValueSet

func NewValueSets(hierarchy []string, attributed []bool, valueSets ValueSets) ValueSets {

result := make(ValueSets, len(valueSets))

if attributed == nil {
attributed = make([]bool, len(hierarchy))
}

for i, vs := range valueSets {
result[i] = vs.setHierarchy(hierarchy, attributed)
}

return result
}

func (vs ValueSets) generate(out io.Writer) {
for _, v := range vs {
v.generate(out)
Expand All @@ -16,6 +31,7 @@ func (vs ValueSets) generate(out io.Writer) {

type IValueSet interface {
generate(out io.Writer)
setHierarchy(hierarchy []string, attributed []bool) IValueSet
}

type AdjectiveType bool
Expand All @@ -37,6 +53,17 @@ type ValueSet struct {
// ValueSetA messages start with the noun
type ValueSetA ValueSet

func (v ValueSetA) setHierarchy(hierarchy []string, attributed []bool) IValueSet {
if len(hierarchy) == 0 {
return v
}

v.hierarchy = append(v.hierarchy, hierarchy...)
v.attributed = append(v.attributed, attributed...)

return v
}

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)))
Expand All @@ -52,6 +79,17 @@ func (v ValueSetA) generate(out io.Writer) {
// ValueSetB messages start with the action
type ValueSetB ValueSet

func (v ValueSetB) setHierarchy(hierarchy []string, attributed []bool) IValueSet {
if len(hierarchy) == 0 {
return v
}

v.hierarchy = append(v.hierarchy, hierarchy...)
v.attributed = append(v.attributed, attributed...)

return v
}

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)}, " "))
Expand Down

0 comments on commit 0b2cee7

Please sign in to comment.