swagger-api / swagger-api/swagger-codegen-generators

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

Open
#1,288 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in AbstractKotlinCodegen and compare its toRegularExpression behavior with AbstractJavaCodegen; inspect the kotlin-spring beanValidationCore.mustache output. Done when generated @Pattern regexp values no longer include slash delimiters and the generated Kotlin validation matches the intended character pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.