mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2024-11-26 23:50:32 +00:00
Add LiveTVModelsHook
This commit is contained in:
parent
f7a6d5f6b3
commit
52fbcf4efe
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user