Skip to content

Commit

Permalink
feat: add extra validation for enums (#266)
Browse files Browse the repository at this point in the history
Part of
#253.

Fixes several failing test cases identified in
#261,
getting us closer to being consistent with the schema.
  • Loading branch information
krzema12 authored Jan 31, 2025
1 parent 478aaca commit 6331966
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import it.krzeminski.githubactionstyping.parsing.ApiItem
import it.krzeminski.githubactionstyping.validation.ItemValidationResult

fun ApiItem.validateEnum(): ItemValidationResult {
if (this.name?.isBlank() == true) {
return ItemValidationResult.Invalid("Name must not be empty.")
}
if (this.allowedValues == null) {
return ItemValidationResult.Invalid("Allowed values must be specified.")
}
Expand All @@ -19,5 +22,8 @@ fun ApiItem.validateEnum(): ItemValidationResult {
if (this.allowedValues.isEmpty()) {
return ItemValidationResult.Invalid("There must be at least one allowed value.")
}
if (this.allowedValues.any { it.isBlank() }) {
return ItemValidationResult.Invalid("Allowed values must not be empty.")
}
return ItemValidationResult.Valid
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ fun ApiItem.validateList(): ItemValidationResult {
if (this.listItem == null) {
return ItemValidationResult.Invalid("List item information must be specified.")
}
if (this.listItem.name?.isBlank() == true) {
return ItemValidationResult.Invalid("List item type: Name must not be empty.")
}
if (this.separator == null) {
return ItemValidationResult.Invalid("Separator must be specified.")
}
Expand Down

0 comments on commit 6331966

Please sign in to comment.