From a84868ecf834c795d42b493f3fb119d3ac9cc1ac Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Tue, 19 Jul 2022 10:16:57 -0400 Subject: [PATCH] Tuned some of the responses in rules after reviewing report. --- functions/openapi/examples.go | 6 +++--- functions/openapi/operation_descriptions.go | 4 ++-- functions/openapi/paths_kebab_case.go | 3 +++ functions/openapi/success_response.go | 2 +- rulesets/ruleset_functions.go | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/functions/openapi/examples.go b/functions/openapi/examples.go index 588afb08..81d3ebb4 100644 --- a/functions/openapi/examples.go +++ b/functions/openapi/examples.go @@ -474,8 +474,8 @@ func analyzeExample(nameNodeValue string, mediaTypeNode *yaml.Node, basePath str // check if the example contains a summary _, summaryNode := utils.FindKeyNode("summary", []*yaml.Node{multiExampleNode}) if summaryNode == nil { - z := model.BuildFunctionResultString(fmt.Sprintf("Example `%s` missing a `summary`, "+ - "examples need explaining", exampleName)) + z := model.BuildFunctionResultString(fmt.Sprintf("Example `%s` missing a `summary` "+ + "- examples need explaining", exampleName)) z.StartNode = esValue z.EndNode = valueNode z.Path = nodePath @@ -486,7 +486,7 @@ func analyzeExample(nameNodeValue string, mediaTypeNode *yaml.Node, basePath str // can`t both have a value and an external value set! if valueNode != nil && externalValueNode != nil { z := model.BuildFunctionResultString(fmt.Sprintf("Example `%s` is not valid: cannot use"+ - " both `value` and `externalValue`, choose one or the other", + " both `value` and `externalValue` - choose one or the other", exampleName)) z.StartNode = esValue z.EndNode = valueNode diff --git a/functions/openapi/operation_descriptions.go b/functions/openapi/operation_descriptions.go index ce6cd848..5f60182b 100644 --- a/functions/openapi/operation_descriptions.go +++ b/functions/openapi/operation_descriptions.go @@ -84,7 +84,7 @@ func (od OperationDescription) RunRule(nodes []*yaml.Node, context model.RuleFun descKey, descNode = utils.FindKeyNode("description", requestBodyNode.Content) if descNode == nil { - res := createDescriptionResult(fmt.Sprintf("Operation requestBody `%s` at path `%s` "+ + res := createDescriptionResult(fmt.Sprintf("Operation `requestBody` for method `%s` at path `%s` "+ "is missing a description", opMethod, opPath), utils.BuildPath(basePath, []string{"requestBody"}), requestBodyKey, requestBodyNode) res.Rule = context.Rule @@ -95,7 +95,7 @@ func (od OperationDescription) RunRule(nodes []*yaml.Node, context model.RuleFun words := strings.Split(descNode.Value, " ") if len(words) < minWords { - res := createDescriptionResult(fmt.Sprintf("Operation `%s` requestBody description "+ + res := createDescriptionResult(fmt.Sprintf("Operation `requestBody` for method `%s` description "+ "at path `%s` must be at least %d words long, (%d is not enough)", opMethod, opPath, minWords, len(words)), basePath, descKey, descNode) res.Rule = context.Rule diff --git a/functions/openapi/paths_kebab_case.go b/functions/openapi/paths_kebab_case.go index cf542a23..c04b4517 100644 --- a/functions/openapi/paths_kebab_case.go +++ b/functions/openapi/paths_kebab_case.go @@ -40,6 +40,9 @@ func (vp PathsKebabCase) RunRule(nodes []*yaml.Node, context model.RuleFunctionC continue } path := fmt.Sprintf("$.paths.%s", opPath) + if opPath == "/" { + continue + } notKebab, segments := checkPathCase(opPath) if notKebab { results = append(results, model.RuleFunctionResult{ diff --git a/functions/openapi/success_response.go b/functions/openapi/success_response.go index 63a04772..99ab5b15 100644 --- a/functions/openapi/success_response.go +++ b/functions/openapi/success_response.go @@ -84,7 +84,7 @@ func (sr SuccessResponse) RunRule(nodes []*yaml.Node, context model.RuleFunction } results = append(results, model.RuleFunctionResult{ - Message: fmt.Sprintf("Operation `%s` must define at least a single 2xx or 3xx response", name), + Message: fmt.Sprintf("Operation `%s` must define at least a single `2xx` or `3xx` response", name), StartNode: fieldNode, EndNode: endNode, Path: fmt.Sprintf("$.paths.%s.%s.%s", currentPath, currentVerb, context.RuleAction.Field), diff --git a/rulesets/ruleset_functions.go b/rulesets/ruleset_functions.go index 67a4c318..474babdb 100644 --- a/rulesets/ruleset_functions.go +++ b/rulesets/ruleset_functions.go @@ -1180,7 +1180,7 @@ func GetPathsKebabCaseRule() *model.Rule { Recommended: true, RuleCategory: model.RuleCategories[model.CategoryOperations], Type: validation, - Severity: err, + Severity: warn, Then: model.RuleAction{ Function: "pathsKebabCase", },