swagger-api / swagger-api/swagger-codegen-generators
Java: Generated @Pattern annotation does not encode the pattern
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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