Skip to content

Commit

Permalink
Add DisplayPreferencesDtoNullabilityFixHook
Browse files Browse the repository at this point in the history
A hook that modifies the type of the "customPrefs" property in "DisplayPreferencesDto" to fix a nullability issue. In the 10.7 API specification the value of the map is incorrectly labelled as not-null. This hook changes the type to the exact type emitted from the 10.8 alpha API specification.
  • Loading branch information
nielsvanvelzen committed Dec 27, 2021
1 parent ea68dfb commit b94b383
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jellyfin.openapi.hooks
import org.jellyfin.openapi.hooks.api.BinaryOperationUrlHook
import org.jellyfin.openapi.hooks.api.PlayStateServiceNameHook
import org.jellyfin.openapi.hooks.model.DefaultUserIdHook
import org.jellyfin.openapi.hooks.model.DisplayPreferencesDtoNullabilityFixHook
import org.jellyfin.openapi.hooks.model.ImageMapsHook
import org.jellyfin.openapi.hooks.model.SyncPlayGroupUpdateHook
import org.koin.dsl.bind
Expand All @@ -11,6 +12,7 @@ import org.koin.dsl.module
val hooksModule = module {
single { ImageMapsHook() } bind TypeBuilderHook::class
single { SyncPlayGroupUpdateHook() } bind TypeBuilderHook::class
single { DisplayPreferencesDtoNullabilityFixHook() } bind TypeBuilderHook::class

single { BinaryOperationUrlHook() } bind OperationUrlHook::class

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jellyfin.openapi.hooks.model

import com.squareup.kotlinpoet.typeNameOf
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

/**
* A hook that modifies the type of the "customPrefs" property in "DisplayPreferencesDto" to fix a nullability issue.
* In the 10.7 API specification the value of the map is incorrectly labelled as not-null.
* This hook changes the type to the exact type emitted from the 10.8 alpha API specification.
*/
@OptIn(ExperimentalStdlibApi::class)
class DisplayPreferencesDtoNullabilityFixHook : TypeBuilderHook {
override fun onBuildType(path: TypePath, schema: Schema<*>, typeBuilder: OpenApiTypeBuilder) = when (path) {
ModelTypePath("DisplayPreferencesDto", "customPrefs") -> typeNameOf<Map<String, String?>>()
else -> null
}
}

0 comments on commit b94b383

Please sign in to comment.