Skip to content

Commit a389647

Browse files
committed
Add support for lists
1 parent ca0918a commit a389647

File tree

10 files changed

+162
-0
lines changed

10 files changed

+162
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ inputs:
124124
...
125125
```
126126

127+
### List
128+
129+
A sequence of values.
130+
131+
Because string is used as a data type for passing inputs to actions, a separator string has to be
132+
specified as well. This is usually a new line or a comma.
133+
134+
Example:
135+
136+
```yaml
137+
...
138+
inputs:
139+
input-files:
140+
type: list
141+
separator: ','
142+
...
143+
```
144+
127145
### Enum
128146

129147
Multiple possible values.

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ data class Manifest(
1515
data class ApiItem(
1616
val type: String? = null,
1717
val allowedValues: List<String>? = null,
18+
val separator: String? = null,
1819
)
1920

2021
private val myYaml = Yaml(

src/main/kotlin/it/krzeminski/githubactionstyping/validation/ManifestValidation.kt

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import it.krzeminski.githubactionstyping.validation.types.validateBoolean
66
import it.krzeminski.githubactionstyping.validation.types.validateEnum
77
import it.krzeminski.githubactionstyping.validation.types.validateFloat
88
import it.krzeminski.githubactionstyping.validation.types.validateInteger
9+
import it.krzeminski.githubactionstyping.validation.types.validateList
910
import it.krzeminski.githubactionstyping.validation.types.validateString
1011

1112
const val expectedTypingSpec = "krzema12/[email protected]"
@@ -41,6 +42,7 @@ private fun ApiItem.validate(): ItemValidationResult {
4142
"boolean" -> this.validateBoolean()
4243
"integer" -> this.validateInteger()
4344
"float" -> this.validateFloat()
45+
"list" -> this.validateList()
4446
"enum" -> this.validateEnum()
4547
else -> ItemValidationResult.Invalid("Unknown type: '${this.type}'.")
4648
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fun ApiItem.validateBoolean(): ItemValidationResult {
77
if (this.allowedValues != null) {
88
return ItemValidationResult.Invalid("'allowedValues' is not allowed for this type.")
99
}
10+
if (this.separator != null) {
11+
return ItemValidationResult.Invalid("'separator' is not allowed for this type.")
12+
}
1013

1114
return ItemValidationResult.Valid
1215
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fun ApiItem.validateEnum(): ItemValidationResult {
77
if (this.allowedValues == null) {
88
return ItemValidationResult.Invalid("Allowed values must be specified.")
99
}
10+
if (this.separator != null) {
11+
return ItemValidationResult.Invalid("'separator' is not allowed for this type.")
12+
}
1013
if (this.allowedValues.size < 2) {
1114
return ItemValidationResult.Invalid("There must be at least two allowed values.")
1215
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fun ApiItem.validateFloat(): ItemValidationResult {
77
if (this.allowedValues != null) {
88
return ItemValidationResult.Invalid("'allowedValues' is not allowed for this type.")
99
}
10+
if (this.separator != null) {
11+
return ItemValidationResult.Invalid("'separator' is not allowed for this type.")
12+
}
1013

1114
return ItemValidationResult.Valid
1215
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fun ApiItem.validateInteger(): ItemValidationResult {
77
if (this.allowedValues != null) {
88
return ItemValidationResult.Invalid("'allowedValues' is not allowed for this type.")
99
}
10+
if (this.separator != null) {
11+
return ItemValidationResult.Invalid("'separator' is not allowed for this type.")
12+
}
1013

1114
return ItemValidationResult.Valid
1215
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package it.krzeminski.githubactionstyping.validation.types
2+
3+
import it.krzeminski.githubactionstyping.parsing.ApiItem
4+
import it.krzeminski.githubactionstyping.validation.ItemValidationResult
5+
6+
fun ApiItem.validateList(): ItemValidationResult {
7+
if (this.separator == null) {
8+
return ItemValidationResult.Invalid("Separator must be specified.")
9+
}
10+
if (this.allowedValues != null) {
11+
return ItemValidationResult.Invalid("'allowedValues' is not allowed for this type.")
12+
}
13+
14+
return ItemValidationResult.Valid
15+
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fun ApiItem.validateString(): ItemValidationResult {
77
if (this.allowedValues != null) {
88
return ItemValidationResult.Invalid("'allowedValues' is not allowed for this type.")
99
}
10+
if (this.separator != null) {
11+
return ItemValidationResult.Invalid("'separator' is not allowed for this type.")
12+
}
1013

1114
return ItemValidationResult.Valid
1215
}

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

+111
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ class ManifestValidationTest : FunSpec({
5454
),
5555
)
5656
}
57+
58+
test("list type") {
59+
// given
60+
val manifest = Manifest(
61+
typingSpec = expectedTypingSpec,
62+
inputs = mapOf(
63+
"list-input" to ApiItem(type = "list", separator = "\n"),
64+
),
65+
)
66+
67+
// when
68+
val result = manifest.validate()
69+
70+
// then
71+
result shouldBe ActionValidationResult(
72+
overallResult = ItemValidationResult.Valid,
73+
inputs = mapOf(
74+
"list-input" to ItemValidationResult.Valid,
75+
),
76+
)
77+
}
5778
}
5879

5980
context("failure cases") {
@@ -181,6 +202,54 @@ class ManifestValidationTest : FunSpec({
181202
)
182203
}
183204

205+
test("primitive types with 'separator' attribute") {
206+
// given
207+
val manifest = Manifest(
208+
typingSpec = expectedTypingSpec,
209+
inputs = mapOf(
210+
"string-input" to ApiItem(type = "string", separator = ","),
211+
"boolean-input" to ApiItem(type = "boolean", separator = ","),
212+
"integer-input" to ApiItem(type = "integer", separator = ","),
213+
"float-input" to ApiItem(type = "float", separator = ","),
214+
),
215+
)
216+
217+
// when
218+
val result = manifest.validate()
219+
220+
// then
221+
result shouldBe ActionValidationResult(
222+
overallResult = ItemValidationResult.Invalid("Some typing is invalid."),
223+
inputs = mapOf(
224+
"string-input" to ItemValidationResult.Invalid("'separator' is not allowed for this type."),
225+
"boolean-input" to ItemValidationResult.Invalid("'separator' is not allowed for this type."),
226+
"integer-input" to ItemValidationResult.Invalid("'separator' is not allowed for this type."),
227+
"float-input" to ItemValidationResult.Invalid("'separator' is not allowed for this type."),
228+
),
229+
)
230+
}
231+
232+
test("enum type with 'separator' attribute") {
233+
// given
234+
val manifest = Manifest(
235+
typingSpec = expectedTypingSpec,
236+
inputs = mapOf(
237+
"enum-input" to ApiItem(type = "enum", allowedValues = listOf("foo", "bar", "baz"), separator = ","),
238+
),
239+
)
240+
241+
// when
242+
val result = manifest.validate()
243+
244+
// then
245+
result shouldBe ActionValidationResult(
246+
overallResult = ItemValidationResult.Invalid("Some typing is invalid."),
247+
inputs = mapOf(
248+
"enum-input" to ItemValidationResult.Invalid("'separator' is not allowed for this type."),
249+
),
250+
)
251+
}
252+
184253
test("enum type without 'allowedValues' attribute") {
185254
// given
186255
val manifest = Manifest(
@@ -222,5 +291,47 @@ class ManifestValidationTest : FunSpec({
222291
),
223292
)
224293
}
294+
295+
test("list type without 'separator' attribute") {
296+
// given
297+
val manifest = Manifest(
298+
typingSpec = expectedTypingSpec,
299+
inputs = mapOf(
300+
"list-input" to ApiItem(type = "list"),
301+
),
302+
)
303+
304+
// when
305+
val result = manifest.validate()
306+
307+
// then
308+
result shouldBe ActionValidationResult(
309+
overallResult = ItemValidationResult.Invalid("Some typing is invalid."),
310+
inputs = mapOf(
311+
"list-input" to ItemValidationResult.Invalid("Separator must be specified."),
312+
),
313+
)
314+
}
315+
316+
test("list type with 'allowedValues' attribute") {
317+
// given
318+
val manifest = Manifest(
319+
typingSpec = expectedTypingSpec,
320+
inputs = mapOf(
321+
"list-input" to ApiItem(type = "list", separator = "\n", allowedValues = listOf("foo", "bar")),
322+
),
323+
)
324+
325+
// when
326+
val result = manifest.validate()
327+
328+
// then
329+
result shouldBe ActionValidationResult(
330+
overallResult = ItemValidationResult.Invalid("Some typing is invalid."),
331+
inputs = mapOf(
332+
"list-input" to ItemValidationResult.Invalid("'allowedValues' is not allowed for this type."),
333+
),
334+
)
335+
}
225336
}
226337
})

0 commit comments

Comments
 (0)