Skip to content

Commit d31dedc

Browse files
Fix: do not replace \r\n pattern for fields
1 parent 07c66ea commit d31dedc

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

boat-scaffold/src/main/java/com/backbase/oss/codegen/java/BoatSpringCodeGen.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public void execute(Fragment frag, Writer out) throws IOException {
124124
return;
125125
}
126126
String formatted = text
127-
.replace("\\n", SINGLE_SPACE)
128127
.replaceAll(WHITESPACE_REGEX, SINGLE_SPACE)
129128
.replaceAll("\\< ", "<")
130129
.replaceAll(" >", ">")

boat-scaffold/src/test/java/com/backbase/oss/codegen/java/BoatSpringCodeGenTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ void shouldGenerateValidations(boolean useLombok, boolean bigDecimalsAsStrings)
259259
assertFieldValueAssignment(
260260
multiLinePaymentRequestUnit, "arrangementIds", "new ArrayList<>()");
261261
assertFieldAnnotation(multiLinePaymentRequestUnit, "uniqueLines", "NotNull");
262+
assertFieldAnnotation(multiLinePaymentRequestUnit, "name", "Pattern", "@Pattern(regexp = \"^[^\\\\r\\\\n]{1,64}$\")");
262263
assertFieldValueAssignment(
263264
multiLinePaymentRequestUnit, "uniqueArrangementIds", null);
264265

@@ -450,6 +451,15 @@ private static void assertFieldAnnotation(
450451
fieldDeclaration.getAnnotationByName(annotationName).isPresent(), is(true));
451452
}
452453

454+
private static void assertFieldAnnotation(
455+
CompilationUnit unit, String fieldName, String annotationName, String value) throws FileNotFoundException {
456+
FieldDeclaration fieldDeclaration = findFieldDeclaration(unit, fieldName);
457+
AnnotationExpr annotation = fieldDeclaration.getAnnotationByName(annotationName)
458+
.orElseThrow(() -> new AssertionError(
459+
"Expect annotation to be present on field: " + annotationName + " " + fieldName));
460+
assertThat(annotation.toString(), equalTo(value));
461+
}
462+
453463
private static void assertFieldValueAssignment(
454464
CompilationUnit unit, String fieldName, String valueAssignment) throws FileNotFoundException {
455465
FieldDeclaration fieldDeclaration = findFieldDeclaration(unit, fieldName);

boat-scaffold/src/test/resources/boat-spring/openapi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ components:
315315
description: Request name
316316
minLength: 3
317317
maxLength: 251
318+
pattern: "^[^\\r\\n]{1,64}$"
318319
amountNumberAsString:
319320
description: The amount string in number format
320321
type: string

0 commit comments

Comments
 (0)