api-validator icon indicating copy to clipboard operation
api-validator copied to clipboard

Xml validation fails on validateMessageBody for Slim v3, all Requests are instances of ServerRequestInterface.

Open jimmy4fingers opened this issue 7 years ago • 1 comments

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 avatar Oct 10 '18 08:10 jimmy4fingers

@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.

guillemcanal avatar Nov 08 '18 22:11 guillemcanal