mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2024-11-23 13:59:42 +00:00
Use kotlin-logging in openapi-generator
This commit is contained in:
parent
6e3508e808
commit
a6f3d1f6ce
@ -28,6 +28,10 @@ dependencies {
|
||||
// Dependency Injection
|
||||
implementation(libs.koin)
|
||||
|
||||
// Logging
|
||||
implementation(libs.kotlin.logging)
|
||||
runtimeOnly(libs.slf4j.simple)
|
||||
|
||||
// Testing
|
||||
testImplementation(libs.kotlin.test.junit)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.swagger.v3.oas.models.info.Info
|
||||
import io.swagger.v3.oas.models.media.Schema
|
||||
import io.swagger.v3.parser.OpenAPIV3Parser
|
||||
import io.swagger.v3.parser.core.models.SwaggerParseResult
|
||||
import mu.KotlinLogging
|
||||
import org.jellyfin.openapi.builder.api.ApiBuilder
|
||||
import org.jellyfin.openapi.builder.extra.FileSpecBuilder
|
||||
import org.jellyfin.openapi.builder.openapi.OpenApiApiServicesBuilder
|
||||
@ -14,6 +15,8 @@ import org.jellyfin.openapi.builder.openapi.OpenApiModelBuilder
|
||||
import org.jellyfin.openapi.model.GeneratorResult
|
||||
import java.io.File
|
||||
|
||||
private val logger = KotlinLogging.logger { }
|
||||
|
||||
class Generator(
|
||||
private val fileSpecBuilder: FileSpecBuilder,
|
||||
private val openApiModelBuilder: OpenApiModelBuilder,
|
||||
@ -23,7 +26,7 @@ class Generator(
|
||||
) {
|
||||
private fun parse(openApiJson: String): SwaggerParseResult {
|
||||
val parseResult = OpenAPIV3Parser().readContents(openApiJson)
|
||||
parseResult.messages.forEach { println(it) }
|
||||
parseResult.messages.forEach { message -> logger.warn { message } }
|
||||
return parseResult
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.jellyfin.openapi
|
||||
|
||||
import com.squareup.kotlinpoet.FileSpec
|
||||
import mu.KotlinLogging
|
||||
import org.jellyfin.openapi.model.GeneratorResult
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
@ -12,6 +13,8 @@ import kotlin.io.path.readText
|
||||
import kotlin.io.path.relativeTo
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
private val logger = KotlinLogging.logger { }
|
||||
|
||||
class Verification(
|
||||
apiOutputDir: File,
|
||||
modelsOutputDir: File,
|
||||
@ -59,10 +62,18 @@ class Verification(
|
||||
.intersect(new.keys)
|
||||
.filter { key -> !current[key].contentEquals(new[key]) }
|
||||
|
||||
removedKeys.forEach { key -> println("$key: removed from sources.") }
|
||||
newKeys.forEach { key -> println("$key: added to sources.") }
|
||||
removedKeys.forEach { key ->
|
||||
logger.error { "$key: removed from sources." }
|
||||
}
|
||||
|
||||
newKeys.forEach { key ->
|
||||
logger.error { "$key: added to sources." }
|
||||
}
|
||||
|
||||
modifiedKeys.forEach { key ->
|
||||
println("$key: modified (${current[key].toMd5String()} -> ${new[key].toMd5String()}).")
|
||||
logger.error {
|
||||
"$key: modified (${current[key].toMd5String()} -> ${new[key].toMd5String()})."
|
||||
}
|
||||
}
|
||||
|
||||
return removedKeys.isEmpty() && newKeys.isEmpty() && modifiedKeys.isEmpty()
|
||||
|
@ -7,6 +7,7 @@ import io.swagger.v3.oas.models.Paths
|
||||
import io.swagger.v3.oas.models.media.IntegerSchema
|
||||
import io.swagger.v3.oas.models.media.Schema
|
||||
import io.swagger.v3.oas.models.parameters.Parameter
|
||||
import mu.KotlinLogging
|
||||
import net.pearx.kasechange.CaseFormat
|
||||
import net.pearx.kasechange.toCamelCase
|
||||
import org.jellyfin.openapi.OpenApiGeneratorError
|
||||
@ -21,6 +22,8 @@ import org.jellyfin.openapi.hooks.DefaultValueHook
|
||||
import org.jellyfin.openapi.hooks.ServiceNameHook
|
||||
import org.jellyfin.openapi.model.*
|
||||
|
||||
private val logger = KotlinLogging.logger { }
|
||||
|
||||
class OpenApiApiServicesBuilder(
|
||||
private val apiNameBuilder: ApiNameBuilder,
|
||||
private val openApiTypeBuilder: OpenApiTypeBuilder,
|
||||
@ -95,10 +98,10 @@ class OpenApiApiServicesBuilder(
|
||||
|
||||
if (parameterSpec.`in` == "path") {
|
||||
if (type.isNullable)
|
||||
println("Path parameter $parameterName in $operationName is marked as nullable")
|
||||
logger.warn { "Path parameter $parameterName in $operationName is marked as nullable" }
|
||||
|
||||
if (!path.contains("{${parameterName}}", ignoreCase = true))
|
||||
println("Path parameter $parameterName in $operationName is missing in path $path")
|
||||
logger.warn { "Path parameter $parameterName in $operationName is missing in path $path" }
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +110,7 @@ class OpenApiApiServicesBuilder(
|
||||
operation.responses["200"]
|
||||
)
|
||||
if (returnType == Types.NONE && "200" in operation.responses)
|
||||
println("Missing return-type for operation $operationName (status-codes: ${operation.responses.keys})")
|
||||
logger.warn { "Missing return-type for operation $operationName (status-codes: ${operation.responses.keys})" }
|
||||
|
||||
val requireAuthentication = operation.security
|
||||
?.firstOrNull { requirement -> requirement.containsKey(Security.SECURITY_SCHEME) }
|
||||
|
Loading…
Reference in New Issue
Block a user