Skip to content

Commit eba0b68

Browse files
committed
handle file content that does not end with curly brace (#303)
(cherry picked from commit 9602441)
1 parent ab7595c commit eba0b68

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/writer/java/GoogleFormatter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ open class GoogleFormatter: SourceFormatter {
3434
// put line feed before last closing }
3535
private fun correctLineFeed(formatted: String): String {
3636
val index = formatted.lastIndexOf("}")
37+
if (index == -1) {
38+
return formatted
39+
}
3740

3841
return StringBuilder()
3942
.append(formatted.substring(0, index))

openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/writer/java/GoogleFormatterSpec.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,22 @@ class GoogleFormatterSpec : StringSpec({
3838
formatter.format("....")
3939
}
4040
}
41+
42+
"does handle package-info.java, no closing curly brace" {
43+
val formatter = GoogleFormatter()
44+
45+
formatter.format(
46+
"""
47+
| @org.springframework.lang.NonNullApi
48+
|@org.springframework.lang.NonNullFields
49+
| package generated.spring;
50+
|
51+
""".trimMargin()
52+
) shouldBe """
53+
|@org.springframework.lang.NonNullApi
54+
|@org.springframework.lang.NonNullFields
55+
|package generated.spring;
56+
|
57+
""".trimMargin()
58+
}
4159
})

0 commit comments

Comments
 (0)