Skip to content

Commit 097f6a4

Browse files
authored
fix: validate some more bad cases in typings (#290)
1 parent d835b1f commit 097f6a4

20 files changed

+265
-23
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ fun parseTypesManifest(manifestString: String): Result<TypesManifest> =
2929
null -> TypesManifest()
3030

3131
is Map<*, *> -> {
32+
val excessKeys = loadedTypesManifest.keys - listOf("inputs", "outputs")
33+
if (excessKeys.isNotEmpty()) {
34+
throw ValidationException(excessKeys.joinToString(prefix = "Excess keys: ", postfix = "."))
35+
}
3236
TypesManifest(
3337
inputs = loadedTypesManifest.toInputsOrOutputs("inputs"),
3438
outputs = loadedTypesManifest.toInputsOrOutputs("outputs"),
@@ -55,19 +59,40 @@ private fun Any?.toApiItem(key: String): ApiItem =
5559
null -> ApiItem()
5660

5761
is Map<*, *> -> {
62+
val excessKeys = keys - listOf(
63+
"type",
64+
"name",
65+
"allowed-values",
66+
"separator",
67+
"named-values",
68+
"list-item",
69+
)
70+
if (excessKeys.isNotEmpty()) {
71+
throw ValidationException(excessKeys.joinToString(prefix = "Excess keys: ", postfix = "."))
72+
}
73+
5874
ApiItem(
5975
type = get("type")?.let {
60-
"$it"
76+
if (it !is String) {
77+
throw ValidationException("type must be a string.")
78+
}
79+
it
6180
},
6281
name = get("name")?.let {
63-
"$it"
82+
if (it !is String) {
83+
throw ValidationException("name must be a string.")
84+
}
85+
it
6486
},
6587
allowedValues = get("allowed-values")?.let {
6688
if (it !is List<*>) {
6789
throw ValidationException("allowed-values must be a sequence.")
6890
}
6991
it.map {
70-
"$it"
92+
if (it !is String) {
93+
throw ValidationException("Allowed Value must be string.")
94+
}
95+
it
7196
}
7297
},
7398
separator = get("separator")?.let {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
foo:
5+
type: string
6+
bar:
7+
baz:
8+
9+
# Expected validation error
10+
#
11+
#Excess keys: bar, baz.
12+
#
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
outputs:
4+
foo:
5+
type: string
6+
bar:
7+
baz:
8+
9+
# Expected validation error
10+
#
11+
#Excess keys: bar, baz.
12+
#
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
foo:
4+
bar:
5+
6+
# Expected validation error
7+
#
8+
#Excess keys: foo, bar.
9+
#
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
granted-scopes:
5+
type: list
6+
separator: ','
7+
list-item:
8+
type: enum
9+
allowed-values:
10+
- 0x0
11+
12+
# Expected validation error
13+
#
14+
#Allowed Value must be string.
15+
#
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
granted-scopes:
5+
type: list
6+
separator: ','
7+
list-item:
8+
type: enum
9+
name: 0x0
10+
allowed-values:
11+
- read
12+
- write
13+
14+
# Expected validation error
15+
#
16+
#name must be a string.
17+
#
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
permissions:
5+
type: enum
6+
allowed-values:
7+
- 0o0
8+
9+
# Expected validation error
10+
#
11+
#Allowed Value must be string.
12+
#
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
permissions:
5+
type: enum
6+
name: 0o0
7+
allowed-values:
8+
- user
9+
- admin
10+
- guest
11+
12+
# Expected validation error
13+
#
14+
#name must be a string.
15+
#
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
list-of-integer:
5+
type: list
6+
separator: ','
7+
list-item:
8+
type: integer
9+
name: 0x0
10+
named-values:
11+
foo: 0
12+
13+
# Expected validation error
14+
#
15+
#name must be a string.
16+
#
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# yaml-language-server: $schema=../../../../github-actions-typing.schema.json
2+
# See https://github.com/typesafegithub/github-actions-typing
3+
inputs:
4+
retries:
5+
type: integer
6+
name: 0o0
7+
named-values:
8+
foo: 0
9+
10+
# Expected validation error
11+
#
12+
#name must be a string.
13+
#

0 commit comments

Comments
 (0)