From a34fa9f996adffeb35cf9cb9ffa50ea4ba171f20 Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Mon, 16 Sep 2024 23:16:36 +0300 Subject: [PATCH] rn data generator --- checker/generator/data.go | 170 ---------------------------- checker/generator/generator_test.go | 7 -- 2 files changed, 177 deletions(-) delete mode 100644 checker/generator/data.go diff --git a/checker/generator/data.go b/checker/generator/data.go deleted file mode 100644 index e98392bc..00000000 --- a/checker/generator/data.go +++ /dev/null @@ -1,170 +0,0 @@ -package generator - -import "slices" - -func GetAll() (MessageGenerator, error) { - return slices.Concat( - getEndpoints(), - getRequest(), - getResponse(), - getComponents(), - ), nil -} - -func getRequest() ValueSets { - return slices.Concat( - NewValueSets([]string{"media-type", "request body"}, schemaValueSets), - NewValueSets([]string{"property", "media-type", "request body"}, schemaValueSets), - NewValueSets([]string{"request parameter"}, schemaValueSets), - NewValueSets(nil, operationValueSets), - ) -} - -func getResponse() ValueSets { - return slices.Concat( - NewValueSets([]string{"media-type", "response"}, schemaValueSets), - NewValueSets([]string{"property", "media-type", "response"}, schemaValueSets), - ) -} - -func getEndpoints() ValueSets { - return NewValueSets(nil, endpointValueSets) -} - -func getComponents() ValueSets { - return slices.Concat( - getSecurity(), - ) -} - -func getSecurity() ValueSets { - return NewValueSets(nil, securityValueSets) -} - -var securityValueSets = ValueSets{ - ValueSetB{ - PredicativeAdjective: "%s", - Names: []string{"endpoint scheme security"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Hierarchy: []string{"global security scheme"}, - Names: []string{"security scope"}, - Actions: []string{"add", "remove"}, - }, -} - -var endpointValueSets = ValueSets{ - ValueSetA{ - Names: []string{"stability"}, // /Paths/PathItem/Operation - Actions: []string{"decrease"}, - }, - ValueSetA{ - Names: []string{"api path", "api"}, - Actions: []string{"remove"}, - Adverbs: []string{"without deprecation", "before sunset"}, - }, - ValueSetB{ - Names: []string{"endpoint"}, // /Paths/PathItem - Actions: []string{"add", "remove", "deprecate", "reactivate"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Names: []string{"success response status", "non-success response status"}, // /Paths/PathItem/Operation/Responses/Response/content/media-type/ - Actions: []string{"add", "remove"}, - }, - ValueSetA{ - Names: []string{"operation id"}, - Actions: []string{"change"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Names: []string{"operation id", "tag"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Hierarchy: []string{"endpoint security scheme"}, - Names: []string{"security scope"}, - Actions: []string{"add", "remove"}, - }, -} - -var operationValueSets = ValueSets{ - ValueSetB{ - Names: []string{"required request body", "optional request body"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - AttributiveAdjective: "%s", - Names: []string{"request parameter"}, - Actions: []string{"add", "remove"}, - }, -} - -var schemaValueSets = ValueSets{ - ValueSetA{ - PredicativeAdjective: "value", - Names: []string{"max", "maxLength", "min", "minLength", "minItems", "maxItems"}, - Actions: []string{"set", "increase", "decrease"}, - }, - ValueSetA{ - Names: []string{"type/format"}, - Actions: []string{"change", "generalize"}, - }, - ValueSetA{ - Names: []string{"discriminator property name"}, - Actions: []string{"change"}, - }, - ValueSetA{ - Names: []string{"pattern"}, - Actions: []string{"change", "generalize"}, - }, - ValueSetA{ - Names: []string{"required property", "optional property"}, - Actions: []string{"change"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Names: []string{"pattern"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - Names: []string{"default value"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Hierarchy: []string{"anyOf list"}, - Names: []string{"schema"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Hierarchy: []string{"anyOf list"}, - Names: []string{"schema"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Hierarchy: []string{"anyOf list"}, - Names: []string{"schema"}, - Actions: []string{"add", "remove"}, - }, - ValueSetB{ - PredicativeAdjective: "%s", - Names: []string{"discriminator", "mapping keys"}, - Actions: []string{"add", "remove"}, - }, -} - -/* -missing: -api-deprecated-sunset-parse -api-path-sunset-parse -api-invalid-stability-level -api-deprecated-sunset-missing -api-sunset-date-too-small -*/ diff --git a/checker/generator/generator_test.go b/checker/generator/generator_test.go index e00023f4..574eecc5 100644 --- a/checker/generator/generator_test.go +++ b/checker/generator/generator_test.go @@ -22,13 +22,6 @@ func WriteToFile(t *testing.T, filename string, lines []string) { } } -func TestDataGenerator(t *testing.T) { - result, err := generator.Generate(generator.GetAll) - require.NoError(t, err) - slices.Sort(result) - WriteToFile(t, "messages.yaml", result) -} - func TestTreeGenerator(t *testing.T) { result, err := generator.Generate(generator.GetTree("tree.yaml")) require.NoError(t, err)