Add TranscodingInfoTranscodeReasonsHook to fix issue with OpenAPI spec

This commit is contained in:
Niels van Velzen 2022-10-08 11:37:14 +02:00 committed by Max Rumpf
parent 6f96e5b7d3
commit 68ad896e42
2 changed files with 26 additions and 0 deletions

View File

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

View File

@ -0,0 +1,24 @@
package org.jellyfin.openapi.hooks.model
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.plusParameter
import io.swagger.v3.oas.models.media.Schema
import org.jellyfin.openapi.builder.openapi.OpenApiTypeBuilder
import org.jellyfin.openapi.constants.Types
import org.jellyfin.openapi.hooks.ModelTypePath
import org.jellyfin.openapi.hooks.TypeBuilderHook
import org.jellyfin.openapi.hooks.TypePath
/**
* A hook that modifies the type of the "transcodeReasons" property in "TranscodingInfo" to fix an issue with the
* OpenAPI specification. It replaces the "String" type with "Collection<String>". When the bug is fixed it should
* use "Collection<TranscodeReason>".
*
* Reference: https://github.com/jellyfin/jellyfin-sdk-kotlin/issues/510
*/
class TranscodingInfoTranscodeReasonsHook : TypeBuilderHook {
override fun onBuildType(path: TypePath, schema: Schema<*>, typeBuilder: OpenApiTypeBuilder) = when (path) {
ModelTypePath("TranscodingInfo", "transcodeReasons") ->
Types.COLLECTION.plusParameter(Types.STRING)
else -> null
}
}