mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2024-11-26 23:50:32 +00:00
Change behavior for deprecated parameters in API operations to generate a secondary function
The @Deprecated annotation is not supported by Kotlin (although IntelliJ worked fine with it!). The new behavior will generate one function with the deprecated members removed and another one with them added. The latter will have a "Deprecated" suffix in the name and a @Deprecated annotation on the function.
This commit is contained in:
parent
bce42ff6d5
commit
a48c7f8be9
@ -4,6 +4,7 @@ import com.squareup.kotlinpoet.*
|
||||
import org.jellyfin.openapi.builder.Builder
|
||||
import org.jellyfin.openapi.constants.Classes
|
||||
import org.jellyfin.openapi.constants.Packages
|
||||
import org.jellyfin.openapi.constants.Strings
|
||||
import org.jellyfin.openapi.hooks.OperationUrlHook
|
||||
import org.jellyfin.openapi.model.ApiService
|
||||
import org.jellyfin.openapi.model.JellyFile
|
||||
@ -19,8 +20,28 @@ class ApiBuilder(
|
||||
addProperty(PropertySpec.builder("api", apiClientType, KModifier.PRIVATE).initializer("api").build())
|
||||
primaryConstructor(FunSpec.constructorBuilder().addParameter("api", apiClientType).build())
|
||||
|
||||
// Handle deprecated members
|
||||
val operations = data.operations.map { namedOperation ->
|
||||
// Check if any member is deprecated
|
||||
if (namedOperation.queryParameters.any { it.deprecated }) {
|
||||
// Return 2 operations, one with and one without deprecated members
|
||||
listOf(
|
||||
// Remove deprecated parameters from normal function
|
||||
namedOperation.copy(
|
||||
queryParameters = namedOperation.queryParameters.filterNot { it.deprecated }
|
||||
),
|
||||
// Add new "deprecated" function with old parameters
|
||||
namedOperation.copy(
|
||||
name = namedOperation.name + Strings.DEPRECATED_OPERATION_SUFFIX,
|
||||
// Mark the operation as deprecated
|
||||
deprecated = true
|
||||
)
|
||||
)
|
||||
} else listOf(namedOperation)
|
||||
}.flatten()
|
||||
|
||||
// Add operations
|
||||
data.operations.forEach { namedOperation ->
|
||||
operations.forEach { namedOperation ->
|
||||
addFunction(operationBuilder.build(namedOperation))
|
||||
|
||||
if (operationUrlHooks.any { it.shouldOperationBuildUrlFun(data, namedOperation) })
|
||||
|
@ -50,9 +50,6 @@ class OperationBuilder(
|
||||
|
||||
// Add description
|
||||
data.description?.let { addKdoc("%L", it) }
|
||||
|
||||
// Add deprecated annotation
|
||||
if (data.deprecated) addAnnotation(deprecatedAnnotationSpecBuilder.build(Strings.DEPRECATED_MEMBER))
|
||||
}.build()
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.jellyfin.openapi.model.ApiServiceOperationParameter
|
||||
class OperationUrlBuilder(
|
||||
private val deprecatedAnnotationSpecBuilder: DeprecatedAnnotationSpecBuilder
|
||||
) : Builder<ApiServiceOperation, FunSpec> {
|
||||
private fun buildFunctionShell(data: ApiServiceOperation) = FunSpec.builder(data.name + "Url").apply {
|
||||
private fun buildFunctionShell(data: ApiServiceOperation) = FunSpec.builder(data.name + Strings.URL_OPERATION_SUFFIX).apply {
|
||||
// Add description
|
||||
data.description?.let { addKdoc("%L", it) }
|
||||
|
||||
@ -28,9 +28,6 @@ class OperationUrlBuilder(
|
||||
|
||||
// Add description
|
||||
data.description?.let { addKdoc("%L", it) }
|
||||
|
||||
// Add deprecated annotation
|
||||
if (data.deprecated) addAnnotation(deprecatedAnnotationSpecBuilder.build(Strings.DEPRECATED_MEMBER))
|
||||
}.build()
|
||||
|
||||
|
||||
|
@ -31,4 +31,14 @@ object Strings {
|
||||
* The description used for the "includeCredentials" parameter in API URL functions
|
||||
*/
|
||||
const val INCLUDE_CREDENTIALS_DESCRIPTION = "Add the access token to the url to make an authenticated request."
|
||||
|
||||
/**
|
||||
* The suffix added to the name of a deprecated operation.
|
||||
*/
|
||||
const val DEPRECATED_OPERATION_SUFFIX = "Deprecated"
|
||||
|
||||
/**
|
||||
* The suffix added to the name of a URL operation. Added after [URL_OPERATION_SUFFIX].
|
||||
*/
|
||||
const val URL_OPERATION_SUFFIX = "Url"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user