Skip to content

Commit

Permalink
fix queryParameter placeholder annotation rule for inline types
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Sep 8, 2023
1 parent fc1b383 commit de645f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"<locale>\" 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 \"<locale>\" must be contained in the template \"text.en\""
}

def "placeholder annotation for query parameter must be object"() {
Expand Down
22 changes: 22 additions & 0 deletions ctp-validators/src/test/resources/placeholder-annotation-rule.raml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ annotationTypes:
template: text.<locale>
placeholder: locale
type: string
/foo.[a-z]{2}/?:
(placeholderParam):
paramName: foo
template: foo.<locale>
placeholder: locale
type: string
description: foo
filter:
type: string
/invalid/?:
Expand All @@ -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

0 comments on commit de645f6

Please sign in to comment.