Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the task @CacheableTask, and explicitly add @OutputDirectory #46

Merged
merged 2 commits into from
Jul 3, 2024
Merged
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
9 changes: 6 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ Add the following to your `build.gradle.kts` file.

```kotlin
plugin {
id("io.github.nomisrev.openapi.plugin") version "0.0.1"
id("io.github.nomisrev.openapi-kt-plugin") version "0.0.4"
}

openApiConfig {
spec.set(file("openapi.json"))
spec("OpenAI", file("openai.yaml")) {
// packageName = "my.company.openai.generated"
}
}
```

Then run the following command to generate the code.
Then run the following command to generate the code,
but it will also automatically run when you build your project.

```shell
./gradlew generateOpenApi
Expand Down
4 changes: 3 additions & 1 deletion example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ plugins {
id("io.github.nomisrev.openapi-kt-plugin") version "0.0.4"
}

openApiConfig { spec("OpenAI", file("openai.yaml")) { packageName = "io.github.nomisrev.openai" } }
openApiConfig { spec("OpenAI", file("openai.yaml")) {
packageName = "io.github.nomisrev.openai" }
}

kotlin {
jvm()
Expand Down
17 changes: 16 additions & 1 deletion plugin/README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Module OpenAPI Kotlin Gradle Plugin

OpenAPI Kotlin Gradle Plugin is a Gradle plugin that uses `generation` to generate Kotlin Code.
OpenAPI Kotlin Gradle Plugin is a Gradle plugin that uses `generation` to generate Kotlin Code.

To use the plugin, you need to add the following to your `build.gradle.kts` file:

```kotlin
openApiConfig {
spec("OpenAI", file("openai.yaml")) {
// packageName = "io.github.nomisrev.openai"
}
}
```

This will generate the Kotlin code from the `openai.yaml` file,
and the generated code will be placed in the `build/generated` directory.

The Gradle plugin automatically adds the generated code to the source set of the project.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ package io.github.nomisrev.openapi.plugin

import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.workers.WorkerExecutor

@CacheableTask
abstract class GenerateClientTask : DefaultTask() {
init {
description = "Generate a Kotlin client based on a configure OpenAPI Specification."
group = "openapi"
}

@get:Input
@get:SkipWhenEmpty
@get:Option(option = "OpenApiSpec", description = "The OpenAPI configuration")
abstract val spec: ListProperty<SpecDefinition>

@get:OutputDirectory abstract val output: DirectoryProperty

@Inject abstract fun getWorkerExecutor(): WorkerExecutor

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class OpenAPIPlugin : Plugin<Project> {
val generateOpenApiClient =
register("generateOpenApiClient", GenerateClientTask::class.java) {
it.spec.set(extension.specs)
it.output.set(project.output)
}

maybeCreate("prepareKotlinIdeaImport").dependsOn(generateOpenApiClient)
Expand Down
Loading