Skip to content

Commit

Permalink
Merge pull request #916 from Kotlin/openapi-runtime
Browse files Browse the repository at this point in the history
Split OpenAPI in module needed for user projects and module needed for code-generation
  • Loading branch information
koperagen authored Oct 16, 2024
2 parents a5a2311 + 92ab4dc commit 40c0113
Show file tree
Hide file tree
Showing 40 changed files with 112 additions and 66 deletions.
6 changes: 4 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,10 @@ tasks.withType<Jar> {
}

// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
tasks.named { it.startsWith("publish") }.configureEach {
dependsOn(processKDocsMain, changeJarTask)
tasks.configureEach {
if (name.startsWith("publish")) {
dependsOn(processKDocsMain, changeJarTask)
}
}

// Exclude the generated/processed sources from the IDE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ internal class Integration(private val notebook: Notebook, private val options:
"org.jetbrains.kotlinx:dataframe-jdbc:$version",
"org.jetbrains.kotlinx:dataframe-arrow:$version",
"org.jetbrains.kotlinx:dataframe-openapi:$version",
"org.jetbrains.kotlinx:dataframe-openapi-generator:$version",
)
}

Expand Down
53 changes: 53 additions & 0 deletions dataframe-openapi-generator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
plugins {
with(libs.plugins) {
alias(kotlin.jvm)
alias(publisher)
alias(serialization)
alias(kover)
alias(ktlint)
alias(jupyter.api)
}
}

group = "org.jetbrains.kotlinx"

val jupyterApiTCRepo: String by project

repositories {
mavenLocal()
mavenCentral()
maven(jupyterApiTCRepo)
}

dependencies {
api(project(":core"))
api(project(":dataframe-openapi"))

implementation(libs.sl4j)
implementation(libs.kotlinLogging)
implementation(libs.kotlin.reflect)
implementation(libs.kotlinpoet)
api(libs.swagger) {
// Fix for Android
exclude("jakarta.validation")
}

testApi(project(":core"))
testImplementation(libs.junit)
testImplementation(libs.kotestAssertions) {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
}
}

kotlinPublications {
publication {
publicationName = "dataframeOpenApi"
artifactId = project.name
description = "OpenAPI code generation support for Kotlin Dataframe"
packageName = artifactId
}
}

kotlin {
explicitApi()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jetbrains.kotlinx.dataframe.io

import org.jetbrains.kotlinx.dataframe.codeGen.FieldType
import org.jetbrains.kotlinx.dataframe.codeGen.Marker
import org.jetbrains.kotlinx.dataframe.codeGen.MarkerVisibility
import org.jetbrains.kotlinx.dataframe.codeGen.ValidFieldName

internal fun AdditionalProperty.Companion.getMarker(typeArguments: List<String>) =
Marker(
name = AdditionalProperty::class.qualifiedName!!,
isOpen = false,
fields = listOf(
generatedFieldOf(
fieldName = ValidFieldName.of(AdditionalProperty<*>::key.name),
columnName = AdditionalProperty<*>::key.name,
overrides = false,
fieldType = FieldType.ValueFieldType(String::class.qualifiedName!!),
),
generatedFieldOf(
fieldName = ValidFieldName.of(AdditionalProperty<*>::`value`.name),
columnName = AdditionalProperty<*>::`value`.name,
overrides = false,
fieldType = FieldType.ValueFieldType(Any::class.qualifiedName!! + "?"),
),
),
superMarkers = emptyList(),
visibility = MarkerVisibility.EXPLICIT_PUBLIC,
typeParameters = emptyList(),
typeArguments = typeArguments,
)
31 changes: 4 additions & 27 deletions dataframe-openapi/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
plugins {
with(libs.plugins) {
alias(kotlin.jvm)
alias(publisher)
alias(serialization)
alias(kover)
alias(ktlint)
alias(jupyter.api)
}
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.ktlint)
alias(libs.plugins.publisher)
alias(libs.plugins.jupyter.api)
}

group = "org.jetbrains.kotlinx"

val jupyterApiTCRepo: String by project

repositories {
mavenLocal()
mavenCentral()
maven(jupyterApiTCRepo)
}

dependencies {
api(project(":core"))

implementation(libs.sl4j)
implementation(libs.kotlinLogging)
implementation(libs.kotlin.reflect)
implementation(libs.kotlinpoet)
api(libs.swagger) {
// Fix for Android
exclude("jakarta.validation")
}

testApi(project(":core"))
testImplementation(libs.junit)
testImplementation(libs.kotestAssertions) {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
}
}

kotlinPublications {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package org.jetbrains.kotlinx.dataframe.io

import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
import org.jetbrains.kotlinx.dataframe.api.KeyValueProperty
import org.jetbrains.kotlinx.dataframe.codeGen.FieldType
import org.jetbrains.kotlinx.dataframe.codeGen.Marker
import org.jetbrains.kotlinx.dataframe.codeGen.MarkerVisibility
import org.jetbrains.kotlinx.dataframe.codeGen.ValidFieldName

/**
* A [DataSchema] interface can implement this if it represents a map-like data schema (so key: value).
Expand All @@ -19,29 +15,5 @@ public interface AdditionalProperty<T> : KeyValueProperty<T> {
/** Value of the property. */
override val value: T

public companion object {
internal fun getMarker(typeArguments: List<String>) =
Marker(
name = AdditionalProperty::class.qualifiedName!!,
isOpen = false,
fields = listOf(
generatedFieldOf(
fieldName = ValidFieldName.of(AdditionalProperty<*>::key.name),
columnName = AdditionalProperty<*>::key.name,
overrides = false,
fieldType = FieldType.ValueFieldType(String::class.qualifiedName!!),
),
generatedFieldOf(
fieldName = ValidFieldName.of(AdditionalProperty<*>::`value`.name),
columnName = AdditionalProperty<*>::`value`.name,
overrides = false,
fieldType = FieldType.ValueFieldType(Any::class.qualifiedName!! + "?"),
),
),
superMarkers = emptyList(),
visibility = MarkerVisibility.EXPLICIT_PUBLIC,
typeParameters = emptyList(),
typeArguments = typeArguments,
)
}
public companion object
}
6 changes: 6 additions & 0 deletions docs/StardustDocs/topics/gettingStartedGradleAdvanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ dependencies {
implementation("org.jetbrains.kotlinx:dataframe-jdbc:%dataFrameVersion%")
implementation("org.jetbrains.kotlinx:dataframe-arrow:%dataFrameVersion%")
implementation("org.jetbrains.kotlinx:dataframe-openapi:%dataFrameVersion%")

// This artifact is only needed to directly call functions that generate @DataSchema code from OpenAPI specifications
// It's used by Gradle and KSP plugins internally.
// Your project needs dataframe-openapi to use generated code
implementation("org.jetbrains.kotlinx:dataframe-openapi-generator:%dataFrameVersion%")
}
```

Expand All @@ -144,6 +149,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:dataframe-jdbc:%dataFrameVersion%'
implementation 'org.jetbrains.kotlinx:dataframe-arrow:%dataFrameVersion%'
implementation 'org.jetbrains.kotlinx:dataframe-openapi:%dataFrameVersion%'
implementation 'org.jetbrains.kotlinx:dataframe-openapi-generator:%dataFrameVersion%'
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 3 additions & 2 deletions plugins/dataframe-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
api(libs.kotlin.reflect)
implementation(project(":core"))
implementation(project(":dataframe-arrow"))
implementation(project(":dataframe-openapi"))
implementation(project(":dataframe-openapi-generator"))
implementation(project(":dataframe-excel"))
implementation(project(":dataframe-jdbc"))

Expand Down Expand Up @@ -116,12 +116,13 @@ val integrationTestTask = task<Test>("integrationTest") {
dependsOn(":dataframe-arrow:publishToMavenLocal")
dependsOn(":dataframe-excel:publishToMavenLocal")
dependsOn(":dataframe-jdbc:publishToMavenLocal")
dependsOn(":dataframe-openapi-generator:publishToMavenLocal")
dependsOn(":dataframe-openapi:publishToMavenLocal")
dependsOn(":publishApiPublicationToMavenLocal")
dependsOn(":dataframe-arrow:publishDataframeArrowPublicationToMavenLocal")
dependsOn(":dataframe-excel:publishDataframeExcelPublicationToMavenLocal")
dependsOn(":dataframe-jdbc:publishDataframeJDBCPublicationToMavenLocal")
dependsOn(":dataframe-openapi:publishDataframeOpenApiPublicationToMavenLocal")
dependsOn(":dataframe-openapi-generator:publishDataframeOpenApiPublicationToMavenLocal")
dependsOn(":plugins:symbol-processor:publishMavenPublicationToMavenLocal")
dependsOn(":core:publishCorePublicationToMavenLocal")
description = "Runs integration tests."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
val cfgsToAdd = configs.toMutableSet()

configs.forEach { cfg ->
target.configurations.named { it == cfg }.configureEach {
target.configurations.findByName(cfg)?.apply {
cfgsToAdd.remove(cfg)
dependencies.add(
target.dependencies.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ fun runGradleBuild(
fun gradleRunner(buildDir: File, task: String): GradleRunner =
GradleRunner.create()
.withProjectDir(buildDir)
// if we use api from the newest Gradle release, a user project will fail with NoSuchMethod
// testing compatibility with an older Gradle version ensures our plugin can run on as many versions as possible
.withGradleVersion("8.5")
.withPluginClasspath()
.withArguments(task, "--stacktrace", "--info")
.withDebug(true)
Expand Down
2 changes: 1 addition & 1 deletion plugins/symbol-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ group = "org.jetbrains.kotlinx.dataframe"
dependencies {
implementation(project(":core"))
implementation(project(":dataframe-arrow"))
implementation(project(":dataframe-openapi"))
implementation(project(":dataframe-openapi-generator"))
implementation(project(":dataframe-excel"))
implementation(project(":dataframe-jdbc"))
implementation(libs.ksp.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ class DataFrameSymbolProcessorTest {
}
}

private val petstoreYaml = File("../../dataframe-openapi/src/test/resources/petstore.yaml")
private val petstoreYaml = File("../../dataframe-openapi-generator/src/test/resources/petstore.yaml")

@Test
fun `openApi yaml test`(): Unit =
Expand Down Expand Up @@ -1238,7 +1238,7 @@ class DataFrameSymbolProcessorTest {
}
}

private val apiGuruMetricsJson = File("../../dataframe-openapi/src/test/resources/apiGuruMetrics.json")
private val apiGuruMetricsJson = File("../../dataframe-openapi-generator/src/test/resources/apiGuruMetrics.json")

@Test
fun `non openApi json test 2`(): Unit =
Expand Down Expand Up @@ -1275,7 +1275,7 @@ class DataFrameSymbolProcessorTest {
}
}

private val petstoreJson = File("../../dataframe-openapi/src/test/resources/petstore.json")
private val petstoreJson = File("../../dataframe-openapi-generator/src/test/resources/petstore.json")

@Test
fun `openApi json test`(): Unit =
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ plugins {
}
include("dataframe-excel")
include("core")
include("dataframe-openapi-generator")

0 comments on commit 40c0113

Please sign in to comment.