Skip to content

Commit a8d58af

Browse files
committed
fix unique property check in Joi models
1 parent b8893ba commit a8d58af

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

languages/typescript/src/main/kotlin/io/vrap/codegen/languages/typescript/joi/JoiValidatorModuleRenderer.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class JoiValidatorModuleRenderer constructor(override val vrapTypeProvider: Vrap
170170
val patternConstraint = if (this.type is StringType && (this.type as StringType).pattern != null ) ".pattern(/${(this.type as StringType).pattern}/)" else ""
171171
val joiLink = joiAlternativesTypes.contains(vrapType.simpleJoiName()) && discriminatorProperty
172172
val joiSchema = if(joiLink)"Joi.link('#${vrapType.simpleJoiName()}')" else vrapType.renderTypeRef()
173-
val uniquePropConstraint = if (this.getAnnotation("uniqueProperty") != null) ".unique(\"${(this.getAnnotation("uniqueProperty").value as StringInstance).value}\")" else ""
173+
val uniqueAnnotation = this.getAnnotation("uniqueProperty") ?: this.type.getAnnotation("uniqueProperty")
174+
val uniquePropConstraint = if (uniqueAnnotation != null) ".unique(\"${(uniqueAnnotation.value as StringInstance).value}\")" else ""
174175
return "${name}: ${joiSchema}${maxConstraint}${patternConstraint}${discriminatorConstraint}${uniquePropConstraint}${requiredConstraint}"
175176
}
176177

0 commit comments

Comments
 (0)