Skip to content

Commit

Permalink
General dependency update (#181) (#193)
Browse files Browse the repository at this point in the history
* General dependency update (#181)

* Fix expected code to match generated code

* Bumping KotlinPoet to latest and undoing some questionable changes to the code generated by previous version

---------

Co-authored-by: Chris Hatton <[email protected]>
Co-authored-by: Jens Zettelmeyer <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2023
1 parent e589ae6 commit 4405871
Show file tree
Hide file tree
Showing 79 changed files with 1,650 additions and 1,635 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '11'
java-version: '17'

# Runs a single command using the runners shell
- name: Build Project
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '11'
java-version: '17'
- name: Publish to the Maven Central Repository
run: ./gradlew clean -PsigningKey='${{ secrets.GPG_SIGNING_KEY }}' -PsigningPassword='${{ secrets.GPG_SIGNING_PASSWORD }}' publish
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ tasks {
)
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
kotlinOptions.jvmTarget = "17"
dependsOn(generateCode)
}
}
Expand Down
47 changes: 26 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.dokka.gradle.DokkaTask

plugins {
id("org.jetbrains.kotlin.jvm") version "1.6.0" // Apply the Kotlin JVM plugin to add support for Kotlin.
id("com.github.johnrengelman.shadow") version "4.0.1"
id("org.jetbrains.dokka") version "0.10.1"
id("com.palantir.git-version") version "0.12.3"
id("org.jetbrains.kotlin.jvm") version "1.8.20" // Apply the Kotlin JVM plugin to add support for Kotlin.
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.jetbrains.dokka") version "1.8.10"
id("com.palantir.git-version") version "3.0.0"
id("maven-publish")
id("signing")

`java-library` // For API and implementation separation.
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

val executableName = "fabrikt"

Expand All @@ -37,17 +41,17 @@ dependencies {

implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.github.jknack:handlebars:4.1.0")
implementation("com.github.jknack:handlebars:4.3.1")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion")
implementation("com.beust:jcommander:1.82")
implementation("com.reprezen.kaizen:openapi-parser:4.0.4") { exclude(group = "junit") }
implementation("com.reprezen.jsonoverlay:jsonoverlay:4.0.3")
implementation("com.squareup:kotlinpoet:1.3.0") { exclude(module = "kotlin-stdlib-jre7") }
implementation("com.google.flogger:flogger:0.4")
implementation("com.reprezen.jsonoverlay:jsonoverlay:4.0.4")
implementation("com.squareup:kotlinpoet:1.14.2") { exclude(module = "kotlin-stdlib-jre7") }
implementation("com.google.flogger:flogger:0.7.4")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.1.0")
Expand All @@ -57,14 +61,15 @@ dependencies {
// Below dependencies are solely present so code examples in the test resources dir compile
testImplementation("javax.validation:validation-api:2.0.1.Final")
testImplementation("jakarta.validation:jakarta.validation-api:3.0.2")
testImplementation("org.springframework:spring-webmvc:5.1.9.RELEASE")
testImplementation("org.springframework.security:spring-security-web:5.4.0")
testImplementation("io.micronaut:micronaut-core:3.8.4")
testImplementation("io.micronaut:micronaut-http:3.8.4")
testCompileOnly("io.micronaut.security:micronaut-security:3.8.3")
testImplementation("com.squareup.okhttp3:okhttp:4.9.1")
testImplementation("com.pinterest.ktlint:ktlint-core:0.41.0")
testImplementation("com.pinterest:ktlint:0.41.0")
testImplementation("org.springframework:spring-webmvc:6.0.0")
testImplementation("org.springframework.security:spring-security-web:6.0.0")
testImplementation("io.micronaut:micronaut-core:3.8.7")
testImplementation("io.micronaut:micronaut-http:3.8.7")
//testCompileOnly("io.micronaut.security:micronaut-security:3.8.7")
testImplementation("com.squareup.okhttp3:okhttp:4.10.0")
testImplementation("com.pinterest.ktlint:ktlint-core:0.48.2")
testImplementation("com.pinterest.ktlint:ktlint-ruleset-standard:0.48.2")
testImplementation("com.pinterest:ktlint:0.48.2")
testImplementation("org.openapitools:jackson-databind-nullable:0.2.6")
}

Expand All @@ -81,9 +86,8 @@ tasks {
archiveClassifier.set("")
}

val dokka by getting(DokkaTask::class) {
outputFormat = "html"
outputDirectory = "$buildDir/dokka"
val dokka = getByName<DokkaTask>("dokkaHtml") {
outputDirectory.set(file("$buildDir/dokka"))
}

create("sourcesJar", Jar::class) {
Expand All @@ -102,18 +106,19 @@ tasks {
create("printCodeGenUsage", JavaExec::class) {
dependsOn(shadowJar)
classpath = project.files("./build/libs/$executableName-$version.jar")
main = "com.cjbooms.fabrikt.cli.CodeGen"
mainClass.set("com.cjbooms.fabrikt.cli.CodeGen")
args = listOf("--help")
}

withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

withType<Test> {
useJUnitPlatform()
jvmArgs = listOf("--add-opens=java.base/java.lang=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED")
}
}

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-6.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object GeneratorUtils {

private fun Schema.toClassName() = KotlinTypeInfo.from(this).modelKClass.asTypeName()

fun String.toClassName(basePackage: String) = ClassName(packageName = basePackage, simpleName = this)
fun String.toClassName(basePackage: String) = ClassName(packageName = basePackage, this)

fun RequestBody.getPrimaryContentMediaType(): Map.Entry<String, MediaType>? =
this.contentMediaTypes.entries.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ class MicronautControllerGeneratorTest {
fun `ensure controller has correct annotations`() {
setupGithubApiTestEnv()
val controllerAnnotations =
generated.flatMap { it.members.flatMap { (it as TypeSpec).annotationSpecs.map { it.className.toString() } } }
generated.flatMap { it.members.flatMap { (it as TypeSpec).annotations.map { it.typeName.toString() } } }
.distinct()

assertThat(controllerAnnotations).containsOnly(
"io.micronaut.http.annotation.Controller",
"io.micronaut.http.`annotation`.Controller",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ class SpringControllerGeneratorTest {
fun `ensure controller has correct annotations`() {
setupGithubApiTestEnv()
val controllerAnnotations =
generated.flatMap { it.members.flatMap { (it as TypeSpec).annotationSpecs.map { it.className.toString() } } }
generated.flatMap { it.members.flatMap { (it as TypeSpec).annotations.map { it.typeName.toString() } } }
.distinct()

assertThat(controllerAnnotations).containsOnly(
"org.springframework.stereotype.Controller",
"org.springframework.validation.annotation.Validated",
"org.springframework.web.bind.annotation.RequestMapping",
"org.springframework.validation.`annotation`.Validated",
"org.springframework.web.bind.`annotation`.RequestMapping",
)
}

Expand Down
32 changes: 10 additions & 22 deletions src/test/kotlin/com/cjbooms/fabrikt/util/Linter.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
package com.cjbooms.fabrikt.util

import com.pinterest.ktlint.core.KtLint
import com.pinterest.ktlint.core.RuleSetProvider
import java.util.ServiceLoader
import com.pinterest.ktlint.core.Code
import com.pinterest.ktlint.core.KtLintRuleEngine
import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider

object Linter {

private val lintRuleSets = ServiceLoader.load(RuleSetProvider::class.java)
.map { it.get() }.sortedBy {
when (it.id) {
"standard" -> 0
else -> 1
}
}

fun lintString(rawText: String) =
// lint twice, first lint adds whitespace after each line in a multiline field annotation.
internalLintString(internalLintString(rawText))

private fun internalLintString(rawText: String) = KtLint.format(
KtLint.Params(
text = rawText,
ruleSets = lintRuleSets,
cb = { _, _ -> }
)
)
fun lintString(rawText: String): String {
val code = Code.CodeSnippet(rawText)
val result = KtLintRuleEngine(
ruleProviders = StandardRuleSetProvider().getRuleProviders(),
).format(code)
return result
}
}
82 changes: 41 additions & 41 deletions src/test/resources/examples/anyOfOneOfAllOf/models/Models.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package examples.anyOfOneOfAllOf.models

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.`annotation`.JsonAnyGetter
import com.fasterxml.jackson.`annotation`.JsonAnySetter
import com.fasterxml.jackson.`annotation`.JsonIgnore
import com.fasterxml.jackson.`annotation`.JsonProperty
import java.math.BigDecimal
import javax.validation.constraints.NotNull
import kotlin.Any
Expand All @@ -12,121 +12,121 @@ import kotlin.String
import kotlin.collections.Map
import kotlin.collections.MutableMap

data class ComplexParent(
public data class ComplexParent(
@param:JsonProperty("oneOf")
@get:JsonProperty("oneOf")
val oneOf: Any? = null,
public val oneOf: Any? = null,
@param:JsonProperty("first_nested_any_of_prop")
@get:JsonProperty("first_nested_any_of_prop")
val firstNestedAnyOfProp: String? = null,
public val firstNestedAnyOfProp: String? = null,
@param:JsonProperty("second_nested_any_of_prop")
@get:JsonProperty("second_nested_any_of_prop")
val secondNestedAnyOfProp: String? = null,
public val secondNestedAnyOfProp: String? = null,
@param:JsonProperty("required_string")
@get:JsonProperty("required_string")
@get:NotNull
val requiredString: String,
public val requiredString: String,
@param:JsonProperty("required_int")
@get:JsonProperty("required_int")
@get:NotNull
val requiredInt: Int,
public val requiredInt: Int,
@param:JsonProperty("top_level_prop")
@get:JsonProperty("top_level_prop")
@get:NotNull
val topLevelProp: BigDecimal
public val topLevelProp: BigDecimal,
)

data class ComplexSecondOneA(
public data class ComplexSecondOneA(
@param:JsonProperty("more_nested_prop_one")
@get:JsonProperty("more_nested_prop_one")
@get:NotNull
val moreNestedPropOne: String
public val moreNestedPropOne: String,
)

data class ContainsNestedAnyOf(
public data class ContainsNestedAnyOf(
@param:JsonProperty("first_nested_any_of_prop")
@get:JsonProperty("first_nested_any_of_prop")
val firstNestedAnyOfProp: String? = null,
public val firstNestedAnyOfProp: String? = null,
@param:JsonProperty("second_nested_any_of_prop")
@get:JsonProperty("second_nested_any_of_prop")
val secondNestedAnyOfProp: String? = null
public val secondNestedAnyOfProp: String? = null,
)

data class FirstAnyA(
public data class FirstAnyA(
@param:JsonProperty("first_nested_any_of_prop")
@get:JsonProperty("first_nested_any_of_prop")
val firstNestedAnyOfProp: String? = null
public val firstNestedAnyOfProp: String? = null,
)

data class FirstOneA(
public data class FirstOneA(
@param:JsonProperty("first_nested_one_of_prop")
@get:JsonProperty("first_nested_one_of_prop")
val firstNestedOneOfProp: String? = null
public val firstNestedOneOfProp: String? = null,
)

data class FirstOneB(
public data class FirstOneB(
@param:JsonProperty("first_property")
@get:JsonProperty("first_property")
val firstProperty: String? = null
public val firstProperty: String? = null,
)

data class MoreNesting(
public data class MoreNesting(
@param:JsonProperty("more_nested_prop_one")
@get:JsonProperty("more_nested_prop_one")
@get:NotNull
val moreNestedPropOne: String
public val moreNestedPropOne: String,
)

data class OneOfAdditionalProps(
public data class OneOfAdditionalProps(
@param:JsonProperty("second_nested_any_of_prop")
@get:JsonProperty("second_nested_any_of_prop")
val secondNestedAnyOfProp: String? = null,
public val secondNestedAnyOfProp: String? = null,
@get:JsonIgnore
val properties: MutableMap<String, Any> = mutableMapOf()
public val properties: MutableMap<String, Any> = mutableMapOf(),
) {
@JsonAnyGetter
fun get(): Map<String, Any> = properties
public fun `get`(): Map<String, Any> = properties

@JsonAnySetter
fun set(name: String, value: Any) {
public fun `set`(name: String, `value`: Any) {
properties[name] = value
}
}

data class SecondAnyA(
public data class SecondAnyA(
@param:JsonProperty("second_nested_any_of_prop")
@get:JsonProperty("second_nested_any_of_prop")
val secondNestedAnyOfProp: String? = null
public val secondNestedAnyOfProp: String? = null,
)

data class SecondOneB(
public data class SecondOneB(
@param:JsonProperty("second_property")
@get:JsonProperty("second_property")
val secondProperty: String? = null,
public val secondProperty: String? = null,
@param:JsonProperty("third_property")
@get:JsonProperty("third_property")
val thirdProperty: String? = null,
public val thirdProperty: String? = null,
@param:JsonProperty("forth_property")
@get:JsonProperty("forth_property")
val forthProperty: Any? = null
public val forthProperty: Any? = null,
)

data class SimpleOneOfs(
public data class SimpleOneOfs(
@param:JsonProperty("oneof_property")
@get:JsonProperty("oneof_property")
val oneofProperty: Any? = null,
public val oneofProperty: Any? = null,
@param:JsonProperty("primitive_oneof_property")
@get:JsonProperty("primitive_oneof_property")
val primitiveOneofProperty: Any? = null
public val primitiveOneofProperty: Any? = null,
)

data class SimpleTypeWithRequiredProps(
public data class SimpleTypeWithRequiredProps(
@param:JsonProperty("required_string")
@get:JsonProperty("required_string")
@get:NotNull
val requiredString: String,
public val requiredString: String,
@param:JsonProperty("required_int")
@get:JsonProperty("required_int")
@get:NotNull
val requiredInt: Int
public val requiredInt: Int,
)
Loading

0 comments on commit 4405871

Please sign in to comment.