Skip to content

Commit

Permalink
fix(composer): Support the license field to be a primitive string
Browse files Browse the repository at this point in the history
Quoting [1]: "The license of the package. This can be either a string or
an array of strings."

[1]: https://getcomposer.org/doc/04-schema.md#license

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Aug 10, 2024
1 parent 34f3760 commit b579f88
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugins/package-managers/composer/src/main/kotlin/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ package org.ossreviewtoolkit.plugins.packagemanagers.composer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonTransformingSerializer
import kotlinx.serialization.serializer

@Serializable
internal data class Lockfile(
Expand All @@ -39,6 +43,7 @@ internal data class PackageInfo(
val description: String? = null,
val source: Source? = null,
val authors: List<Author> = emptyList(),
@Serializable(LicenseListSerializer::class)
val license: List<String> = emptyList(),
val provide: Map<String, String> = emptyMap(),
val replace: Map<String, String> = emptyMap(),
Expand Down Expand Up @@ -73,6 +78,11 @@ internal data class PackageInfo(

private val JSON = Json { ignoreUnknownKeys = true }

private object LicenseListSerializer : JsonTransformingSerializer<List<String>>(serializer<List<String>>()) {
override fun transformDeserialize(element: JsonElement): JsonElement =
if (element !is JsonArray) JsonArray(listOf(element)) else element
}

internal fun parseLockfile(json: String): Lockfile = JSON.decodeFromString<Lockfile>(json)

internal fun parsePackageInfo(json: String): PackageInfo = JSON.decodeFromString<PackageInfo>(json)

0 comments on commit b579f88

Please sign in to comment.