Skip to content

Commit

Permalink
Improve tests related to zalando#1249
Browse files Browse the repository at this point in the history
  • Loading branch information
martinblume committed Oct 25, 2024
1 parent 8c7407d commit 04502dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ package org.zalando.zally.ruleset.zalando
import org.assertj.core.api.Assertions
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import org.zalando.zally.core.DefaultContextFactory
import java.util.stream.Stream

class EnumValueTypeTest {

private val rule = EnumValueTypeRule()

@Test
fun `fail validation if 'x-extensible-enum' has a 'string' type`() {
companion object {
@JvmStatic
fun nonStringTypes(): Stream<Arguments> = Stream.of(
Arguments.of("number", "1", "2"),
Arguments.of("integer", "1", "2"),
Arguments.of("boolean", "true", "false")
)
}

@ParameterizedTest
@MethodSource("nonStringTypes")
fun `fail validation if 'x-extensible-enum' has a non-'string' type`(nonStringType: String, value1: String, value2: String) {
@Language("YAML")
val spec = """
openapi: 3.0.1
Expand All @@ -26,18 +40,18 @@ class EnumValueTypeTest {
type: object
properties:
prop-1:
type: integer
type: $nonStringType
x-extensible-enum:
- 1
- 2
- 3
- $value1
- $value2
""".trimIndent()

val context = DefaultContextFactory().getOpenApiContext(spec)

val violations = rule.validate(context)
Assertions.assertThat(violations).hasSize(1)
Assertions.assertThat(violations[0].description).isEqualTo("Enumeration value should have \"type = string\": prop-1")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ExtensibleEnumRuleTest {
}

@Test
fun `checkForEnums should return violation if no enums are used`() {
fun `checkForEnums should return no violation if no enums are used`() {
val content = """
openapi: 3.0.1
components:
Expand Down

0 comments on commit 04502dd

Please sign in to comment.