mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2024-11-23 05:49:59 +00:00
Set default value for requireAuthentication (#155)
* Set the default value of requireAuthentication based on the security requirements * Improve requireAuthentication code readability
This commit is contained in:
parent
2c4cdf5630
commit
280ce75590
@ -2,6 +2,7 @@ root = true
|
||||
|
||||
[*]
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
|
||||
[{*.kts, *.kt}]
|
||||
charset = utf-8
|
||||
|
@ -54,7 +54,7 @@ class OperationUrlBuilder(
|
||||
.forEach { parameter -> addParameter(buildParameter(parameter)) }
|
||||
|
||||
ParameterSpec.builder("includeCredentials", Boolean::class).apply {
|
||||
defaultValue("%L", "false")
|
||||
defaultValue("%L", data.requireAuthentication)
|
||||
addKdoc("%L", Strings.INCLUDE_CREDENTIALS_DESCRIPTION)
|
||||
}.build().let(::addParameter)
|
||||
|
||||
|
@ -8,6 +8,7 @@ import net.pearx.kasechange.toCamelCase
|
||||
import org.jellyfin.openapi.builder.Builder
|
||||
import org.jellyfin.openapi.builder.api.ApiNameBuilder
|
||||
import org.jellyfin.openapi.constants.MimeType
|
||||
import org.jellyfin.openapi.constants.Security
|
||||
import org.jellyfin.openapi.constants.Strings
|
||||
import org.jellyfin.openapi.hooks.ApiTypePath
|
||||
import org.jellyfin.openapi.model.ApiService
|
||||
@ -73,12 +74,19 @@ class OpenApiApiServicesBuilder(
|
||||
if (returnType == Unit::class.asTypeName() && "200" in operation.responses)
|
||||
println("Missing return-type for operation $operationName (status-codes: ${operation.responses.keys})")
|
||||
|
||||
val requireAuthentication = operation.security
|
||||
?.firstOrNull { requirement -> requirement.containsKey(Security.SECURITY_SCHEME) }
|
||||
?.get(Security.SECURITY_SCHEME)
|
||||
?.any(Security.AUTHENTICATION_POLICIES::contains)
|
||||
?: false
|
||||
|
||||
operations[serviceName]!! += ApiServiceOperation(
|
||||
name = operationName,
|
||||
description = operation.description ?: operation.summary,
|
||||
deprecated = operation.deprecated == true,
|
||||
pathTemplate = path,
|
||||
method = method,
|
||||
requireAuthentication = requireAuthentication,
|
||||
returnType = returnType,
|
||||
pathParameters = pathParameters,
|
||||
queryParameters = queryParameters,
|
||||
|
@ -0,0 +1,6 @@
|
||||
package org.jellyfin.openapi.constants
|
||||
|
||||
object Security {
|
||||
const val SECURITY_SCHEME = "CustomAuthentication"
|
||||
val AUTHENTICATION_POLICIES = arrayOf("DefaultAuthorization", "RequiresElevation")
|
||||
}
|
@ -8,6 +8,7 @@ data class ApiServiceOperation(
|
||||
val deprecated: Boolean,
|
||||
val pathTemplate: String,
|
||||
val method: HttpMethod,
|
||||
val requireAuthentication: Boolean,
|
||||
val returnType: TypeName,
|
||||
val pathParameters: Collection<ApiServiceOperationParameter> = emptyList(),
|
||||
val queryParameters: Collection<ApiServiceOperationParameter> = emptyList(),
|
||||
|
Loading…
Reference in New Issue
Block a user