From e335204fbe461b85745cb2e4d1ca77a07c6ec6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Tue, 9 Jun 2026 17:54:25 +0200 Subject: [PATCH] test(plugin): add compilation test for a feature-rich spec Generates code from a spec exercising models, enums, oneOf polymorphism, allOf, all parameter locations, a JSON request body, UUID/date formats, and bearer security, then runs `compileKotlin` in a real Gradle project (TestKit) to prove the output compiles against the actual Ktor / kotlinx-serialization / kotlinx-datetime dependencies and the serialization compiler plugin. This uses the existing functionalTest harness (real compiler + real plugins) rather than kotlin-compile-testing, which does not yet support Kotlin 2.4. functionalTest runs as part of `./gradlew check` and CI. Closes #46 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../gradle/JustworksPluginFunctionalTest.kt | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/plugin/src/functionalTest/kotlin/com/avsystem/justworks/gradle/JustworksPluginFunctionalTest.kt b/plugin/src/functionalTest/kotlin/com/avsystem/justworks/gradle/JustworksPluginFunctionalTest.kt index 762f67d..d41da67 100644 --- a/plugin/src/functionalTest/kotlin/com/avsystem/justworks/gradle/JustworksPluginFunctionalTest.kt +++ b/plugin/src/functionalTest/kotlin/com/avsystem/justworks/gradle/JustworksPluginFunctionalTest.kt @@ -99,6 +99,7 @@ class JustworksPluginFunctionalTest { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.1") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.8.0") implementation("io.ktor:ktor-client-core:3.1.1") implementation("io.ktor:ktor-client-content-negotiation:3.1.1") implementation("io.ktor:ktor-serialization-kotlinx-json:3.1.1") @@ -191,6 +192,125 @@ class JustworksPluginFunctionalTest { assertTrue(content.contains("class PetsApi"), "PetsApi should define PetsApi class") } + @Test + fun `generated code for a feature-rich spec compiles`() { + // Exercises models, enums, oneOf polymorphism, allOf, all parameter locations, + // a JSON request body, UUID / date / date-time formats, and bearer security. + writeFile( + "api/petstore.yaml", + """ + openapi: '3.0.0' + info: + title: Featureful + version: '1.0' + security: + - bearerAuth: [] + paths: + /pets: + get: + operationId: listPets + summary: List pets + tags: [pets] + parameters: + - { name: limit, in: query, schema: { type: integer, format: int32 } } + - { name: X-Trace, in: header, schema: { type: string } } + responses: + '200': + description: ok + content: + application/json: + schema: { type: array, items: { ${'$'}ref: '#/components/schemas/Pet' } } + post: + operationId: createPet + tags: [pets] + requestBody: + required: true + content: + application/json: + schema: { ${'$'}ref: '#/components/schemas/NewPet' } + responses: + '201': + description: created + content: + application/json: + schema: { ${'$'}ref: '#/components/schemas/Pet' } + /pets/{petId}: + get: + operationId: getPet + tags: [pets] + parameters: + - { name: petId, in: path, required: true, schema: { type: integer, format: int64 } } + responses: + '200': + description: ok + content: + application/json: + schema: { ${'$'}ref: '#/components/schemas/Pet' } + components: + securitySchemes: + bearerAuth: + type: http + scheme: bearer + schemas: + Pet: + type: object + required: [id, name] + properties: + id: { type: integer, format: int64 } + uuid: { type: string, format: uuid } + birthday: { type: string, format: date } + name: { type: string } + status: { ${'$'}ref: '#/components/schemas/PetStatus' } + NewPet: + type: object + required: [name] + properties: + name: { type: string } + Identified: + type: object + required: [id] + properties: + id: { type: integer, format: int64 } + NamedPet: + allOf: + - ${'$'}ref: '#/components/schemas/Identified' + - type: object + properties: + name: { type: string } + PetStatus: + type: string + enum: [available, pending, sold] + Shape: + oneOf: + - ${'$'}ref: '#/components/schemas/Circle' + - ${'$'}ref: '#/components/schemas/Square' + discriminator: + propertyName: kind + Circle: + type: object + required: [kind, radius] + properties: + kind: { type: string } + radius: { type: number, format: double } + Square: + type: object + required: [kind, side] + properties: + kind: { type: string } + side: { type: number, format: double } + """.trimIndent(), + ) + writeBuildFile() + + val result = runner("compileKotlin").build() + + assertEquals( + TaskOutcome.SUCCESS, + result.task(":compileKotlin")?.outcome, + "Generated code from a feature-rich spec should compile", + ) + } + @Test fun `second run is UP-TO-DATE when inputs unchanged`() { writeBuildFile() @@ -551,6 +671,7 @@ class JustworksPluginFunctionalTest { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.1") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.8.0") implementation("io.ktor:ktor-client-core:3.1.1") implementation("io.ktor:ktor-client-content-negotiation:3.1.1") implementation("io.ktor:ktor-serialization-kotlinx-json:3.1.1")