swagger-api / swagger-codegen-generators

Apache License 2.0
280 stars 418 forks source link

Extra generated regex pattern delimiters ('/') generates code that does not work for kotlin #1288

Open robin123123123 opened 1 month ago

robin123123123 commented 1 month ago

DESCRIPTION It has been noted before, 10827 8124 that in some languages and frameworks it is not desirable to automatically include regular expression delimiters in a pattern.

I'm using some custom mustache files based on openapi-generator to generate classes for a kotlin-spring application : beanValidationCore.mustache

This now generates jakarta validation annotations like this:

@Pattern(regexp="/^[0-9a-zA-Z]{0,5}$/")

This does not work, as it's now matching the forward slash '/'.

PROPOSED SOLUTION My suggestion is to override toRegularExpression in the AbstractKotlinCodegen similar to what has been done in AbstractJavaCodegen, so that it does not create extra regular expression delimiters. It's easier to add this in a mustache/handlebar files, than to remove it.