Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,27 @@ jobs:
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'

- name: Build and Release
run: ./gradlew clean check shadowJar
env:
GRADLE_OPTS: "-Dorg.gradle.internal.http.connectionTimeout=120000 -Dorg.gradle.internal.http.socketTimeout=120000"
run: |
set -euo pipefail
for attempt in 1 2 3; do
echo "Gradle build attempt ${attempt}/3"
if ./gradlew --no-daemon clean check shadowJar; then
exit 0
fi

if [[ "${attempt}" -lt 3 ]]; then
echo "Build failed, retrying in 15 seconds..."
sleep 15
fi
done

echo "Build failed after 3 attempts."
exit 1

- run: ./scripts/install_local.sh
- name: Checkout
Expand All @@ -50,6 +68,7 @@ jobs:
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'

- name: Setup Node
uses: actions/setup-node@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fun Example.renderExample(exampleName: String, inlineExample: Boolean = false):
| <<${this.description.value.trim()}>>""" else ""}${if (this.annotations.isNotEmpty()) """
| <<${this.annotations.joinToString("\n") { it.renderAnnotation() }}>>""" else ""}
| strict: ${this.strict.value}
| value:${if (!inlineExample) " !include ../examples/$exampleName.json" else if (this.value is ObjectInstance) """|
| value:${if (!inlineExample) " !include ../examples/$exampleName.json" else if (this.value is ObjectInstance || this.value is ArrayInstance) """|
| <<${this.value.toJson().escapeAll()}>>""".trimMargin().keepAngleIndent().escapeAll() else " " + this.value.toJson().escapeAll() }
""".trimMargin().keepAngleIndent().escapeAll()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,32 @@ class TestCodeGenerator {
""".trimIndent().trimStart())
}

@Test
fun testArrayExampleRenderUsesMultilineBlock() {
val generatorConfig = CodeGeneratorConfig(
basePackageName = "com/commercetools/importer",
outputFolder = Paths.get("build/gensrc"),
inlineExamples = true
)

val apiProvider = RamlApiProvider(Paths.get("src/test/resources/arrayexample.raml"))

val dataSink = MemoryDataSink()
val generatorModule = RamlGeneratorModule(apiProvider, generatorConfig, RamldocBaseTypes, dataSink = dataSink)
val generatorComponent = RamlGeneratorComponent(generatorModule, RamldocModelModule)
generatorComponent.generateFiles()

Assertions.assertThat(dataSink.files).isNotEmpty()
val resourceContent = dataSink.files.entries
.filter { it.key.startsWith("resources/") }
.map { it.value }
.joinToString("\n")
Assertions.assertThat(resourceContent).isNotBlank()
Assertions.assertThat(resourceContent)
.contains("value: |")
.doesNotContain("value: [ {")
}

@Test
fun ramlRenderToRamlDoc() {
val generatorConfig = CodeGeneratorConfig(
Expand Down
22 changes: 22 additions & 0 deletions languages/ramldoc/src/test/resources/arrayexample.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#%RAML 1.0
---
title: Array Example Test API
version: 1.0
baseUri: http://example.com/api
/items:
get:
displayName: QueryItems
securedBy: []
responses:
200:
body:
application/json:
type: array
items:
type: object
examples:
default:
strict: true
value:
- name: "first"
- name: "second"
Loading