Skip to content

Commit

Permalink
fix unique property check in Joi models
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Jan 31, 2025
1 parent b8893ba commit a8d58af
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class JoiValidatorModuleRenderer constructor(override val vrapTypeProvider: Vrap
val patternConstraint = if (this.type is StringType && (this.type as StringType).pattern != null ) ".pattern(/${(this.type as StringType).pattern}/)" else ""
val joiLink = joiAlternativesTypes.contains(vrapType.simpleJoiName()) && discriminatorProperty
val joiSchema = if(joiLink)"Joi.link('#${vrapType.simpleJoiName()}')" else vrapType.renderTypeRef()
val uniquePropConstraint = if (this.getAnnotation("uniqueProperty") != null) ".unique(\"${(this.getAnnotation("uniqueProperty").value as StringInstance).value}\")" else ""
val uniqueAnnotation = this.getAnnotation("uniqueProperty") ?: this.type.getAnnotation("uniqueProperty")
val uniquePropConstraint = if (uniqueAnnotation != null) ".unique(\"${(uniqueAnnotation.value as StringInstance).value}\")" else ""
return "${name}: ${joiSchema}${maxConstraint}${patternConstraint}${discriminatorConstraint}${uniquePropConstraint}${requiredConstraint}"
}

Expand Down

0 comments on commit a8d58af

Please sign in to comment.