Bug Report Checklist
Description
When using a regex pattern in an OpenAPI template, openapi-generator will now emit validate:"regexp=..." tags into generated data structures. Unfortunately, the tags are escaped twice somewhere, resulting in 4 consecutive backslashes if the original pattern contained character classes or escape sequences.
Escaping is necessary, but escaping twice is incorrect and leads to problems with regex validation later.
I was previously using the x-go-custom-tag property to insert validate tags into the generated code, and validate those using a 3rd party validation package. This still works fine, but requires removing any extra escaping backslashes, because openapi-generator is now automatically escaping them.
openapi-generator version
This is a regression since 7.7.0, patterns were ignored in 7.6.0 and before.
OpenAPI declaration file content or url
---
openapi: 3.0.0
info:
title: unset
version: "1"
paths: {}
components:
schemas:
Bar:
type: object
properties:
Email:
type: string
pattern: '^\S+@\S+$'
Generation Details
No special options or environment needed.
The CLI was executed using the official Docker container as follows:
openapi-generator-cli generate -i regex.yaml -g go -o openapi
Steps to reproduce
Run the generator on the template to produce Go code, as described above.
The model for Bar renders as:
type Bar struct {
Email *string `json:"Email,omitempty" validate:"regexp=^\\\\S+@\\\\S+$"`
}
My expectation is that the backslashes are properly escaped, using a single extra backslash:
type Bar struct {
Email *string `json:"Email,omitempty" validate:"regexp=^\\S+@\\S+$"`
}
Related issues/PRs
N/A
Suggest a fix
Bug Report Checklist
Description
When using a regex pattern in an OpenAPI template, openapi-generator will now emit
validate:"regexp=..."tags into generated data structures. Unfortunately, the tags are escaped twice somewhere, resulting in 4 consecutive backslashes if the original pattern contained character classes or escape sequences.Escaping is necessary, but escaping twice is incorrect and leads to problems with regex validation later.
I was previously using the
x-go-custom-tagproperty to insert validate tags into the generated code, and validate those using a 3rd party validation package. This still works fine, but requires removing any extra escaping backslashes, because openapi-generator is now automatically escaping them.openapi-generator version
This is a regression since 7.7.0, patterns were ignored in 7.6.0 and before.
OpenAPI declaration file content or url
Generation Details
No special options or environment needed.
The CLI was executed using the official Docker container as follows:
Steps to reproduce
Run the generator on the template to produce Go code, as described above.
The model for
Barrenders as:My expectation is that the backslashes are properly escaped, using a single extra backslash:
Related issues/PRs
N/A
Suggest a fix