Skip to content

Commit 93aba7b

Browse files
authored
feat: improve validation for integer's named values (#274)
Part of #253.
1 parent 7084de0 commit 93aba7b

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/jvmMain/kotlin/it/krzeminski/githubactionstyping/parsing/TypesManifestParsing.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ data class ApiItem(
2121
val allowedValues: List<String>? = null,
2222
val separator: String? = null,
2323
@SerialName("named-values")
24-
val namedValues: Map<String, Int>? = null,
24+
val namedValues: Map<String, String>? = null,
2525
@SerialName("list-item")
2626
val listItem: ApiItem? = null,
2727
)

src/jvmMain/kotlin/it/krzeminski/githubactionstyping/validation/types/Integer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fun ApiItem.validateInteger(): ItemValidationResult {
1313
if (this.namedValues?.keys?.any { it.isBlank() } == true) {
1414
return ItemValidationResult.Invalid("Named value names must not be empty.")
1515
}
16+
if (this.namedValues?.values?.any { it.toIntOrNull() == null } == true) {
17+
return ItemValidationResult.Invalid("Named values must be integer.")
18+
}
1619
if (this.name != null && this.name.isBlank()) {
1720
return ItemValidationResult.Invalid("Name must not be empty.")
1821
}

src/jvmTest/kotlin/it/krzeminski/githubactionstyping/validation/ManifestValidationTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class ManifestValidationTest : FunSpec({
1717
"integer-input" to ApiItem(type = "integer"),
1818
"integer-with-named-values-input" to ApiItem(
1919
type = "integer",
20-
namedValues = mapOf("foo" to 1, "bar" to 2)
20+
namedValues = mapOf("foo" to "1", "bar" to "2")
2121
),
2222
"integer-with-named-values-and-custom-item-name-input" to ApiItem(
2323
type = "integer",
2424
name = "SomeItemName",
25-
namedValues = mapOf("foo" to 1, "bar" to 2)
25+
namedValues = mapOf("foo" to "1", "bar" to "2")
2626
),
2727
"float-input" to ApiItem(type = "float"),
2828
),
@@ -481,11 +481,11 @@ class ManifestValidationTest : FunSpec({
481481
// given
482482
val manifest = TypesManifest(
483483
inputs = mapOf(
484-
"string-input" to ApiItem(type = "string", namedValues = mapOf("foo" to 1)),
485-
"boolean-input" to ApiItem(type = "boolean", namedValues = mapOf("foo" to 1)),
486-
"float-input" to ApiItem(type = "float", namedValues = mapOf("foo" to 1)),
487-
"list-input" to ApiItem(type = "list", separator = ",", listItem = ApiItem(type = "string"), namedValues = mapOf("foo" to 1)),
488-
"enum-input" to ApiItem(type = "enum", allowedValues = listOf("foo", "bar"), namedValues = mapOf("foo" to 1)),
484+
"string-input" to ApiItem(type = "string", namedValues = mapOf("foo" to "1")),
485+
"boolean-input" to ApiItem(type = "boolean", namedValues = mapOf("foo" to "1")),
486+
"float-input" to ApiItem(type = "float", namedValues = mapOf("foo" to "1")),
487+
"list-input" to ApiItem(type = "list", separator = ",", listItem = ApiItem(type = "string"), namedValues = mapOf("foo" to "1")),
488+
"enum-input" to ApiItem(type = "enum", allowedValues = listOf("foo", "bar"), namedValues = mapOf("foo" to "1")),
489489
),
490490
)
491491

0 commit comments

Comments
 (0)