Add LiveTVModelsHook

This commit is contained in:
Niels van Velzen 2024-06-18 15:54:36 +02:00 committed by Niels van Velzen
parent f7a6d5f6b3
commit 52fbcf4efe
2 changed files with 38 additions and 0 deletions

View File

@ -6,12 +6,14 @@ import org.jellyfin.openapi.hooks.api.LargeOperationRequestModelHook
import org.jellyfin.openapi.hooks.api.PlayStateServiceNameHook
import org.jellyfin.openapi.hooks.model.DotNetDescriptionHook
import org.jellyfin.openapi.hooks.model.ImageMapsHook
import org.jellyfin.openapi.hooks.model.LiveTVModelsHook
import org.jellyfin.openapi.hooks.model.SwashbuckleDescriptionHook
import org.koin.dsl.bind
import org.koin.dsl.module
val hooksModule = module {
single { ImageMapsHook() } bind TypeBuilderHook::class
single { LiveTVModelsHook() } bind TypeBuilderHook::class
single { BinaryOperationUrlHook() } bind OperationUrlHook::class
single { ClientLogOperationUrlHook() } bind OperationUrlHook::class

View File

@ -0,0 +1,36 @@
package org.jellyfin.openapi.hooks.model
import com.squareup.kotlinpoet.TypeName
import io.swagger.v3.oas.models.media.Schema
import org.jellyfin.openapi.builder.openapi.OpenApiTypeBuilder
import org.jellyfin.openapi.hooks.ModelTypePath
import org.jellyfin.openapi.hooks.TypeBuilderHook
import org.jellyfin.openapi.hooks.TypePath
import org.jellyfin.openapi.hooks.model.LiveTVModelsHook.Companion.liveTvNullableModels
/**
* A hook that modifies all properties of the models stored in [liveTvNullableModels] to be nullable.
*/
class LiveTVModelsHook : TypeBuilderHook {
companion object {
private val liveTvNullableModels = setOf(
"SeriesTimerInfoDto",
"TimerInfoDto",
)
private val ignoreProperties = setOf(
"imageTags",
)
}
override fun onBuildType(path: TypePath, schema: Schema<*>, typeBuilder: OpenApiTypeBuilder): TypeName? {
return when {
path is ModelTypePath && liveTvNullableModels.contains(path.model) && !ignoreProperties.contains(path.property) ->
typeBuilder
.buildSchema(path, schema)
.copy(nullable = true)
else -> null
}
}
}