OpenAPITools / OpenAPITools/openapi-generator
[BUG] figma OpenAPI specification to kotlin
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
Was not possible - Have you tested with the latest master to confirm the issue still exists?
I've used the latest version. - Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [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
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
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 directory
if (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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the generation using the linked Figma openapi.yaml and the shown Gradle openApiGenerate configuration, then inspect the generated ActivityLogEntity.kt and BooleanOperationNode.kt errors. Compare the Kotlin serialization output and number/decimal mappings with the compile failures; done means the generated models compile without the manual fixGeneratedCode task.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- backend-api-design, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100