api-validator
api-validator copied to clipboard
Xml validation fails on validateMessageBody for Slim v3, all Requests are instances of ServerRequestInterface.
MessageValidator class:
public function validateMessageBody(MessageInterface $message, MessageDefinition $definition)
{
if ($message instanceof ServerRequestInterface) {
$bodyString = json_encode((array) $message->getParsedBody());
} else {
$bodyString = (string) $message->getBody();
}
if ($bodyString !== '' && $definition->hasBodySchema()) {
$contentType = $message->getHeaderLine('Content-Type');
$decodedBody = $this->decoder->decode(
$bodyString,
DecoderUtils::extractFormatFromContentType($contentType)
);
$this->validate($decodedBody, $definition->getBodySchema(), 'body');
}
}
The xml in $message->getBody() is being converted to a json string before it's decoded. All requests in Slim v3 are instances of ServerRequestInterface.
@jimmy4fingers Sorry for the delay, and thanks for reporting this. I'll look at it A.S.A.P. I haven't tested this library against an xml payload at all to be honest.