Skip to content

Commit

Permalink
Merge branch 'pre-release-5-0-0' into pre-release-5-0-0
Browse files Browse the repository at this point in the history
  • Loading branch information
king-phyte authored Feb 1, 2025
2 parents 214d590 + 55c7382 commit 3bc2add
Show file tree
Hide file tree
Showing 45 changed files with 1,111 additions and 316 deletions.
4 changes: 4 additions & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
}

repositories {
mavenLocal() // todo: remove after releasing schema-kenerator 1.7.0
mavenCentral()
}

Expand All @@ -17,13 +18,16 @@ dependencies {
implementation(project(":ktor-swagger-ui"))
implementation(project(":ktor-redoc"))

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")

val versionKtor: String by project
implementation("io.ktor:ktor-server-netty-jvm:$versionKtor")
implementation("io.ktor:ktor-server-content-negotiation:$versionKtor")
implementation("io.ktor:ktor-serialization-jackson:$versionKtor")
implementation("io.ktor:ktor-server-auth:$versionKtor")
implementation("io.ktor:ktor-server-call-logging:$versionKtor")
implementation("io.ktor:ktor-server-test-host:$versionKtor")
implementation("io.ktor:ktor-server-resources:$versionKtor")

val versionSchemaKenerator: String by project
implementation("io.github.smiley4:schema-kenerator-core:$versionSchemaKenerator")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.github.smiley4.ktoropenapi.examples

import io.github.smiley4.ktoropenapi.OpenApi
import io.github.smiley4.ktoropenapi.config.OpenApiPluginConfig
import io.github.smiley4.ktoropenapi.config.AuthScheme
import io.github.smiley4.ktoropenapi.config.AuthType
import io.github.smiley4.ktoropenapi.config.OpenApiPluginConfig
import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.config.SwaggerUISort
import io.github.smiley4.ktorswaggerui.config.OperationsSort
import io.github.smiley4.ktorswaggerui.config.SwaggerUISyntaxHighlight
import io.github.smiley4.ktorswaggerui.config.TagSort
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.github.smiley4.schemakenerator.reflection.processReflection
import io.github.smiley4.schemakenerator.reflection.analyseTypeUsingReflection
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
import io.github.smiley4.schemakenerator.swagger.data.TitleType
import io.github.smiley4.schemakenerator.swagger.generateSwaggerSchema
Expand Down Expand Up @@ -107,7 +108,7 @@ private fun Application.myModule() {
schema<String>("string")
generator = { type ->
type
.processReflection()
.analyseTypeUsingReflection()
.generateSwaggerSchema()
.withTitle(TitleType.SIMPLE)
.compileReferencingRoot()
Expand Down Expand Up @@ -143,53 +144,70 @@ private fun Application.myModule() {
}
route("swagger") {
swaggerUI("/api.json") {
displayOperationId = true
showTagFilterInput = true
sort = SwaggerUISort.HTTP_METHOD
deepLinking = true
displayOperationId = false
defaultModelsExpandDepth = 1
defaultModelExpandDepth = 1
displayRequestDuration = false
filter = false
maxDisplayedTags = 99
operationsSorter = OperationsSort.HTTP_METHOD
showExtensions = false
showCommonExtensions = false
tagsSorter = TagSort.ALPHANUMERICALLY
syntaxHighlight = SwaggerUISyntaxHighlight.MONOKAI
tryItOutEnabled = true
requestSnippetsEnabled = true
oauth2RedirectUrl = "example.com"
requestInterceptor = "req => { alert(JSON.stringify(req)); return req; }"
responseInterceptor = "res => { alert(JSON.stringify(res)); return res; }"
supportedSubmitMethods = setOf("get", "put", "post", "delete", "options", "head", "patch", "trace")
onlineSpecValidator()
withCredentials = false
persistAuthorization = false
}
route("redoc") {
redoc("/api.json") {
disableSearch = false
minCharacterLengthToInitSearch = 1
expandResponses = listOf("all")
expandSingleSchemaField = true
hideDownloadButton = false
hideHostname = false
hideLoading = false
hideRequestPayloadSample = true
hideOneOfDescription = false
hideSchemaPattern = false
hideSchemaTitles = true
hideSecuritySection = false
hideSingleRequestSampleTab = true
jsonSampleExpandLevel = "1"
maxDisplayedEnumValues = 3
menuToggle = true
nativeScrollbars = true
onlyRequiredInSamples = false
pathInMiddlePanel = true
requiredPropsFirst = true
schemaExpansionLevel = "all"
showObjectSchemaExamples = true
showWebhookVerb = true
simpleOneOfTypeLabel = true
sortEnumValuesAlphabetically = true
sortOperationsAlphabetically = true
sortPropsAlphabetically = true
sortTagsAlphabetically = true
theme = """
{
"sidebar": {
"backgroundColor": "lightblue"
},
"rightPanel": {
"backgroundColor": "darkblue"
}
}
route("redoc") {
redoc("/api.json") {
pageTitle = "Redoc - My Api"
disableSearch = false
minCharacterLengthToInitSearch = 1
expandResponses = listOf("all")
expandSingleSchemaField = true
hideDownloadButton = false
hideHostname = false
hideLoading = false
hideRequestPayloadSample = true
hideOneOfDescription = false
hideSchemaPattern = false
hideSchemaTitles = true
hideSecuritySection = false
hideSingleRequestSampleTab = true
jsonSampleExpandLevel = "1"
maxDisplayedEnumValues = 3
menuToggle = true
nativeScrollbars = true
onlyRequiredInSamples = false
pathInMiddlePanel = true
requiredPropsFirst = true
schemaExpansionLevel = "all"
showObjectSchemaExamples = true
showWebhookVerb = true
simpleOneOfTypeLabel = true
sortEnumValuesAlphabetically = true
sortOperationsAlphabetically = true
sortPropsAlphabetically = true
sortTagsAlphabetically = true
theme = """
{
"sidebar": {
"backgroundColor": "lightblue"
},
"rightPanel": {
"backgroundColor": "darkblue"
}
""".trimIndent()
}
}
""".trimIndent()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.github.smiley4.schemakenerator.serialization.processKotlinxSerialization
import io.github.smiley4.schemakenerator.serialization.analyzeTypeUsingKotlinxSerialization
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
import io.github.smiley4.schemakenerator.swagger.data.TitleType
import io.github.smiley4.schemakenerator.swagger.generateSwaggerSchema
Expand Down Expand Up @@ -35,7 +35,7 @@ private fun Application.myModule() {
// process type using kotlinx-serialization instead of reflection
// requires additional dependency "io.github.smiley4:schema-kenerator-kotlinx-serialization:<VERSION>"
// see https://github.com/SMILEY4/schema-kenerator for more information
.processKotlinxSerialization()
.analyzeTypeUsingKotlinxSerialization()
.generateSwaggerSchema()
.withTitle(TitleType.SIMPLE)
.compileReferencingRoot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.github.smiley4.schemakenerator.serialization.processKotlinxSerialization
import io.github.smiley4.schemakenerator.serialization.analyzeTypeUsingKotlinxSerialization
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
import io.github.smiley4.schemakenerator.swagger.data.TitleType
import io.github.smiley4.schemakenerator.swagger.generateSwaggerSchema
Expand All @@ -33,7 +33,7 @@ private fun Application.myModule() {
// (see https://github.com/SMILEY4/schema-kenerator/wiki for more information)
generator = { type ->
type
.processKotlinxSerialization()
.analyzeTypeUsingKotlinxSerialization()
.generateSwaggerSchema()
.withTitle(TitleType.SIMPLE)
.compileReferencingRoot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,26 @@ fun main() {


/**
* Uses the OpenApi-Example "petstore-simple" to demonstrate ktor with swagger-ui
* Uses the OpenAPI example "petstore simple" to demonstrate ktor with swagger-ui
* https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v2.0/json/petstore-simple.json
*/
private fun Application.myModule() {

data class Pet(
val id: Long,
val name: String,
val tag: String
)

data class NewPet(
val name: String,
val tag: String
)

data class ErrorModel(
val message: String
)

install(OpenApi) {
info {
title = "Swagger Petstore"
Expand Down Expand Up @@ -57,7 +72,9 @@ private fun Application.myModule() {
openApi()
}
route("redoc") {
redoc("/api.json")
redoc("/api.json") {
hideLoading = true
}
}

route("/pets") {
Expand Down Expand Up @@ -241,25 +258,7 @@ private fun Application.myModule() {
}) {
call.respond(HttpStatusCode.NotImplemented, Unit)
}

}
}

}

}

private data class Pet(
val id: Long,
val name: String,
val tag: String
)

private data class NewPet(
val name: String,
val tag: String
)

private data class ErrorModel(
val message: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import io.github.smiley4.ktoropenapi.get
import io.github.smiley4.ktoropenapi.openApi
import io.github.smiley4.ktorredoc.redoc
import io.github.smiley4.ktorswaggerui.swaggerUI
import io.github.smiley4.schemakenerator.core.connectSubTypes
import io.github.smiley4.schemakenerator.core.addMissingSupertypeSubtypeRelations
import io.github.smiley4.schemakenerator.jackson.collectJacksonSubTypes
import io.github.smiley4.schemakenerator.reflection.processReflection
import io.github.smiley4.schemakenerator.reflection.analyseTypeUsingReflection
import io.github.smiley4.schemakenerator.swagger.compileReferencingRoot
import io.github.smiley4.schemakenerator.swagger.data.TitleType
import io.github.smiley4.schemakenerator.swagger.generateSwaggerSchema
Expand Down Expand Up @@ -54,9 +54,9 @@ private fun Application.myModule() {
// customized schema generation pipeline
generator = { type ->
type
.collectJacksonSubTypes(typeProcessing = { types -> types.processReflection() }) // include types from jackson subtype-annotation
.processReflection()
.connectSubTypes() // connect the supertypes with their subtypes
.collectJacksonSubTypes(typeProcessing = { types -> types.analyseTypeUsingReflection() }) // include types from jackson subtype-annotation
.analyseTypeUsingReflection()
.addMissingSupertypeSubtypeRelations()
.generateSwaggerSchema()
.withTitle(TitleType.SIMPLE)
.compileReferencingRoot()
Expand Down
Loading

0 comments on commit 3bc2add

Please sign in to comment.