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

Java: Generated @Pattern annotation does not encode the pattern

Open
#854 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

My spec contains a pattern validation for a schema:

components:
  schemas:
    myCustomId:
      type: string
      pattern: '^[A-Z]\d{9}$'

When generating code the beanValidationCore.mustache uses the literal pattern from the Spec which leads to compile errors because the \ character is not escaped in the generated Java String.

I know I can just put the properly escaped pattern into the spec. But from a modeling/specification point of view I don't want to deal with Java specifics. IMHO that's the concern of the code generator for the platform.

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 with the generated Java annotation handling in beanValidationCore.mustache and compare it with the supplied schema pattern. Verify the generated Java string compiles while preserving the intended regular expression, then check generated output for the example schema.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.