Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
SMILEY4 committed Dec 9, 2022
2 parents b567e2e + d6d0a6c commit be30488
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.7.20"
kotlin("jvm") version "1.7.21"
`maven-publish`
}

group = "io.github.smiley4"
version = "0.8.0"
version = "0.9.0"

repositories {
mavenCentral()
}

dependencies {

val ktorVersion = "2.1.3"
val ktorVersion = "2.2.1"
implementation("io.ktor:ktor-server-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-webjars:$ktorVersion")
implementation("io.ktor:ktor-server-auth:$ktorVersion")
Expand Down Expand Up @@ -48,7 +48,7 @@ dependencies {
testImplementation("io.kotest:kotest-runner-junit5:$versionKotest")
testImplementation("io.kotest:kotest-assertions-core:$versionKotest")

val versionKotlinTest = "1.7.20"
val versionKotlinTest = "1.7.21"
testImplementation("org.jetbrains.kotlin:kotlin-test:$versionKotlinTest")

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package io.github.smiley4.ktorswaggerui

import com.github.victools.jsonschema.generator.Option
import com.github.victools.jsonschema.generator.OptionPreset
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder
import com.github.victools.jsonschema.generator.SchemaVersion
import com.github.victools.jsonschema.module.jackson.JacksonModule
import io.github.smiley4.ktorswaggerui.dsl.CustomSchemas
import io.github.smiley4.ktorswaggerui.dsl.OpenApiDslMarker
import io.github.smiley4.ktorswaggerui.dsl.OpenApiInfo
Expand Down Expand Up @@ -142,4 +147,14 @@ class SwaggerUIPluginConfig {

fun getCustomSchemas() = customSchemas

/**
* Customize or replace the configuration-builder for the json-schema-generator (see https://victools.github.io/jsonschema-generator/#generator-options for more information)
*/
var schemaGeneratorConfigBuilder: SchemaGeneratorConfigBuilder = SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON)
.with(JacksonModule())
.without(Option.DEFINITIONS_FOR_ALL_OBJECTS)
.with(Option.INLINE_ALL_SCHEMAS)
.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.with(Option.ALLOF_CLEANUP_AT_THE_END)

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ package io.github.smiley4.ktorswaggerui.specbuilder

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import com.github.victools.jsonschema.generator.Option
import com.github.victools.jsonschema.generator.OptionPreset
import com.github.victools.jsonschema.generator.SchemaGenerator
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder
import com.github.victools.jsonschema.generator.SchemaVersion
import com.github.victools.jsonschema.module.jackson.JacksonModule
import io.github.smiley4.ktorswaggerui.SwaggerUIPluginConfig
import io.swagger.v3.oas.models.media.Schema
import java.lang.reflect.Type
Expand Down Expand Up @@ -69,18 +64,12 @@ class OApiJsonSchemaBuilder {
return ObjectMapper().readTree(jsonSchema) as ObjectNode
}
}
return generateJsonSchema(type)
return generateJsonSchema(type, config)
}

private fun generateJsonSchema(type: Type): ObjectNode {
val config = SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON)
.with(JacksonModule())
.without(Option.DEFINITIONS_FOR_ALL_OBJECTS)
.with(Option.INLINE_ALL_SCHEMAS)
.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.with(Option.ALLOF_CLEANUP_AT_THE_END)
.build()
return SchemaGenerator(config).generateSchema(type)
private fun generateJsonSchema(type: Type, config: SwaggerUIPluginConfig): ObjectNode {
val generatorConfig = config.schemaGeneratorConfigBuilder.build()
return SchemaGenerator(generatorConfig).generateSchema(type)
}

}

0 comments on commit be30488

Please sign in to comment.