From de645f6eedc273087da5963dce9f241b59c2ef83 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Fri, 8 Sep 2023 12:31:42 +0200 Subject: [PATCH] fix queryParameter placeholder annotation rule for inline types --- ...QueryParameterPlaceholderAnnotationRule.kt | 4 ++-- .../rmf/validators/ValidatorRulesTest.groovy | 5 ++++- .../placeholder-annotation-rule.raml | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/ctp-validators/src/main/kotlin/com/commercetools/rmf/validators/QueryParameterPlaceholderAnnotationRule.kt b/ctp-validators/src/main/kotlin/com/commercetools/rmf/validators/QueryParameterPlaceholderAnnotationRule.kt index 5d372cec8..3272f386e 100644 --- a/ctp-validators/src/main/kotlin/com/commercetools/rmf/validators/QueryParameterPlaceholderAnnotationRule.kt +++ b/ctp-validators/src/main/kotlin/com/commercetools/rmf/validators/QueryParameterPlaceholderAnnotationRule.kt @@ -18,10 +18,10 @@ class QueryParameterPlaceholderAnnotationRule(severity: RuleSeverity, options: L method.queryParameters.forEach { queryParameter -> run { if (exclude.contains(queryParameter.name).not() && queryParameter.isPatternParameter()) { - if (queryParameter.getAnnotation("placeholderParam") == null) { + if (queryParameter.getAnnotation("placeholderParam", true) == null) { validationResults.add(error(queryParameter, "Property \"{0}\" must define placeholder annotation", queryParameter.name)) } else { - val annoValue = queryParameter.getAnnotation("placeholderParam").value; + val annoValue = queryParameter.getAnnotation("placeholderParam",true).value; when (annoValue) { is ObjectInstance -> { if (!(annoValue.value.find { propertyValue -> propertyValue.name == "paramName" } != null && annoValue.value.find { propertyValue -> propertyValue.name == "template" } != null && annoValue.value.find { propertyValue -> propertyValue.name == "placeholder" } != null)) diff --git a/ctp-validators/src/test/groovy/com/commercetools/rmf/validators/ValidatorRulesTest.groovy b/ctp-validators/src/test/groovy/com/commercetools/rmf/validators/ValidatorRulesTest.groovy index 1c0e03460..2fed562d6 100644 --- a/ctp-validators/src/test/groovy/com/commercetools/rmf/validators/ValidatorRulesTest.groovy +++ b/ctp-validators/src/test/groovy/com/commercetools/rmf/validators/ValidatorRulesTest.groovy @@ -353,10 +353,13 @@ class ValidatorRulesTest extends Specification implements ValidatorFixtures { def uri = uriFromClasspath("/placeholder-annotation-rule.raml") def result = new RamlModelBuilder(validators).buildApi(uri) then: - result.validationResults.size == 3 + result.validationResults.size == 6 result.validationResults[0].message == "Property \"/invalid/\" must define placeholder annotation" result.validationResults[1].message == "Placeholder object must have fields paramName, template and placeholder" result.validationResults[2].message == "Placeholder value \"\" must be contained in the template \"text.en\"" + result.validationResults[3].message == "Property \"/invalidfoo/\" must define placeholder annotation" + result.validationResults[4].message == "Placeholder object must have fields paramName, template and placeholder" + result.validationResults[5].message == "Placeholder value \"\" must be contained in the template \"text.en\"" } def "placeholder annotation for query parameter must be object"() { diff --git a/ctp-validators/src/test/resources/placeholder-annotation-rule.raml b/ctp-validators/src/test/resources/placeholder-annotation-rule.raml index 7f4294d8c..8ea6bda90 100644 --- a/ctp-validators/src/test/resources/placeholder-annotation-rule.raml +++ b/ctp-validators/src/test/resources/placeholder-annotation-rule.raml @@ -13,6 +13,13 @@ annotationTypes: template: text. placeholder: locale type: string + /foo.[a-z]{2}/?: + (placeholderParam): + paramName: foo + template: foo. + placeholder: locale + type: string + description: foo filter: type: string /invalid/?: @@ -27,3 +34,18 @@ annotationTypes: template: text.en placeholder: locale type: string + /invalidfoo/?: + type: string + description: foo + /incompletefoo.[a-z]{2}/?: + (placeholderParam): + paramName: text + type: string + description: foo + /invalidplaceholderfoo.[a-z]{2}/?: + (placeholderParam): + paramName: text + template: text.en + placeholder: locale + type: string + description: foo