Skip to content

Commit 365bd57

Browse files
committed
Add support for named values for integers
1 parent c83520d commit 365bd57

File tree

8 files changed

+59
-0
lines changed

8 files changed

+59
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ inputs:
110110
...
111111
```
112112

113+
In case of "magic values" meaning something else that the user would expect, you can specify them like so:
114+
115+
```yaml
116+
...
117+
inputs:
118+
fetch-depth:
119+
type: integer
120+
namedValues:
121+
infinite: 0
122+
...
123+
```
124+
113125
### Float
114126

115127
A number with a fractional component.

src/main/kotlin/it/krzeminski/githubactionstyping/parsing/ManifestParsing.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ data class ApiItem(
1616
val type: String? = null,
1717
val allowedValues: List<String>? = null,
1818
val separator: String? = null,
19+
val namedValues: Map<String, Int>? = null,
1920
val listItem: ApiItem? = null,
2021
)
2122

src/main/kotlin/it/krzeminski/githubactionstyping/validation/types/Boolean.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fun ApiItem.validateBoolean(): ItemValidationResult {
1313
if (this.listItem != null) {
1414
return ItemValidationResult.Invalid("'listItem' is not allowed for this type.")
1515
}
16+
if (this.namedValues != null) {
17+
return ItemValidationResult.Invalid("'namedValues' are currently supported only for integers.")
18+
}
1619

1720
return ItemValidationResult.Valid
1821
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fun ApiItem.validateEnum(): ItemValidationResult {
1313
if (this.listItem != null) {
1414
return ItemValidationResult.Invalid("'listItem' is not allowed for this type.")
1515
}
16+
if (this.namedValues != null) {
17+
return ItemValidationResult.Invalid("'namedValues' are currently supported only for integers.")
18+
}
1619
if (this.allowedValues.size < 2) {
1720
return ItemValidationResult.Invalid("There must be at least two allowed values.")
1821
}

src/main/kotlin/it/krzeminski/githubactionstyping/validation/types/Float.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fun ApiItem.validateFloat(): ItemValidationResult {
1313
if (this.listItem != null) {
1414
return ItemValidationResult.Invalid("'listItem' is not allowed for this type.")
1515
}
16+
if (this.namedValues != null) {
17+
return ItemValidationResult.Invalid("'namedValues' are currently supported only for integers.")
18+
}
1619

1720
return ItemValidationResult.Valid
1821
}

src/main/kotlin/it/krzeminski/githubactionstyping/validation/types/List.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ fun ApiItem.validateList(): ItemValidationResult {
1414
if (this.allowedValues != null) {
1515
return ItemValidationResult.Invalid("'allowedValues' is not allowed for this type.")
1616
}
17+
if (this.namedValues != null) {
18+
return ItemValidationResult.Invalid("'namedValues' are currently supported only for integers.")
19+
}
1720
return when (this.listItem.type) {
1821
"string" -> this.listItem.validateString()
1922
"boolean" -> this.listItem.validateBoolean()

src/main/kotlin/it/krzeminski/githubactionstyping/validation/types/String.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ fun ApiItem.validateString(): ItemValidationResult {
1313
if (this.listItem != null) {
1414
return ItemValidationResult.Invalid("'listItem' is not allowed for this type.")
1515
}
16+
if (this.namedValues != null) {
17+
return ItemValidationResult.Invalid("'namedValues' are currently supported only for integers.")
18+
}
1619

1720
return ItemValidationResult.Valid
1821
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ManifestValidationTest : FunSpec({
1515
"string-input" to ApiItem(type = "string"),
1616
"boolean-input" to ApiItem(type = "boolean"),
1717
"integer-input" to ApiItem(type = "integer"),
18+
"integer-with-named-values-input" to ApiItem(type = "integer", namedValues = mapOf("foo" to 1, "bar" to 2)),
1819
"float-input" to ApiItem(type = "float"),
1920
),
2021
)
@@ -29,6 +30,7 @@ class ManifestValidationTest : FunSpec({
2930
"string-input" to ItemValidationResult.Valid,
3031
"boolean-input" to ItemValidationResult.Valid,
3132
"integer-input" to ItemValidationResult.Valid,
33+
"integer-with-named-values-input" to ItemValidationResult.Valid,
3234
"float-input" to ItemValidationResult.Valid,
3335
),
3436
)
@@ -497,5 +499,34 @@ class ManifestValidationTest : FunSpec({
497499
),
498500
)
499501
}
502+
503+
test("non-integer types with named values") {
504+
// given
505+
val manifest = Manifest(
506+
typingSpec = expectedTypingSpec,
507+
inputs = mapOf(
508+
"string-input" to ApiItem(type = "string", namedValues = mapOf("foo" to 1)),
509+
"boolean-input" to ApiItem(type = "boolean", namedValues = mapOf("foo" to 1)),
510+
"float-input" to ApiItem(type = "float", namedValues = mapOf("foo" to 1)),
511+
"list-input" to ApiItem(type = "list", separator = ",", listItem = ApiItem(type = "string"), namedValues = mapOf("foo" to 1)),
512+
"enum-input" to ApiItem(type = "enum", allowedValues = listOf("foo", "bar"), namedValues = mapOf("foo" to 1)),
513+
),
514+
)
515+
516+
// when
517+
val result = manifest.validate()
518+
519+
// then
520+
result shouldBe ActionValidationResult(
521+
overallResult = ItemValidationResult.Invalid("Some typing is invalid."),
522+
inputs = mapOf(
523+
"string-input" to ItemValidationResult.Invalid("'namedValues' are currently supported only for integers."),
524+
"boolean-input" to ItemValidationResult.Invalid("'namedValues' are currently supported only for integers."),
525+
"float-input" to ItemValidationResult.Invalid("'namedValues' are currently supported only for integers."),
526+
"list-input" to ItemValidationResult.Invalid("'namedValues' are currently supported only for integers."),
527+
"enum-input" to ItemValidationResult.Invalid("'namedValues' are currently supported only for integers."),
528+
),
529+
)
530+
}
500531
}
501532
})

0 commit comments

Comments
 (0)