You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
I'm willing to sponsor/donate $100 for a fully working kotlin code from the figma openapi specification.
Description
I like to generate kotlin data classes from figma openapi specification
group ="org.example"
version ="1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(11)
}
plugins {
kotlin("jvm") version "2.0.10"
application
id("org.jetbrains.kotlin.plugin.serialization") version "2.1.0"
id("org.openapi.generator") version "7.11.0"
}
repositories {
mavenCentral()
}
sourceSets.main {
java.srcDirs("build/generated-sources/src/main")
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.8.0")
}
openApiGenerate {
generatorName.set("kotlin")
inputSpec.set("$projectDir/src/main/resources/figma/openapi.yaml")
outputDir.set("$buildDir/generated-sources")
apiPackage.set("org.example.figmaopenapitokotlin.figmaclient.api") // Package for API classes
modelPackage.set("org.example.figmaopenapitokotlin.figmaclient.model") // Package for model classes
invokerPackage.set("org.example.figmaopenapitokotlin.figmaclient.invoker") // Package for supporting classes
configOptions.set(
mapOf(
"dateLibrary" to "java8",
"serializationLibrary" to "kotlinx_serialization"
)
)
typeMappings.set(
mapOf(
// does not work: Too many arguments for 'constructor(): String'."number" to "kotlin.String",
"decimal" to "kotlin.String"
)
)
globalProperties.set(
mapOf(
"models" to ""// Generate only models
)
)
skipValidateSpec.set(true)
}
tasks.register("fixGeneratedCode") {
group ="build"
description ="Replaces invalid kotlin.String constructor calls with string literals"
doLast {
val generatedSourceDir = file("build/generated-sources") // Adjust the path to match your generated sources directoryif (generatedSourceDir.exists()) {
generatedSourceDir.walkTopDown()
.filter { it.isFile && it.extension =="kt" }
.forEach { file ->val updatedContent = file.readText()
.replace("""kotlin.String\("(.*?)"\)""".toRegex(), "\"$1\"") // Replace kotlin.String("value") with "value"
file.writeText(updatedContent)
}
} else {
println("Generated source directory not found: $generatedSourceDir")
}
}
}
Generation Details
.\gradlew openapigenerate
.\gradlew fixGeneratedCode
To get rid of the string constructor problem
.\gradlew assemble
Steps to reproduce
gradlew shows errors
Strings are created with a constructor (from number and decimal) which might be easy to solve like my fixGeneratedCode task. But there might be a better solution.
There are a lot of errors like
> Task :compileKotlin FAILED
e: file:///C:/Users/bladenth/IdeaProjects/figmaopenapitokotlin/build/generated-sources/src/main/kotlin/org/example/figmaopenapitokotlin/figmaclient/model/ActivityLogEntity.kt:45:1 @Serializable annotation without arguments can be used only on sealed interfaces.Non-sealed interfaces are polymorphically serializable by default.
e: file:///C:/Users/bladenth/IdeaProjects/figmaopenapitokotlin/build/generated-sources/src/main/kotlin/org/example/figmaopenapitokotlin/figmaclient/model/BooleanOperationNode.kt:199:56 Initializer type mismatch: expected 'org.example.figmaopenapitokotlin.figmaclient.model.BooleanOperationNode.LayoutGrow?', actual 'kotlin.String'.
Related issues/PRs
Suggest a fix
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Was not possible
I've used the latest version.
I'm willing to sponsor/donate $100 for a fully working kotlin code from the figma openapi specification.
Description
I like to generate kotlin data classes from figma openapi specification
Full example: figmaopenapitokotlin.zip
openapi-generator version
id("org.openapi.generator") version "7.11.0"
OpenAPI file
https://github.com/figma/rest-api-spec/blob/main/openapi/openapi.yaml
Gradle file
Generation Details
To get rid of the string constructor problem
Steps to reproduce
gradlew shows errors
Related issues/PRs
Suggest a fix
The text was updated successfully, but these errors were encountered: