Skip to content

[JavaSpring] Bug generating @Pattern regex #9509

Closed
@elier

Description

@elier
Description

When generating from this yaml file:
https://raw.githubusercontent.com/OpenBankingUK/account-info-api-spec/master/dist/v2.0.0/account-info-swagger.yaml

Regex pattern like this '^\d{1,13}.\d{1,5}$' are not escape property and the generated java code does not compile.

To discuss: Should the code generation be responsible for escaping the regex properly for every language? or Should I modify the YAML to provide the appropriated escape?

Swagger-codegen version

3.0.8

Swagger declaration file content or url
definitions:
  Amount:
    type: string
    pattern: '^\d{1,13}\.\d{1,5}$'
Command line used for generation

swagger-codegen generate -i https://raw.githubusercontent.com/OpenBankingUK/account-info-api-spec/master/dist/v2.0.0/account-info-swagger.yaml -l spring -o api-server

Steps to reproduce

swagger-codegen generate -i https://raw.githubusercontent.com/OpenBankingUK/account-info-api-spec/master/dist/v2.0.0/account-info-swagger.yaml -l spring -o api-account
mvn install

Related issues/PRs
Suggest a fix/enhancement

Wrong java code generated:

@Pattern(regexp="^\d{1,13}\.\d{1,5}$")   

Right code generated should be: \

@Pattern(regexp="^\\d{1,13}\\.\\d{1,5}$")   

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions