diff --git a/src/Validation/RequestValidator.php b/src/Validation/RequestValidator.php index d09fcf6..95e60ac 100644 --- a/src/Validation/RequestValidator.php +++ b/src/Validation/RequestValidator.php @@ -102,6 +102,10 @@ protected function validateParameters(): void } } elseif ($parameter->in === 'header' && $this->request->headers->has($parameter->name)) { $parameterValue = $this->request->headers->get($parameter->name); + + if ($parameter->explode === false && $parameter->schema->type === 'array') { + $parameterValue = explode(',', $parameterValue); + } } elseif ($parameter->in === 'cookie' && $this->request->cookies->has($parameter->name)) { $parameterValue = $this->request->cookies->get($parameter->name); } diff --git a/tests/Fixtures/CommaSeparatedString.v1.json b/tests/Fixtures/CommaSeparatedString.v1.json index e63d676..1ed6a21 100644 --- a/tests/Fixtures/CommaSeparatedString.v1.json +++ b/tests/Fixtures/CommaSeparatedString.v1.json @@ -115,6 +115,17 @@ "enum": ["foo", "bar"] } } + }, + { + "name": "X-Include", + "in": "header", + "schema": { + "type": "array", + "items": { + "type": "string", + "enum": ["foo", "bar"] + } + } } ] } diff --git a/tests/RequestValidatorTest.php b/tests/RequestValidatorTest.php index c088ebe..8e493c8 100644 --- a/tests/RequestValidatorTest.php +++ b/tests/RequestValidatorTest.php @@ -791,7 +791,9 @@ public function test_comma_separated_values() }) ->middleware(Middleware::class); - $this->getJson('/users?include=foo,bar') + $this + ->withHeader('X-Include', 'foo,bar') + ->getJson('/users?include=foo,bar') ->assertStatus(200) ->assertValidRequest() ->assertValidResponse();