Skip to content

Commit 0897378

Browse files
authored
feat: allow single value in enum type (#264)
Part of #253. There may be cases where someone wants to make the users explicitly say some single value of enum, e.g. like we discussed here: typesafegithub/github-actions-typing-catalog#45 (comment) This is what we already allow in the schema.
1 parent f9d0e25 commit 0897378

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ fun ApiItem.validateEnum(): ItemValidationResult {
1616
if (this.namedValues != null) {
1717
return ItemValidationResult.Invalid("'named-values' are currently supported only for integers.")
1818
}
19-
if (this.allowedValues.size < 2) {
20-
return ItemValidationResult.Invalid("There must be at least two allowed values.")
19+
if (this.allowedValues.isEmpty()) {
20+
return ItemValidationResult.Invalid("There must be at least one allowed value.")
2121
}
2222
return ItemValidationResult.Valid
2323
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,31 @@ class ManifestValidationTest : FunSpec({
311311
// when
312312
val result = manifest.validate(Path("action.yml")).pathToActionValidationResult[Path("action.yml")]
313313

314+
// then
315+
result shouldBe ActionValidationResult(
316+
overallResult = ItemValidationResult.Valid,
317+
inputs = mapOf(
318+
"enum-input" to ItemValidationResult.Valid,
319+
),
320+
)
321+
}
322+
323+
test("enum type with empty list of allowed value") {
324+
// given
325+
val manifest = TypesManifest(
326+
inputs = mapOf(
327+
"enum-input" to ApiItem(type = "enum", allowedValues = emptyList()),
328+
),
329+
)
330+
331+
// when
332+
val result = manifest.validate(Path("action.yml")).pathToActionValidationResult[Path("action.yml")]
333+
314334
// then
315335
result shouldBe ActionValidationResult(
316336
overallResult = ItemValidationResult.Invalid("Some typing is invalid."),
317337
inputs = mapOf(
318-
"enum-input" to ItemValidationResult.Invalid("There must be at least two allowed values."),
338+
"enum-input" to ItemValidationResult.Invalid("There must be at least one allowed value."),
319339
),
320340
)
321341
}

0 commit comments

Comments
 (0)