diff --git a/README.md b/README.md
index ae645f3..7835567 100644
--- a/README.md
+++ b/README.md
@@ -84,6 +84,7 @@ fabrikt {
quarkusReflectionConfig = enabled
typeOverrides {
datetime = OffsetDateTime
+ binary = ByteArray
}
client {
generate = disabled
@@ -125,6 +126,7 @@ fabrikt {
| sourcesPath | The path for generated source files, interpreted relative to the output directory. | `src/main/kotlin` |
| resourcesPath | The path for generated resource files, interpreted relative to the output directory. | `src/main/resources` |
| typeOverrides.datetime | Specifies the Kotlin type for the OAS type `datetime`.
Values: `OffsetDateTime`, `Instant`, `LocalDateTime`. | `OffsetDateTime` |
+| typeOverrides.binary | Specifies the Kotlin type for the OAS type `string` with format `binary`.
Values: `ByteArray`, `InputStream`. | `ByteArray` |
| validationLibrary | Specifies the validation library used for annotations in generated model classes.
Values: `Javax`, `Jakarta`, `NoValidation`. | `Jakarta` |
| quarkusReflectionConfig | Enables generating the reflection-config.json file for quarkus integration projects.
Values: `enabled`, `disabled`, `true`, `false`. | `enabled` |
| client.generate | Enables generating the http client code.
Values: `enabled`, `disabled`, `true`, `false`. | `disabled` |
diff --git a/src/main/kotlin/ch/acanda/gradle/fabrikt/ConfigurationInitializer.kt b/src/main/kotlin/ch/acanda/gradle/fabrikt/ConfigurationInitializer.kt
index 1e45121..936a06e 100644
--- a/src/main/kotlin/ch/acanda/gradle/fabrikt/ConfigurationInitializer.kt
+++ b/src/main/kotlin/ch/acanda/gradle/fabrikt/ConfigurationInitializer.kt
@@ -17,6 +17,10 @@ internal fun initializeWithDefaults(
validationLibrary.assign(source.validationLibrary, defaults.validationLibrary)
// same as model.quarkusReflection?
quarkusReflectionConfig.assign(source.quarkusReflectionConfig, defaults.quarkusReflectionConfig)
+ with(typeOverrides) {
+ datetime.assign(source.typeOverrides.datetime, defaults.typeOverrides.datetime)
+ binary.assign(source.typeOverrides.binary, defaults.typeOverrides.binary)
+ }
typeOverrides.datetime.assign(source.typeOverrides.datetime, defaults.typeOverrides.datetime)
with(client) {
val s = source.client
diff --git a/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktExtension.kt b/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktExtension.kt
index 58e1728..01c50bf 100644
--- a/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktExtension.kt
+++ b/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktExtension.kt
@@ -126,6 +126,14 @@ open class TypeOverridesExtension @Inject constructor(objects: ObjectFactory) {
@Suppress("VariableNaming")
val LocalDateTime: DateTimeOverrideOption = DateTimeOverrideOption.LocalDateTime
+ val binary: Property = objects.property(BinaryOverrideOption::class.java)
+
+ @Suppress("VariableNaming")
+ val ByteArray: BinaryOverrideOption = BinaryOverrideOption.ByteArray
+
+ @Suppress("VariableNaming")
+ val InputStream: BinaryOverrideOption = BinaryOverrideOption.InputStream
+
}
open class GenerateClientExtension @Inject constructor(objects: ObjectFactory) {
diff --git a/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktOptions.kt b/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktOptions.kt
index 9c3d423..2eb2a65 100644
--- a/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktOptions.kt
+++ b/src/main/kotlin/ch/acanda/gradle/fabrikt/FabriktOptions.kt
@@ -26,6 +26,13 @@ enum class DateTimeOverrideOption(
LocalDateTime(CodeGenTypeOverride.DATETIME_AS_LOCALDATETIME),
}
+enum class BinaryOverrideOption(
+ override val fabriktOption: CodeGenTypeOverride?,
+) : FabriktOption {
+ ByteArray(null),
+ InputStream(CodeGenTypeOverride.BYTEARRAY_AS_INPUTSTREAM),
+}
+
enum class ValidationLibraryOption(
override val fabriktOption: ValidationLibrary,
) : FabriktOption {
diff --git a/src/main/kotlin/ch/acanda/gradle/fabrikt/GenerateTaskConfiguration.kt b/src/main/kotlin/ch/acanda/gradle/fabrikt/GenerateTaskConfiguration.kt
index afdefb8..24c14ba 100644
--- a/src/main/kotlin/ch/acanda/gradle/fabrikt/GenerateTaskConfiguration.kt
+++ b/src/main/kotlin/ch/acanda/gradle/fabrikt/GenerateTaskConfiguration.kt
@@ -143,6 +143,18 @@ open class TypeOverridesConfiguration @Inject constructor(objects: ObjectFactory
@Suppress("VariableNaming")
val LocalDateTime: DateTimeOverrideOption = DateTimeOverrideOption.LocalDateTime
+ @get:Input
+ @get:Optional
+ val binary: Property = objects.property(BinaryOverrideOption::class.java)
+
+ @get:Internal
+ @Suppress("VariableNaming")
+ val ByteArray: BinaryOverrideOption = BinaryOverrideOption.ByteArray
+
+ @get:Internal
+ @Suppress("VariableNaming")
+ val InputStream: BinaryOverrideOption = BinaryOverrideOption.InputStream
+
}
open class GenerateClientConfiguration @Inject constructor(objects: ObjectFactory) {
@@ -347,6 +359,15 @@ open class TypeOverridesDefaults @Inject constructor(objects: ObjectFactory) {
@Suppress("VariableNaming")
val LocalDateTime: DateTimeOverrideOption = DateTimeOverrideOption.LocalDateTime
+ val binary: Property =
+ objects.property(BinaryOverrideOption::class.java).convention(BinaryOverrideOption.ByteArray)
+
+ @Suppress("VariableNaming")
+ val ByteArray: BinaryOverrideOption = BinaryOverrideOption.ByteArray
+
+ @Suppress("VariableNaming")
+ val InputStream: BinaryOverrideOption = BinaryOverrideOption.InputStream
+
}
open class GenerateClientDefaults @Inject constructor(objects: ObjectFactory) {
diff --git a/src/main/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArguments.kt b/src/main/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArguments.kt
index 61d4159..bff3790 100644
--- a/src/main/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArguments.kt
+++ b/src/main/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArguments.kt
@@ -1,10 +1,12 @@
package ch.acanda.gradle.fabrikt.generator
+import ch.acanda.gradle.fabrikt.FabriktOption
import ch.acanda.gradle.fabrikt.GenerateTaskConfiguration
import com.cjbooms.fabrikt.cli.ClientCodeGenOptionType
import com.cjbooms.fabrikt.cli.CodeGenerationType
import com.cjbooms.fabrikt.cli.ControllerCodeGenOptionType
import com.cjbooms.fabrikt.cli.ModelCodeGenOptionType
+import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
internal const val ARG_API_FILE = "--api-file"
@@ -64,12 +66,14 @@ internal data class FabriktArguments(private val config: GenerateTaskConfigurati
}
private fun GenerateTaskConfiguration.addTypeOverridesArgs(args: MutableList) = with(typeOverrides) {
- val overrides = listOfNotNull(
- datetime.orNull?.fabriktOption
- )
- if (overrides.isNotEmpty()) {
+ addTypeOverrideArg(args, datetime)
+ addTypeOverrideArg(args, binary)
+ }
+
+ private fun addTypeOverrideArg(args: MutableList, property: Property) {
+ property.orNull?.fabriktOption?.let { option ->
args.add(ARG_TYPE_OVERRIDES)
- args.addAll(overrides.map { it.name })
+ args.add(option.name)
}
}
diff --git a/src/test/kotlin/ch/acanda/gradle/fabrikt/Generators.kt b/src/test/kotlin/ch/acanda/gradle/fabrikt/Generators.kt
index 7434d12..163971c 100644
--- a/src/test/kotlin/ch/acanda/gradle/fabrikt/Generators.kt
+++ b/src/test/kotlin/ch/acanda/gradle/fabrikt/Generators.kt
@@ -24,6 +24,7 @@ internal val generateTaskExtGen: Arb = arbitrary {
resourcesPath.set(Arb.stringPattern("[a-z]{1,5}(/[a-z]{1,5}){0,3}").orNull(0.2).bind())
quarkusReflectionConfig.set(Arb.boolean().orNull(0.2).bind())
typeOverrides.datetime.set(Arb.enum().orNull(0.2).bind())
+ typeOverrides.binary.set(Arb.enum().orNull(0.2).bind())
validationLibrary.set(Arb.enum().orNull(0.2).bind())
client.generate.set(Arb.boolean().orNull(0.2).bind())
client.resilience4j.set(Arb.boolean().orNull(0.2).bind())
diff --git a/src/test/kotlin/ch/acanda/gradle/fabrikt/GradleTest.kt b/src/test/kotlin/ch/acanda/gradle/fabrikt/GradleTest.kt
index 47b67e2..9268962 100644
--- a/src/test/kotlin/ch/acanda/gradle/fabrikt/GradleTest.kt
+++ b/src/test/kotlin/ch/acanda/gradle/fabrikt/GradleTest.kt
@@ -46,6 +46,7 @@ class GradleTest : StringSpec({
| quarkusReflectionConfig = enabled
| typeOverrides {
| datetime = Instant
+ | binary = InputStream
| }
| client {
| generate = enabled
@@ -118,6 +119,7 @@ class GradleTest : StringSpec({
| quarkusReflectionConfig = enabled
| typeOverrides {
| datetime = Instant
+ | binary = InputStream
| }
| client {
| generate = enabled
diff --git a/src/test/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArgumentsTest.kt b/src/test/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArgumentsTest.kt
index fa09205..51a3144 100644
--- a/src/test/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArgumentsTest.kt
+++ b/src/test/kotlin/ch/acanda/gradle/fabrikt/generator/FabriktArgumentsTest.kt
@@ -43,6 +43,7 @@ class FabriktArgumentsTest : StringSpec({
}
with(config.typeOverrides) {
cliArgs.shouldContainOptionally(datetime, ARG_TYPE_OVERRIDES)
+ cliArgs.shouldContainOptionally(binary, ARG_TYPE_OVERRIDES)
}
with(config.client) {
if (generate.get()) {