diff --git a/jellyfin-model/api/jellyfin-model.api b/jellyfin-model/api/jellyfin-model.api index 2ccbdb020..52acd0f61 100644 --- a/jellyfin-model/api/jellyfin-model.api +++ b/jellyfin-model/api/jellyfin-model.api @@ -24,6 +24,11 @@ public final class org/jellyfin/sdk/model/DeviceInfo { public fun toString ()Ljava/lang/String; } +public final class org/jellyfin/sdk/model/RegexValidator { + public static final field INSTANCE Lorg/jellyfin/sdk/model/RegexValidator; + public final fun matches (Ljava/lang/String;Ljava/lang/String;)Z +} + public final class org/jellyfin/sdk/model/ServerVersion : java/lang/Comparable { public static final field Companion Lorg/jellyfin/sdk/model/ServerVersion$Companion; public fun (IIILjava/lang/Integer;)V diff --git a/jellyfin-model/src/commonMain/kotlin/org/jellyfin/sdk/model/RegexValidator.kt b/jellyfin-model/src/commonMain/kotlin/org/jellyfin/sdk/model/RegexValidator.kt new file mode 100644 index 000000000..8b32345a5 --- /dev/null +++ b/jellyfin-model/src/commonMain/kotlin/org/jellyfin/sdk/model/RegexValidator.kt @@ -0,0 +1,10 @@ +package org.jellyfin.sdk.model + + +public object RegexValidator { + private val patterns = mutableMapOf() + + public fun matches(value: String, pattern: String): Boolean { + return patterns.getOrPut(pattern) { Regex(pattern) }.matches(value) + } +} diff --git a/openapi-generator/src/main/kotlin/org/jellyfin/openapi/builder/api/OperationBuilder.kt b/openapi-generator/src/main/kotlin/org/jellyfin/openapi/builder/api/OperationBuilder.kt index 6a8b3f43a..fd178556c 100644 --- a/openapi-generator/src/main/kotlin/org/jellyfin/openapi/builder/api/OperationBuilder.kt +++ b/openapi-generator/src/main/kotlin/org/jellyfin/openapi/builder/api/OperationBuilder.kt @@ -71,21 +71,21 @@ open class OperationBuilder( is RegexValidation -> addCode(CodeBlock.builder().apply { if (parameter.type.isNullable) { addStatement( - "%M(%N·==·null·||·%M(%P).matches(%N))·{·%P·}", + "%M(%N·==·null·||·%M.matches(%N,%P))·{·%P·}", MemberName("kotlin", "require"), parameter.name, - MemberName("kotlin.text", "Regex"), - validation.pattern, + MemberName("org.jellyfin.sdk.model", "RegexValidator"), parameter.name, + validation.pattern, "Parameter \"${parameter.name}\" must match ${validation.pattern}." ) } else { addStatement( - "%M(%M(%P).matches(%N))·{·%P·}", + "%M(%M.matches(%N,%P))·{·%P·}", MemberName("kotlin", "require"), - MemberName("kotlin.text", "Regex"), - validation.pattern, + MemberName("org.jellyfin.sdk.model", "RegexValidator"), parameter.name, + validation.pattern, "Parameter \"${parameter.name}\" must match ${validation.pattern}." ) }