Skip to content

Commit

Permalink
GH-180 Bump OpenApi spec to 3.1.0, include only non-null properties i…
Browse files Browse the repository at this point in the history
…n scheme & use standalone ObjectMapper instance (Fix #180)
  • Loading branch information
dzikoysk committed Apr 26, 2023
1 parent 45bf946 commit 553ef56
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ subprojects {

testImplementation("org.assertj:assertj-core:3.24.2")
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:2.36.1")
testImplementation("com.konghq:unirest-java:3.14.1")
testImplementation("com.konghq:unirest-java:3.14.2")

testImplementation("ch.qos.logback:logback-classic:1.4.5")
testImplementation("ch.qos.logback:logback-classic:1.4.6")
}

tasks.withType<Test> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public static void main(String[] args) {
openApiLicense.setIdentifier("Apache-2.0");

openApiInfo.setTitle("Awesome App");
openApiInfo.setSummary("App summary");
openApiInfo.setDescription("App description goes right here");
openApiInfo.setTermsOfService("https://example.com/tos");
openApiInfo.setContact(openApiContact);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.javalin.openapi.plugin

import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import io.javalin.Javalin
import io.javalin.json.JavalinJackson
import io.javalin.json.jsonMapper
import io.javalin.openapi.OpenApiLoader
import io.javalin.plugin.Plugin
import kotlin.DeprecationLevel.WARNING
Expand All @@ -28,17 +27,17 @@ open class OpenApiPlugin @JvmOverloads constructor(private val configuration: Op

private fun createDocumentation(app: Javalin): Lazy<Map<String, String>> =
lazy {
val jsonMapper = when (val jsonMapper = app.jsonMapper()) {
is JavalinJackson -> jsonMapper.mapper
else -> JavalinJackson.defaultMapper()
// skip nulls from cfg
val jsonMapper = lazy {
ObjectMapper().setSerializationInclusion(Include.NON_NULL)
}

OpenApiLoader()
.loadOpenApiSchemes()
.mapValues { (version, rawDocs) ->
configuration.definitionConfiguration
?.let { DefinitionConfiguration().also { definition -> it.accept(version, definition) } }
?.applyConfigurationTo(jsonMapper, version, rawDocs)
?.applyConfigurationTo(jsonMapper.value, version, rawDocs)
?: rawDocs
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal class OpenApiGenerator {
*/
private fun generateSchema(openApiAnnotations: Collection<Pair<Element, OpenApi>>): String {
val openApi = JsonObject()
openApi.addProperty("openapi", "3.0.3")
openApi.addProperty("openapi", "3.1.0")

// fill info
val info = JsonObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class OpenApiAnnotationTest : OpenApiAnnotationProcessorSpecification()
fun should_generate_info() = withOpenApi("should_generate_info") {
assertThatJson(it)
.isObject
.containsEntry("openapi", "3.0.3")
.containsEntry("openapi", "3.1.0")
.containsEntry("info", json("""{ "title":"", "version": "" }"""))
}

Expand Down
4 changes: 3 additions & 1 deletion openapi-specification/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
description = "Javalin OpenAPI Specification | Compile-time OpenAPI integration for Javalin 5.x"

dependencies {
api("com.fasterxml.jackson.core:jackson-databind:2.14.2")
val jacksonVersion = "2.14.2"
api("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
api("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
api("com.google.code.gson:gson:2.10.1")
}

0 comments on commit 553ef56

Please sign in to comment.