Skip to content

Commit a1f3466

Browse files
authored
fix: remove \ from \\ in regex patterns for @pattern annotation (asyncapi#134)
1 parent 8fc77aa commit a1f3466

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

filters/all.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,9 @@ function createEnum(val){
161161
return result;
162162
};
163163
filter.createEnum = createEnum;
164+
165+
function addBackSlashToPattern(val) {
166+
let result = val.replace(/\\/g, "\\\\");
167+
return result;
168+
}
169+
filter.addBackSlashToPattern = addBackSlashToPattern;

template/src/main/java/com/asyncapi/model/$$objectSchema$$.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ public class {{allName}} {
132132
*/{% endif %}
133133
@JsonProperty("{{propName}}")
134134
{%- if propName | isRequired(schema.required()) %}@NotNull{% endif %}
135-
{%- if prop.minLength() or prop.maxLength() or prop.maxItems() or prop.minItems() %}@Size({% if prop.minLength() or prop.minItems() %}min = {{prop.minLength()}}{{prop.minItems()}}{% endif %}{% if prop.maxLength() or prop.maxItems() %}{% if prop.minLength() or prop.minItems() %},{% endif %}max = {{prop.maxLength()}}{{prop.maxItems()}}{% endif %}){% endif %}
136-
{%- if prop.pattern() %}@Pattern(regexp="{{prop.pattern()}}"){% endif %}
135+
{%- if prop.minLength() or prop.maxLength() or prop.maxItems() or prop.minItems() %}@Size({% if prop.minLength() or prop.minItems() %}min = {{prop.minLength()}}{{prop.minItems()}}{% endif %}{% if prop.maxLength() or prop.maxItems() %}{% if prop.minLength() or prop.minItems() %},{% endif %}max = {{prop.maxLength()}}{{prop.maxItems()}}{% endif %}){% endif %}
136+
{%- if prop.pattern() %}@Pattern(regexp="{{prop.pattern() | addBackSlashToPattern}}"){% endif %}
137137
{%- if prop.minimum() %}@Min({{prop.minimum()}}){% endif %}{% if prop.exclusiveMinimum() %}@Min({{prop.exclusiveMinimum() + 1}}){% endif %}
138138
{%- if prop.maximum() %}@Max({{prop.maximum()}}){% endif %}{% if prop.exclusiveMaximum() %}@Max({{prop.exclusiveMaximum() + 1}}){% endif %}
139139
public {{propType}} get{{className}}() {

0 commit comments

Comments
 (0)