diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java index 614b2de512..39bdd2486e 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java @@ -219,7 +219,7 @@ public static Map getRequiredHeaders(Oas30Response response) return response.headers.entrySet() .stream() - .filter(entry -> entry.getValue().required) + .filter(entry -> Boolean.TRUE.equals(entry.getValue().required)) .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().schema)); } diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.java new file mode 100644 index 0000000000..38d8b13fde --- /dev/null +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.java @@ -0,0 +1,54 @@ +package org.citrusframework.openapi.model.v3; + +import io.apicurio.datamodels.openapi.models.OasSchema; +import io.apicurio.datamodels.openapi.v3.models.Oas30Header; +import io.apicurio.datamodels.openapi.v3.models.Oas30Response; +import io.apicurio.datamodels.openapi.v3.models.Oas30Schema; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.Map; + +public class Oas30ModelHelperTest { + + @Test + public void shouldNotFindRequiredHeadersWithoutRequiredAttribute() { + var header = new Oas30Header("X-TEST"); + header.schema = new Oas30Schema(); + header.required = null; // explicitely assigned because this is test case + var response = new Oas30Response("200"); + response.headers.put(header.getName(), header); + + Map result = Oas30ModelHelper.getRequiredHeaders(response); + + Assert.assertEquals(result.size(), 0); + } + + @Test + public void shouldFindRequiredHeaders() { + var header = new Oas30Header("X-TEST"); + header.schema = new Oas30Schema(); + header.required = Boolean.TRUE; // explicitely assigned because this is test case + var response = new Oas30Response("200"); + response.headers.put(header.getName(), header); + + Map result = Oas30ModelHelper.getRequiredHeaders(response); + + Assert.assertEquals(result.size(), 1); + Assert.assertSame(result.get(header.getName()), header.schema); + } + + @Test + public void shouldNotFindOptionalHeaders() { + var header = new Oas30Header("X-TEST"); + header.schema = new Oas30Schema(); + header.required = Boolean.FALSE; // explicitely assigned because this is test case + var response = new Oas30Response("200"); + response.headers.put(header.getName(), header); + + Map result = Oas30ModelHelper.getRequiredHeaders(response); + + Assert.assertEquals(result.size(), 0); + } + +} \ No newline at end of file